Ticket #7203: 7203.patch
| File 7203.patch, 3.0 KB (added by , 10 years ago) |
|---|
-
src/bp-core/classes/class-bp-core-nav.php
diff --git src/bp-core/classes/class-bp-core-nav.php src/bp-core/classes/class-bp-core-nav.php index ed97c36..eaab9b8 100644
class BP_Core_Nav { 258 258 return false; 259 259 } 260 260 261 $screen_functions = array( $nav_item->screen_function ); 261 /** 262 * As we are using array_unique() a bit later, in case a plugin is using 263 * the method of a class to set the screen function of a nav item, we need 264 * to serialize/unserialize arrays to avoid a notice error. 265 * 266 * @see https://buddypress.trac.wordpress.org/ticket/7203 267 */ 268 $screen_functions = array( maybe_serialize( $nav_item->screen_function ) ); 262 269 263 270 // Life's unfair, children won't survive the parent :( 264 271 $sub_items = $this->get_secondary( array( 'parent_slug' => $nav_item->slug ), false ); 265 272 266 273 if ( ! empty( $sub_items ) ) { 267 274 foreach ( $sub_items as $sub_item ) { 268 $screen_functions[] = $sub_item->screen_function;275 $screen_functions[] = maybe_serialize( $sub_item->screen_function ); 269 276 270 277 // Delete the child 271 278 unset( $this->nav[ $this->object_id ][ $nav_item->slug . '/' . $sub_item->slug ] ); … … class BP_Core_Nav { 276 283 unset( $this->nav[ $this->object_id ][ $nav_item->slug ] ); 277 284 278 285 // Return the deleted item's screen functions. 279 return array_ unique( $screen_functions);286 return array_map( 'maybe_unserialize', array_unique( $screen_functions ) ); 280 287 } 281 288 } 282 289 -
tests/phpunit/testcases/core/nav/bpCoreRemoveNavItem.php
diff --git tests/phpunit/testcases/core/nav/bpCoreRemoveNavItem.php tests/phpunit/testcases/core/nav/bpCoreRemoveNavItem.php index 0b35708..8003b1c 100644
class BP_Tests_Core_Nav_BpCoreRemoveNavItem extends BP_UnitTestCase { 64 64 $bp->bp_nav = $_bp_nav; 65 65 $bp->bp_options_nav = $_bp_options_nav; 66 66 } 67 68 public function foo_is_active( $retval, $component ) { 69 if ( 'foo' === $component ) { 70 $retval = true; 71 } 72 73 return $retval; 74 } 75 /** 76 * @ticket BP7203 77 */ 78 public function test_remove_subnav_item_array_as_screen_function() { 79 $bp = buddypress(); 80 81 add_filter( 'bp_is_active', array( $this, 'foo_is_active' ), 10, 2 ); 82 83 $bp->foo = new stdClass; 84 $bp->foo->nav = new BP_Core_Nav( 0 ); 85 86 $expected = array( 'foo', 'bar' ); 87 88 bp_core_new_nav_item( array( 89 'name' => 'Foo', 90 'slug' => 'foo', 91 'screen_function' => $expected, 92 ), 'foo' ); 93 94 bp_core_new_subnav_item( array( 95 'name' => 'Bar', 96 'slug' => 'bar', 97 'parent_slug' => 'foo', 98 'parent_url' => 'foo', 99 'screen_function' => $expected, 100 ), 'foo' ); 101 102 remove_filter( 'bp_is_active', array( $this, 'foo_is_active' ), 10, 2 ); 103 104 $this->assertNotEmpty( $bp->foo->nav->get_primary( array( 'slug' => 'foo' ), false ) ); 105 106 $tested = $bp->foo->nav->delete_nav( 'foo' ); 107 $this->assertSame( $expected, reset( $tested ) ); 108 109 $this->assertEmpty( $bp->foo->nav->get_primary( array( 'slug' => 'foo' ), false ) ); 110 } 67 111 }