Changeset 9177
- Timestamp:
- 11/25/2014 03:33:45 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-functions.php
r9012 r9177 382 382 foreach( (array) $page_ids as $component_name => $page_id ) { 383 383 if ( empty( $component_name ) || empty( $page_id ) ) { 384 unset( $page_ids[$component_name] ); 384 unset( $page_ids[ $component_name ] ); 385 } 386 387 if ( ! bp_is_active( $component_name ) || 'trash' == get_post_status( $page_id ) ) { 388 unset( $page_ids[ $component_name ] ); 385 389 } 386 390 } … … 566 570 } 567 571 } 572 573 /** 574 * Remove the entry from bp_pages when the corresponding WP page is deleted. 575 * 576 * @since BuddyPress (2.2.0) 577 * 578 * @param int $post_id Post ID. 579 */ 580 function bp_core_on_directory_page_delete( $post_id ) { 581 $page_ids = bp_core_get_directory_page_ids(); 582 $component_name = array_search( $post_id, $page_ids ); 583 584 if ( ! empty( $component_name ) ) { 585 unset( $page_ids[ $component_name ] ); 586 } 587 588 bp_core_update_directory_page_ids( $page_ids ); 589 } 590 add_action( 'delete_post', 'bp_core_on_directory_page_delete' ); 568 591 569 592 /** -
trunk/tests/phpunit/testcases/core/functions.php
r8958 r9177 282 282 283 283 /** 284 * @group bp_core_get_directory_page_ids 285 */ 286 public function test_bp_core_get_directory_page_ids_on_directory_page_to_trash() { 287 $old_page_ids = bp_core_get_directory_page_ids(); 288 289 // Grab the and remove the first page. 290 foreach ( $old_page_ids as $component => $page_id ) { 291 $p = $page_id; 292 unset( $old_page_ids[ $component ] ); 293 break; 294 } 295 296 // Move page to trash. 297 wp_delete_post( $p, false ); 298 299 $new_page_ids = bp_core_get_directory_page_ids(); 300 301 $this->assertEquals( $old_page_ids, $new_page_ids ); 302 } 303 304 /** 305 * @group bp_core_get_directory_page_ids 306 */ 307 public function test_bp_core_get_directory_page_ids_on_directory_page_delete() { 308 $old_page_ids = bp_core_get_directory_page_ids(); 309 310 // Grab the and remove the first page. 311 foreach ( $old_page_ids as $component => $page_id ) { 312 $p = $page_id; 313 unset( $old_page_ids[ $component ] ); 314 break; 315 } 316 317 // Force delete page. 318 wp_delete_post( $p, true ); 319 320 $new_page_ids = bp_core_get_directory_page_ids(); 321 322 $this->assertEquals( $old_page_ids, $new_page_ids ); 323 } 324 325 /** 326 * @group bp_core_get_directory_page_ids 327 */ 328 public function test_bp_core_get_directory_page_ids_on_non_directory_page_delete() { 329 $old_page_ids = bp_core_get_directory_page_ids(); 330 331 $p = $this->factory->post->create( array( 332 'post_status' => 'publish', 333 'post_type' => 'page', 334 ) ); 335 336 // Force delete page. 337 wp_delete_post( $p, true ); 338 339 $new_page_ids = bp_core_get_directory_page_ids(); 340 341 $this->assertEquals( $old_page_ids, $new_page_ids ); 342 } 343 344 /** 345 * @group bp_core_get_directory_page_ids 346 */ 347 public function test_bp_core_get_directory_page_ids_non_active_component() { 348 $old_page_ids = bp_core_get_directory_page_ids(); 349 $bp = buddypress(); 350 351 // Grab the and remove the first page. 352 foreach ( $old_page_ids as $component => $page_id ) { 353 $p = $page_id; 354 $c = $component; 355 unset( $old_page_ids[ $component ] ); 356 break; 357 } 358 359 // Deactivate component. 360 unset( $bp->active_components[ $c ] ); 361 362 $new_page_ids = bp_core_get_directory_page_ids(); 363 364 // Restore components. 365 $bp->active_components[ $c ] = 1; 366 367 $this->assertEquals( $old_page_ids, $new_page_ids ); 368 } 369 370 /** 284 371 * @group bp_core_get_directory_pages 285 372 */
Note: See TracChangeset
for help on using the changeset viewer.