Skip to:
Content

BuddyPress.org

Ticket #7036: 7036.01.patch

File 7036.01.patch, 8.1 KB (added by r-a-y, 10 years ago)
  • src/bp-core/admin/bp-core-admin-schema.php

     
    531531 * Add default emails.
    532532 *
    533533 * @since 2.5.0
     534 * @since 2.x.0 Added $email_types as a parameter.
     535 *
     536 * @param array $email_types Enter specific email types as an array to reinstall only those emails. If
     537 *                           left empty, we will reinstall all email types.
    534538 */
    535 function bp_core_install_emails() {
     539function bp_core_install_emails( $email_types = array() ) {
    536540        $defaults = array(
    537541                'post_status' => 'publish',
    538542                'post_type'   => bp_get_email_post_type(),
    539543        );
    540544
    541         $emails       = bp_email_get_schema();
    542         $descriptions = bp_email_get_type_schema();
     545        $emails       = bp_email_get_schema( $email_types );
     546        $descriptions = bp_email_get_type_schema( $email_types );
    543547
    544548        // Add these emails to the database.
    545549        foreach ( $emails as $id => $email ) {
     
    557561                }
    558562        }
    559563
    560         /**
    561          * Fires after BuddyPress adds the posts for its emails.
    562          *
    563          * @since 2.5.0
    564          */
    565         do_action( 'bp_core_install_emails' );
     564        // Only fire hook when wiping out all BuddyPress emails.
     565        if ( empty( $email_types ) ) {
     566                /**
     567                 * Fires after BuddyPress adds the posts for its emails.
     568                 *
     569                 * @since 2.5.0
     570                 */
     571                do_action( 'bp_core_install_emails' );
     572        }
    566573}
  • src/bp-core/admin/bp-core-admin-tools.php

     
    423423 * Delete emails and restore from defaults.
    424424 *
    425425 * @since 2.5.0
     426 * @since 2.x.0 Added $email_types as a parameter.
    426427 *
     428 * @param array $email_types Enter specific email types as an array to reinstall only those emails. By
     429 *                           default, we will reinstall all email types.
    427430 * @return array
    428431 */
    429 function bp_admin_reinstall_emails() {
     432function bp_admin_reinstall_emails( $email_types = array() ) {
    430433        $switched = false;
    431434
    432435        // Switch to the root blog, where the email posts live.
     
    437440                $switched = true;
    438441        }
    439442
    440         $emails = get_posts( array(
     443        $args = array(
    441444                'fields'           => 'ids',
    442445                'post_status'      => 'publish',
    443446                'post_type'        => bp_get_email_post_type(),
    444447                'posts_per_page'   => 200,
    445448                'suppress_filters' => false,
    446         ) );
     449        );
     450
     451        if ( ! empty( $email_types ) ) {
     452                $args['tax_query'] = array(
     453                        array(
     454                                'taxonomy' => bp_get_email_tax_type(),
     455                                'field'    => 'slug',
     456                                'terms'    => $email_types,
     457                        ),
     458                );
     459        }
     460
     461        $emails = get_posts( $args );
    447462
    448463        if ( $emails ) {
    449464                foreach ( $emails as $email_id ) {
     
    452467        }
    453468
    454469        // Make sure we have no orphaned email type terms.
    455         $email_types = get_terms( bp_get_email_tax_type(), array(
    456                 'fields'                 => 'ids',
    457                 'hide_empty'             => false,
    458                 'update_term_meta_cache' => false,
    459         ) );
    460 
    461         if ( $email_types ) {
    462                 foreach ( $email_types as $term_id ) {
    463                         wp_delete_term( (int) $term_id, bp_get_email_tax_type() );
     470        if ( empty( $email_types ) ) {
     471                $remove_types = get_terms( bp_get_email_tax_type(), array(
     472                        'fields'                 => 'ids',
     473                        'hide_empty'             => false,
     474                        'update_term_meta_cache' => false,
     475                ) );
     476
     477                if ( $remove_types ) {
     478                        foreach ( $remove_types as $term_id ) {
     479                                wp_delete_term( (int) $term_id, bp_get_email_tax_type() );
     480                        }
    464481                }
    465482        }
    466483
    467484        require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
    468         bp_core_install_emails();
     485        bp_core_install_emails( $email_types );
    469486
    470487        if ( $switched ) {
    471488                restore_current_blog();
  • src/bp-core/bp-core-functions.php

     
    31153115 * Get a list of emails for populating the email post type.
    31163116 *t
    31173117 * @since 2.5.1
     3118 * @since 2.x.0 Added $email_types as a parameter.
    31183119 *
     3120 * @param array $email_types Enter specific email types as an array to fetch data for only those emails.
     3121 *                           If left empty, we will fetch data for all email types.
    31193122 * @return array
    31203123 */
    3121 function bp_email_get_schema() {
    3122         return array(
     3124function bp_email_get_schema( $email_types = array() ) {
     3125        $types = array(
    31233126                'activity-comment' => array(
    31243127                        /* translators: do not remove {} brackets or translate its contents. */
    31253128                        'post_title'   => __( '[{{{site.name}}}] {{poster.name}} replied to one of your updates', 'buddypress' ),
     
    32493252                        'post_excerpt' => __( "Your membership request for the group "{{group.name}}" has been rejected.\n\nTo request membership again, visit: {{{group.url}}}", 'buddypress' ),
    32503253                ),
    32513254        );
     3255
     3256        // Return data for specific email types.
     3257        if ( ! empty( $email_types ) ) {
     3258                return array_intersect_key( $types, array_flip( $email_types ) );
     3259        }
     3260
     3261        // Return all email types.
     3262        return $types;
    32523263}
    32533264
    32543265/**
    32553266 * Get a list of emails for populating email type taxonomy terms.
    32563267 *
    32573268 * @since 2.5.1
     3269 * @since 2.x.0 Added $email_types as a parameter.
    32583270 *
     3271 * @param array $email_types Enter specific email types as an array to fetch data for only those emails.
     3272 *                           If left empty, we will fetch data for all email types.
    32593273 * @return array
    32603274 */
    3261 function bp_email_get_type_schema() {
    3262         return array(
     3275function bp_email_get_type_schema( $email_types = array() ) {
     3276        $types = array(
    32633277                'activity-comment'                   => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ),
    32643278                'activity-comment-author'            => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ),
    32653279                'activity-at-message'                => __( 'Recipient was mentioned in an activity update.', 'buddypress' ),
     
    32773291                'groups-membership-request-accepted' => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ),
    32783292                'groups-membership-request-rejected' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
    32793293        );
     3294
     3295        // Return data for specific email types.
     3296        if ( ! empty( $email_types ) ) {
     3297                return array_intersect_key( $types, array_flip( $email_types ) );
     3298        }
     3299
     3300        // Return all email types.
     3301        return $types;
    32803302}
  • tests/phpunit/testcases/admin/functions.php

     
    221221
    222222        /**
    223223         * @ticket BP6936
     224         * @group emails
    224225         */
    225226        public function test_email_type_descriptions_should_match_when_split_terms_exist() {
    226227                global $wpdb;
  • tests/phpunit/testcases/core/class-bp-email.php

     
    22/**
    33 * @group core
    44 * @group BP_Email
     5 * @group emails
    56 */
    67class BP_Tests_Email extends BP_UnitTestCase_Emails {
    78        protected $u1;
     
    267268
    268269                $this->assertTrue( $result );
    269270        }
     271
     272        /**
     273         * @group bp_admin_reinstall_emails
     274         */
     275        public function test_bp_admin_reinstall_emails_for_specific_email_types_only() {
     276                // Fetch email post for an existing email type.
     277                $settings_email = bp_get_email( 'settings-verify-email-change' );
     278
     279                // Fetch another email post just for comparison.
     280                $activity_email = bp_get_email( 'activity-at-message' );
     281
     282                // Reinstall only the 'settings-verify-email-change' email.
     283                require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-tools.php' );
     284                bp_admin_reinstall_emails( array(
     285                        'settings-verify-email-change'
     286                ) );
     287
     288                // Refetch emails for comparison.
     289                $new_settings_email = bp_get_email( 'settings-verify-email-change' );
     290                $new_activity_email = bp_get_email( 'activity-at-message' );
     291
     292                // Assert!
     293                $this->assertNotEquals( $settings_email->get_post_object(), $new_settings_email->get_post_object() );
     294                $this->assertEquals( $activity_email->get_post_object(), $new_activity_email->get_post_object() );
     295        }
    270296}