Open
Description
Is your feature request related to a problem?
As of WP 5.3, integer menu location slugs will no longer be supported.
Refs:
- https://make.wordpress.org/core/2019/09/18/integer-menu-slugs-are-no-longer-supported-from-wordpress-5-3/
- https://core.trac.wordpress.org/ticket/45361
- https://developer.wordpress.org/reference/functions/register_nav_menus/
- https://developer.wordpress.org/reference/functions/register_nav_menu/
Describe the solution you'd like
I'd like to suggest we add a sniff to the NamingConventions
category to check code for this.
While this sniff could be a candidate for the Core
ruleset, at the very least, it should go into the Extra
ruleset (and the WPThemeReview
ruleset /cc @dingo-d ).
// OK.
register_nav_menus(
array(
'primary' => 'Primary',
'first' => 'First',
'se' . 'cond' => 'Second',
)
);
// Ignore.
register_nav_menus( $locations );
register_nav_menus( $obj->get_locations() );
register_nav_menus(
array(
MENU_ONE => 'First',
$second => 'Second',
)
);
// Bad.
register_nav_menus(
array(
1 => 'First',
'Second',
2.5 => 'Third',
false => 'Fourth',
)
);
To find inspiration for additional unit tests: https://wpdirectory.net/search/01DN3RPKFHVQ712NG72GP99D5D
Additional context (optional)
Considerations to keep in mind when writing the sniff:
- If
$locations
is passed as a variable, constant or via a function call, the sniff should just bow out as it will be very difficult to figure out the value in a reliable manner. - The sniff should check for both array values without key, as well as array values with a non-string key.
Keys set via a variable or constant should be ignored. - The
register_nav_menu()
function should be checked as well, as, while the$location
parameter is documented as astring
, the function does no variable type checking.
To be researched
Are there any other restrictions to menu slugs ? And if so, should those be covered in the same sniff ?
Think along the lines of:
- Names which shouldn't be used (reserved).
- Any restrictions to the slug name ? allowed characters, slug length, etc
Input welcome!