Ticket #8163: 8163.patch
File 8163.patch, 5.1 KB (added by , 5 years ago) |
---|
-
src/bp-core/classes/class-bp-walker-nav-menu.php
diff --git src/bp-core/classes/class-bp-walker-nav-menu.php src/bp-core/classes/class-bp-walker-nav-menu.php index c88181f5a..7a5397a2f 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 if ( PHP_VERSION_ID >= 50600 ) { 14 require_once dirname( __DIR__ ) . '/compat/php56/trait-bp-compat-walker-nav-menu.php'; 15 } else { 16 require_once dirname( __DIR__ ) . '/compat/php53/trait-bp-compat-walker-nav-menu.php'; 17 } 18 13 19 /** 14 20 * Create HTML list of BP nav items. 15 21 * 16 22 * @since 1.7.0 17 23 */ 18 24 class BP_Walker_Nav_Menu extends Walker_Nav_Menu { 25 /** 26 * Use the Compat Trait according to PHP version. 27 * 28 * @since 5.1.0 29 */ 30 use BP_Compat_Walker_Nav_Menu; 19 31 20 32 /** 21 33 * Description of fields indexes for building markup. … … class BP_Walker_Nav_Menu extends Walker_Nav_Menu { 47 59 * those have ID/post_parent. 48 60 * 49 61 * @since 1.7.0 62 * @since 5.1.0 Method was renamed from `walk` to `do_walk` to ensure PHP 5.3 compatibility 50 63 * 51 64 * @see Walker::walk() 52 65 * … … class BP_Walker_Nav_Menu extends Walker_Nav_Menu { 54 67 * @param int $max_depth See {@link Walker::walk()}. 55 68 * @return string See {@link Walker::walk()}. 56 69 */ 57 public function walk( $elements, $max_depth ) { 58 $args = array_slice( func_get_args(), 2 ); 70 public function do_walk( $elements, $max_depth, $args = array() ) { 59 71 $output = ''; 60 72 61 73 if ( $max_depth < -1 ) // Invalid parameter. -
src/bp-core/compat/php53/trait-bp-compat-walker-nav-menu.php
diff --git src/bp-core/compat/php53/trait-bp-compat-walker-nav-menu.php src/bp-core/compat/php53/trait-bp-compat-walker-nav-menu.php index e69de29bb..e86ff1ea4 100644
1 <?php 2 /** 3 * Walker_Nav_Menu Compat for PHP 5.3 and UP. 4 * 5 * @package BuddyPress 6 * @subpackage Core 7 * @since 5.1.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 14 trait BP_Compat_Walker_Nav_Menu { 15 /** 16 * Compat method to extend Walker_Nav_Menu::walk() in PHP < 5.6. 17 * 18 * @since 5.1.0 19 * 20 * @param array $elements See {@link Walker::walk()}. 21 * @param int $max_depth See {@link Walker::walk()}. 22 */ 23 public function walk( $elements, $max_depth ) { 24 $args = array_slice( func_get_args(), 2 ); 25 26 return $this->do_walk( $elements, $max_depth, $args ); 27 } 28 } -
src/bp-core/compat/php56/trait-bp-compat-walker-nav-menu.php
diff --git src/bp-core/compat/php56/trait-bp-compat-walker-nav-menu.php src/bp-core/compat/php56/trait-bp-compat-walker-nav-menu.php index e69de29bb..6dc121691 100644
1 <?php 2 /** 3 * Walker_Nav_Menu Compat for PHP 5.6 and UP. 4 * 5 * @package BuddyPress 6 * @subpackage Core 7 * @since 5.1.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 trait BP_Compat_Walker_Nav_Menu { 14 /** 15 * Compat method to extend Walker_Nav_Menu::walk() in PHP > 5.6. 16 * 17 * @since 5.1.0 18 * 19 * @param array $elements See {@link Walker::walk()}. 20 * @param int $max_depth See {@link Walker::walk()}. 21 * @param mixed ...$args See {@link Walker::walk()}. 22 */ 23 public function walk( $elements, $max_depth, ...$args ) { 24 return $this->do_walk( $elements, $max_depth, $args ); 25 } 26 } -
tests/phpunit/testcases/core/class-bp-walker-nav-menu.php
diff --git tests/phpunit/testcases/core/class-bp-walker-nav-menu.php tests/phpunit/testcases/core/class-bp-walker-nav-menu.php index e69de29bb..75f4866c2 100644
1 <?php 2 /** 3 * @group core 4 * @group BP_Walker_Nav_Menu 5 */ 6 class BP_Tests_Walker_Nav_Menu extends BP_UnitTestCase { 7 protected $reset_user_id; 8 protected $user_id; 9 10 public function setUp() { 11 parent::setUp(); 12 13 $this->reset_user_id = get_current_user_id(); 14 15 $this->user_id = self::factory()->user->create(); 16 $this->set_current_user( $this->user_id ); 17 } 18 19 public function tearDown() { 20 parent::tearDown(); 21 $this->set_current_user( $this->reset_user_id ); 22 } 23 24 public function test_walk_method() { 25 $expected = array( 'activity-class', 'xprofile-class' ); 26 $items = array( 27 (object) array( 28 'component_id' => 'activity', 29 'name' => 'Activity', 30 'slug' => 'activity', 31 'link' => trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() ), 32 'css_id' => 'activity', 33 'class' => array( $expected[0] ), 34 ), 35 (object) array( 36 'component_id' => 'xprofile', 37 'name' => 'Profile', 38 'slug' => 'profile', 39 'link' => trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() ), 40 'css_id' => 'xprofile', 41 'class' => array( $expected[1] ), 42 ), 43 ); 44 $args = (object) array( 'before' => '', 'link_before' => '', 'after' => '', 'link_after' => '' ); 45 $walker = new BP_Walker_Nav_Menu(); 46 $output = $walker->walk( $items, -1, $args ); 47 preg_match_all( '/class=["\']?([^"\']*)["\' ]/is', $output, $classes ); 48 $this->assertSame( $classes[1], $expected ); 49 } 50 }