• Resolved Michelle Blanchette

    (@michelleblanchette)


    Hello!

    I am a fellow WordPress developer and have noticed an error being logged caused by this plugin’s Ch_Th_Gen_Admin::create_menu() code.

    In /wp-content/plugins/child-theme-generator/admin, line 122, a dashicons icon name is provided as a seventh parameter in the add_submenu_page() call. Because of this, the menu priority is not the seventh/last parameter.

    A submenu page does not take an icon as a parameter like a toplevel admin page: https://developer.wordpress.org/reference/functions/add_submenu_page/

    Here is the debug notice that gets displayed from this:
    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

    Have a nice day!

    Michelle

Viewing 15 replies - 1 through 15 (of 25 total)
  • Plugin Author Serafino

    (@seraph63)

    Hi Michelle,
    thank you for error reporting, I have fixed and the issue would be solved.

    If you would check and let me know.

    Thanks & Regards

    Thread Starter Michelle Blanchette

    (@michelleblanchette)

    Hello Serafino,

    The error is still there and I do not see any changes to that function in the code. Did you not commit your changes?

    All you need to do is delete line 122: https://plugins.trac.wordpress.org/browser/child-theme-generator/tags/2.2.4/admin/class-child-theme-generator-admin.php#L122

    Also, the changelog says v2.1.4, but the downloaded and most recent version on here is tagged 2.2.4.

    Plugin Author Serafino

    (@seraph63)

    Changes was made only in trunk folder, sorry.
    Tags/2.2.4 now is updated, please check.

    Thread Starter Michelle Blanchette

    (@michelleblanchette)

    Great! I see the change and have updated the plugin. The error is now gone.

    Thank you for the super quick fix and great plugin! Cheers!

    Hi Michelle @michelleblanchette ,
    I’m newer to WordPress Development. Can you tell me how you found out which plugin was the problem? I have the exact error:
    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
    but I don’t have this plugin. Any help would be appreciated! Thanks!

    Thread Starter Michelle Blanchette

    (@michelleblanchette)

    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 );
    

    @michelleblanchette That’s so nice of you. I have a basic understanding of code so I will be trying this. I may get back to you with more questions if I get stuck! 😉 Thanks again!

    Hi guys,

    1. Thx for the good plugin.

    2. i also have this problem with the line 4903:

    PHP Notice: add_submenu_page wurde fehlerhaft aufgerufen. Der siebte Paramater, der an add_submenu_page() übergeben wird, sollte ein ganzzahliger Wert sein, der eine Menüposition repräsentiert. Weitere Informationen: Debugging in WordPress (engl.) (Diese Meldung wurde in Version 5.3.0 hinzugefügt.) in /var/home/murau-botschafter_at/www/wp-includes/functions.php on line 4903

    3. Do i need to solve it?

    4. How should i solve it?

    5. Just upgrade to next version?

    Thx. Best regards.
    Thomas

    @michelleblanchette I got it! Thanks. Is it best to contact the plugin developer, or can I change it myself? I understand what you mean about the core and that it will update. Thanks.

    @neumeith: @michelleblanchette answered it above. It worked! 🙂

    Thread Starter Michelle Blanchette

    (@michelleblanchette)

    @juliesuccess I recommend notifying the plugin developer of the problematic code because you will have to patch it every time you update the plugin. Your fix will be replaced by all of their code if you make edits directly. (Just like editing and updating WP Core directly.)

    So I recommend notifying the plugin developer, but also noting the fix yourself in case the plugin developer does not implement the fix for future releases. Also, you’ll have the fix in place immediately while waiting on the plugin developer to implement the fix on their end. 🙂

    @michelleblanchette Thanks again! 🙂

    @michelleblanchette Very helpful – thanks! Solved my problem!

    Hi Michelle,
    @michelleblanchette

    I’m having the same issue, but mine deals with OceanWP child theme.

    So to solve this issue in your example did you delete line 122 in class-child-theme-generator-admin.php? What were the steps you made to resolve this issue after the backtrace print?

    ” #1 add_submenu_page() called at [/var/www/html/wp-content/plugins/child-theme-generator/admin/class-child-theme-generator-admin.php:122]”

    Thread Starter Michelle Blanchette

    (@michelleblanchette)

    Hi @joey12 ,

    The backtrace print shows you where in the code you need to be looking for issues. In my case, I knew the parameters provided in the function call were incorrect and I also knew how it gets fixed. More specifically, there was an extra parameter provided to the function call. Comparing the problematic usage to the function’s documentation/source clues you in to if a function is being used properly, which helped me know, for instance, which parameter needed to be removed.

    If you are struggling to understand the issue in the code and why it is throwing an error, I definitely suggest reaching out to the plugin developer and telling them what the error is. Even better, you can now tell them that you at least found the file and line that are the root of the problem!

    Even if you have fixed the problem for yourself, it’s still good to notify the developer so they can implement the fix for later releases.

    I hope this helps!

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘add_submenu_page debugging’ is closed to new replies.