3

I'm testing WordPress 5.3 (5.3-RC4-46673) with my theme. I have WP_DEBUG enabled. I notice the following error in the dashboard now:

Notice: add_submenu_page was called incorrectly. The seventh parameter passed to add_submenu_page() should be an integer representing menu position. Please see Debugging in WordPress for more information. (This message was added in version 5.3.0.) in /app/wp-includes/functions.php on line 4903

There's a related ticket for this error here: Trac Ticket #48249

Troubleshooting The theme I'm using is a child theme.

  • Disabled all plugins, issue persists.
  • Issue happens with child them active and parent theme active.
  • Issue goes away with twentynineteen.

So it's definitely within the theme. Just not sure how to go about tracking this down.

1
  • If I understood correctly, the issue is there even when the active theme is the parent theme. That means the parent theme is creating a submenu page with a wrong argument, probably due to the confusion between add_menu_page and add_submenu_page. The best course of action would be to contact the author of the parent theme, so that he can patch it. Commented Nov 8, 2019 at 1:21

4 Answers 4

4

I was able to track this down to the culprit function add_theme_page(). There

There was an additional parameter, per the codex for add_theme_page() that needed to be removed. Removing that seemed to help.

function fivehundred_register_admin_menu() {
  add_theme_page(
    '500 Settings',
    '500 Settings',
    'manage_options',
    'theme-settings',
    'fivehundred_admin_menu',
    plugins_url( '/ignitiondeck/images/ignitiondeck-menu.png' )
  );
}

add_action(
  'admin_menu',
  'fivehundred_register_admin_menu'
);

Fixed code

function fivehundred_register_admin_menu() {
  add_theme_page(
    '500 Settings',
    '500 Settings',
    'manage_options',
    'theme-settings',
    'fivehundred_admin_menu'
  );
}

add_action(
  'admin_menu',
  'fivehundred_register_admin_menu'
);

1
1

This Notice can be triggered by several variations/wrappers of the function add_submenu_page.

as of WP v5.8

  • add_plugins_page
  • add_users_page
  • add_dashboard_page
  • add_posts_page
  • add_media_page
  • add_links_page
  • add_pages_page
  • add_comments_page
  • add_management_page
  • add_options_page
  • add_theme_page

To narrow the scope looking for the right function, we can modify the core file ./wp-admin/includes/plugin.php ( around line 1420 ) to be more verbose about it.

_doing_it_wrong(
  __FUNCTION__,
  sprintf(
    /* translators: %s: add_submenu_page() */
    __( 'The seventh parameter passed to %s should be an integer representing menu position. %s' ),
    '<code>add_submenu_page()</code>',
    print_r( $new_sub_menu, true )
  ),
  '5.3.0'
);

In my case the offending function was add_dashboard_page

add_dashboard_page(
  'Link Builder',
  'Link Builder',
  'manage_options',
  'mytheme-woocommerce-helper',
  array( $this, 'mytheme_woocommerce_helper_create_admin_page' ),
  'dashicons-admin-generic',
  2
);

Notice before edit core file:

PHP Notice:  add_submenu_page was called <strong>incorrectly</strong>. 
The seventh parameter passed to <code>add_submenu_page()</code> 
should be an integer representing menu position.  
Please see <a href="https://wordpress.org/support/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. 
(This message was added in version 5.3.0.) in wp-includes/functions.php on line 5535

Notice after edit core file:

PHP Notice:  add_submenu_page was called <strong>incorrectly</strong>. 
The seventh parameter passed to <code>add_submenu_page()</code> 
should be an integer representing menu position.  
Array
(
   [0] => Link Builder
   [1] => manage_options
   [2] => mytheme-woocommerce-helper
   [3] => Link Builder
)

warning/disclaimer/notes

Do this edit only in a development instance. WP core updates or upgrades will revert the changes. Plugins like wordfence will emit a warning and maybe revert the changes.

0

This same error is also being applied to argument issues in the add_pages_page() function.

For anyone else not using add_theme_page() or add_submenu_page() functions look for your usage of add_pages_page() and correct the arguments.

In my case I needed to remove the first argument which was null and give the page a title.

0

You could avoid the warning by adding the seventh parameter as null.

function fivehundred_register_admin_menu() {
  add_theme_page(
    '500 Settings',
    '500 Settings',
    'manage_options',
    'theme-settings',
    'fivehundred_admin_menu',
    plugins_url( '/ignitiondeck/images/ignitiondeck-menu.png' ),
    null
  );
}

add_action(
  'admin_menu',
  'fivehundred_register_admin_menu'
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.