Hello @juliesuccess . Thank you for asking because this is probably a common issue since upgrading to WP 5.3.0 for some people.
……………………………………..
After upgrading to WordPress 5.3.0, you may notice this error notice that was added:
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 /var/www/html/wp-includes/functions.php on line 4903
To find out where the code is that’s originally causing the error, we can review the stacktrace of execution. PHP’s debug_backtrace
is the function to call to review part of the stacktrace, https://www.php.net/manual/en/function.debug-backtrace.php.
The error notice tells us where we should put this code: /var/www/html/wp-includes/functions.php on line 4903
That line looks like this:
trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
After that line is where we’ll put a backtrace print to review some of the stacktrace:
debug_print_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 5 );
Once the code changes have been uploaded, you can refresh the page that is outputting the errors to now see 5 steps back of the stacktrace, which is hopefully enough for you to identify the source. Here’s what it output for me:
#0 _doing_it_wrong() called at [/var/www/html/wp-admin/includes/plugin.php:1385]
#1 add_submenu_page() called at [/var/www/html/wp-content/plugins/child-theme-generator/admin/class-child-theme-generator-admin.php:122]
#2 Ch_Th_Gen_Admin->create_menu() called at [/var/www/html/wp-includes/class-wp-hook.php:288]
#3 WP_Hook->apply_filters() called at [/var/www/html/wp-includes/class-wp-hook.php:312]
#4 WP_Hook->do_action() called at [/var/www/html/wp-includes/plugin.php:478]
If you still can’t find where the original function call was made, increase the backtrace limit integer parameter. In this case, we were looking for where the problematic add_submenu_page()
was called. It shows as #1 in my backtrace.
After finding the root of the error, it’s good to remove all code changes made to WordPress Core files since they will be overwritten when updating WordPress again. It’s best to keep your WordPress install as pure as possible so that all your code changes are somewhere more manageable.
To not even edit WP Core code to begin with, you can utilize the doing_it_wrong_run
action hook:
/**
* Fires when the given function is being used incorrectly.
*
* @since 3.1.0
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
do_action( 'doing_it_wrong_run', $function, $message, $version );