Skip to:
Content

BuddyPress.org

Changeset 14328


Ignore:
Timestamp:
10/09/2026 09:57:58 PM (5 weeks ago)
Author:
espellcaste
Message:

Email: Allow extensions to filter email type schemas.

Add a bp_email_get_type_schema filter before schema fields are selected. This lets extensions provide email type metadata, including descriptions stored when email taxonomy terms are installed.

Props indigetal.

Fixes #9329.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r14326 r14328  
    45374537                'groups-membership-request-rejected-by-admin' => $groups_membership_request_rejected_by_admin,
    45384538        );
     4539
     4540        /**
     4541         * Filters the list of `bp_email_get_type_schema()` allowing anyone to add/remove email types.
     4542         *
     4543         * @since 15.0.0
     4544         *
     4545         * @param array $types The array of email type schema.
     4546         */
     4547        $types = (array) apply_filters( 'bp_email_get_type_schema', $types );
    45394548
    45404549        if ( $field !== 'all' ) {
  • trunk/tests/phpunit/testcases/admin/functions.php

    r14316 r14328  
    258258        }
    259259
     260        /**
     261         * @ticket BP9329
     262         */
     263        public function test_bp_email_get_type_schema_should_allow_custom_types() {
     264                add_filter( 'bp_email_get_schema', array( $this, 'filter_bp_email_get_schema' ) );
     265                add_filter( 'bp_email_get_type_schema', array( $this, 'filter_bp_email_get_type_schema' ) );
     266
     267                try {
     268                        $types = bp_email_get_type_schema( 'all' );
     269                        $this->assertArrayHasKey( 'test-email-type', $types );
     270                        $this->assertSame( 'Test email type description.', $types['test-email-type']['description'] );
     271
     272                        $descriptions = bp_email_get_type_schema( 'description' );
     273                        $this->assertSame( 'Test email type description.', $descriptions['test-email-type'] );
     274
     275                        require_once( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-admin-schema.php' );
     276                        bp_core_install_emails();
     277
     278                        $term = get_term_by( 'slug', 'test-email-type', bp_get_email_tax_type() );
     279                        $this->assertInstanceOf( 'WP_Term', $term );
     280                        $this->assertSame( 'Test email type description.', $term->description );
     281                } finally {
     282                        remove_filter( 'bp_email_get_schema', array( $this, 'filter_bp_email_get_schema' ) );
     283                        remove_filter( 'bp_email_get_type_schema', array( $this, 'filter_bp_email_get_type_schema' ) );
     284                }
     285        }
     286
     287        public function filter_bp_email_get_schema( $emails ) {
     288                $emails['test-email-type'] = array(
     289                        'post_title'   => 'Test email type',
     290                        'post_content' => 'Test email type content.',
     291                        'post_excerpt' => 'Test email type content.',
     292                );
     293
     294                return $emails;
     295        }
     296
     297        public function filter_bp_email_get_type_schema( $types ) {
     298                $types['test-email-type'] = array(
     299                        'description'      => 'Test email type description.',
     300                        'named_salutation' => false,
     301                        'unsubscribe'      => false,
     302                );
     303
     304                return $types;
     305        }
     306
    260307        public function is_active_filter( $is_active, $component ) {
    261308                if ( ! $is_active && 'attachments' === $component ) {
Note: See TracChangeset for help on using the changeset viewer.