From 79c8fbe3dcf816c4cbd3987c50bd968302e00035 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 26 Apr 2022 02:57:22 +0000 Subject: [PATCH] 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 --- src/wp-admin/includes/plugin.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php index 5396f7bca8..6f47c8b6c7 100644 --- a/src/wp-admin/includes/plugin.php +++ b/src/wp-admin/includes/plugin.php @@ -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.' ), + 'add_menu_page()' + ), + '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.' ), 'add_submenu_page()' ), '5.3.0'