Administration: Relax the default value check for the $position argument added to add_submenu_page() and related functions in [46197].

Due to a confusion with `add_menu_page()`, which takes the `$icon_url` parameter, while `add_submenu_page()` does not, some plugins were passing in a string instead of integer as `$position`, causing backward compatibility issues.

A `_doing_it_wrong()` message is now added to alert developers of the wrong parameter type.

Props david.binda, desrosj, 123host, dennis_f, MattyRob.
Reviewed by desrosj.
Fixes #48249.

git-svn-id: https://develop.svn.wordpress.org/trunk@46570 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-10-22 17:50:45 +00:00
parent 747f8e2186
commit 7ee1e12715

View File

@ -1373,7 +1373,19 @@ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability,
}
$new_sub_menu = array( $menu_title, $capability, $menu_slug, $page_title );
if ( null === $position ) {
if ( ! is_int( $position ) ) {
if ( null !== $position ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: %s: add_submenu_page() */
__( 'The seventh parameter passed to %s should be an integer representing menu position.' ),
'<code>add_submenu_page()</code>'
),
'5.3.0'
);
}
$submenu[ $parent_slug ][] = $new_sub_menu;
} else {
// If position is equal or higher than the number of items in the array, append the submenu.