Ticket #7036: 7036.01.patch
| File 7036.01.patch, 8.1 KB (added by , 10 years ago) |
|---|
-
src/bp-core/admin/bp-core-admin-schema.php
531 531 * Add default emails. 532 532 * 533 533 * @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. 534 538 */ 535 function bp_core_install_emails( ) {539 function bp_core_install_emails( $email_types = array() ) { 536 540 $defaults = array( 537 541 'post_status' => 'publish', 538 542 'post_type' => bp_get_email_post_type(), 539 543 ); 540 544 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 ); 543 547 544 548 // Add these emails to the database. 545 549 foreach ( $emails as $id => $email ) { … … 557 561 } 558 562 } 559 563 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 } 566 573 } -
src/bp-core/admin/bp-core-admin-tools.php
423 423 * Delete emails and restore from defaults. 424 424 * 425 425 * @since 2.5.0 426 * @since 2.x.0 Added $email_types as a parameter. 426 427 * 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. 427 430 * @return array 428 431 */ 429 function bp_admin_reinstall_emails( ) {432 function bp_admin_reinstall_emails( $email_types = array() ) { 430 433 $switched = false; 431 434 432 435 // Switch to the root blog, where the email posts live. … … 437 440 $switched = true; 438 441 } 439 442 440 $ emails = get_posts(array(443 $args = array( 441 444 'fields' => 'ids', 442 445 'post_status' => 'publish', 443 446 'post_type' => bp_get_email_post_type(), 444 447 'posts_per_page' => 200, 445 448 '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 ); 447 462 448 463 if ( $emails ) { 449 464 foreach ( $emails as $email_id ) { … … 452 467 } 453 468 454 469 // 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 } 464 481 } 465 482 } 466 483 467 484 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 ); 469 486 470 487 if ( $switched ) { 471 488 restore_current_blog(); -
src/bp-core/bp-core-functions.php
3115 3115 * Get a list of emails for populating the email post type. 3116 3116 *t 3117 3117 * @since 2.5.1 3118 * @since 2.x.0 Added $email_types as a parameter. 3118 3119 * 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. 3119 3122 * @return array 3120 3123 */ 3121 function bp_email_get_schema( ) {3122 returnarray(3124 function bp_email_get_schema( $email_types = array() ) { 3125 $types = array( 3123 3126 'activity-comment' => array( 3124 3127 /* translators: do not remove {} brackets or translate its contents. */ 3125 3128 'post_title' => __( '[{{{site.name}}}] {{poster.name}} replied to one of your updates', 'buddypress' ), … … 3249 3252 'post_excerpt' => __( "Your membership request for the group "{{group.name}}" has been rejected.\n\nTo request membership again, visit: {{{group.url}}}", 'buddypress' ), 3250 3253 ), 3251 3254 ); 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; 3252 3263 } 3253 3264 3254 3265 /** 3255 3266 * Get a list of emails for populating email type taxonomy terms. 3256 3267 * 3257 3268 * @since 2.5.1 3269 * @since 2.x.0 Added $email_types as a parameter. 3258 3270 * 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. 3259 3273 * @return array 3260 3274 */ 3261 function bp_email_get_type_schema( ) {3262 returnarray(3275 function bp_email_get_type_schema( $email_types = array() ) { 3276 $types = array( 3263 3277 'activity-comment' => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ), 3264 3278 'activity-comment-author' => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ), 3265 3279 'activity-at-message' => __( 'Recipient was mentioned in an activity update.', 'buddypress' ), … … 3277 3291 'groups-membership-request-accepted' => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ), 3278 3292 'groups-membership-request-rejected' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ), 3279 3293 ); 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; 3280 3302 } -
tests/phpunit/testcases/admin/functions.php
221 221 222 222 /** 223 223 * @ticket BP6936 224 * @group emails 224 225 */ 225 226 public function test_email_type_descriptions_should_match_when_split_terms_exist() { 226 227 global $wpdb; -
tests/phpunit/testcases/core/class-bp-email.php
2 2 /** 3 3 * @group core 4 4 * @group BP_Email 5 * @group emails 5 6 */ 6 7 class BP_Tests_Email extends BP_UnitTestCase_Emails { 7 8 protected $u1; … … 267 268 268 269 $this->assertTrue( $result ); 269 270 } 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 } 270 296 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)