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.
Built from https://develop.svn.wordpress.org/trunk@46570


git-svn-id: http://core.svn.wordpress.org/trunk@46367 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-10-22 17:52:04 +00:00
parent 4e06f0ad40
commit 0609e04266
2 changed files with 14 additions and 2 deletions

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.

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-RC1-46569';
$wp_version = '5.3-RC1-46570';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.