Ticket #8163: 8163.2.alt.patch
File 8163.2.alt.patch, 5.8 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 8ba7f9c12..b9cc47196 100644
11 11 defined( 'ABSPATH' ) || exit; 12 12 13 13 /** 14 * Create HTML list of BP nav items. 14 * Compatibility Class to make BP_Walker_Nav_Menu::walk() compatible 15 * from PHP 5.3 to 5.6 and up. 15 16 * 16 * @since 1.7.017 * @since 5.1.0 17 18 */ 18 class BP_Walker_Nav_Menu extends Walker_Nav_Menu { 19 19 class BP_Walker_Nav_Menu_Compat extends Walker_Nav_Menu { 20 20 /** 21 21 * Description of fields indexes for building markup. 22 22 * … … class BP_Walker_Nav_Menu extends Walker_Nav_Menu { 47 47 * those have ID/post_parent. 48 48 * 49 49 * @since 1.7.0 50 * @since 6.0.0 Formalized the existing `...$args` parameter by adding it51 * to the function signature to match WordPress 5.3.50 * @since 5.1.0 Method was renamed from `walk` to `do_walk` to ensure PHP 5.3 compatibility 51 * 52 52 * @see Walker::walk() 53 53 * 54 54 * @param array $elements See {@link Walker::walk()}. 55 55 * @param int $max_depth See {@link Walker::walk()}. 56 * @param mixed ...$argsOptional additional arguments.56 * @param array $args Optional additional arguments. 57 57 * @return string See {@link Walker::walk()}. 58 58 */ 59 public function walk( $elements, $max_depth, ...$args) {59 public function do_walk( $elements, $max_depth, $args = array() ) { 60 60 $output = ''; 61 61 62 62 if ( $max_depth < -1 ) // Invalid parameter. … … class BP_Walker_Nav_Menu extends Walker_Nav_Menu { 212 212 $output .= apply_filters( 'bp_walker_nav_menu_start_el', $item_output, $item, $depth, $args ); 213 213 } 214 214 } 215 216 if ( version_compare( bp_get_major_wp_version(), '5.3', '<' ) ) { 217 require_once dirname( __DIR__ ) . '/compat/php53/class-bp-compat-walker-nav-menu.php'; 218 } else { 219 require_once dirname( __DIR__ ) . '/compat/php56/class-bp-compat-walker-nav-menu.php'; 220 } -
new file src/bp-core/compat/php53/class-bp-compat-walker-nav-menu.php
diff --git src/bp-core/compat/php53/class-bp-compat-walker-nav-menu.php src/bp-core/compat/php53/class-bp-compat-walker-nav-menu.php new file mode 100644 index 000000000..7bfc6f9c8
- + 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 * Create HTML list of BP nav items. 15 * 16 * @since 1.7.0 17 */ 18 class BP_Walker_Nav_Menu extends BP_Walker_Nav_Menu_Compat { 19 /** 20 * Compat method to extend Walker_Nav_Menu::walk() in PHP < 5.6. 21 * 22 * @since 5.1.0 23 * 24 * @param array $elements See {@link Walker::walk()}. 25 * @param int $max_depth See {@link Walker::walk()}. 26 */ 27 public function walk( $elements, $max_depth ) { 28 $args = array_slice( func_get_args(), 2 ); 29 30 return $this->do_walk( $elements, $max_depth, $args ); 31 } 32 } -
new file src/bp-core/compat/php56/class-bp-compat-walker-nav-menu.php
diff --git src/bp-core/compat/php56/class-bp-compat-walker-nav-menu.php src/bp-core/compat/php56/class-bp-compat-walker-nav-menu.php new file mode 100644 index 000000000..0e35f37cc
- + 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 /** 14 * Create HTML list of BP nav items. 15 * 16 * @since 1.7.0 17 */ 18 class BP_Walker_Nav_Menu extends BP_Walker_Nav_Menu_Compat { 19 /** 20 * Compat method to extend Walker_Nav_Menu::walk() in PHP > 5.6. 21 * 22 * @since 5.1.0 23 * 24 * @param array $elements See {@link Walker::walk()}. 25 * @param int $max_depth See {@link Walker::walk()}. 26 * @param mixed ...$args See {@link Walker::walk()}. 27 */ 28 public function walk( $elements, $max_depth, ...$args ) { // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ellipsisFound 29 return $this->do_walk( $elements, $max_depth, $args ); 30 } 31 } -
new file 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 new file mode 100644 index 000000000..75f4866c2
- + 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 }