Administration: Trigger a notice for incorrect add_menu_page() parameter.

Trigger a notice (via `_doing_it_wrong()`) for developers incorrectly setting the position when calling `add_menu_page()`.

Modify a similar message in `add_submenu_page()` to combine near identical strings and match the error description to the conditions in which it is called.

Follow up to [52569], [53104].

Fixes #40927.


git-svn-id: https://develop.svn.wordpress.org/trunk@53264 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson 2022-04-26 02:57:22 +00:00
parent 9eb6c11755
commit 79c8fbe3dc

View File

@ -1325,6 +1325,19 @@ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $call
$new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $icon_class . $hookname, $hookname, $icon_url );
if ( null !== $position && ! is_numeric( $position ) ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: %s: add_menu_page() */
__( 'The seventh parameter passed to %s should be numeric representing menu position.' ),
'<code>add_menu_page()</code>'
),
'6.0.0'
);
$position = null;
}
if ( null === $position || ! is_numeric( $position ) ) {
$menu[] = $new_menu;
} elseif ( isset( $menu[ (string) $position ] ) ) {
@ -1421,7 +1434,7 @@ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability,
__FUNCTION__,
sprintf(
/* translators: %s: add_submenu_page() */
__( 'The seventh parameter passed to %s should be an integer representing menu position.' ),
__( 'The seventh parameter passed to %s should be numeric representing menu position.' ),
'<code>add_submenu_page()</code>'
),
'5.3.0'