Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#48702 closed defect (bug) (worksforme)

[function] => add_submenu_page

Reported by: j3gaming's profile j3gaming Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Got this immediately after updating
(Triggered by my overly cautious error reporting)

Array
(
    [0] => Array
        (
            [function] => CustomStackTrace
            [args] => Array
                (
                    [0] => 1024
                    [1] => 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.)
                    [2] => C:\inetpub\wwwroot\wp-includes\functions.php
                    [3] => 4903
                    [4] => Array
                        (
                            [function] => add_submenu_page
                            [message] => The seventh parameter passed to add_submenu_page() should be an integer representing menu position. Please see Debugging in WordPress for more information.
                            [version] => (This message was added in version 5.3.0.)
                        )

                )

        )

    [1] => Array
        (
            [file] => C:\inetpub\wwwroot\wp-includes\functions.php
            [line] => 4903
            [function] => trigger_error
            [args] => Array
                (
                    [0] => 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.)
                )

        )

    [2] => Array
        (
            [file] => C:\inetpub\wwwroot\wp-admin\includes\plugin.php
            [line] => 1385
            [function] => _doing_it_wrong
            [args] => Array
                (
                    [0] => add_submenu_page
                    [1] => The seventh parameter passed to add_submenu_page() should be an integer representing menu position. Please see Debugging in WordPress for more information.
                    [2] => (This message was added in version 5.3.0.)
                )

        )

    [3] => Array
        (
            [file] => C:\inetpub\wwwroot\wp-content\functions\Sidebar.php
            [line] => 76
            [function] => add_submenu_page
            [args] => Array
                (
                    [0] => Reporting
                    [1] => Labour Hours
                    [2] => Labour Hours
                    [3] => reporting_dashboard
                    [4] => LabourHours
                    [5] => ShowLabourHours
                    [6] => https://fillmore.mobi/wp-content/uploads/2018/07/pin.png
                    [7] => 2
                )

        )

    [4] => Array
        (
            [file] => C:\inetpub\wwwroot\wp-includes\class-wp-hook.php
            [line] => 288
            [function] => custom_menu_page_removing
            [args] => Array
                (
                    [0] => 
                )

        )

    [5] => Array
        (
            [file] => C:\inetpub\wwwroot\wp-includes\class-wp-hook.php
            [line] => 312
            [function] => apply_filters
            [class] => WP_Hook
            [object] => WP_Hook Object
                (
                    [callbacks] => Array
                        (
                            [10] => Array
                                (
                                    [_add_post_type_submenus] => Array
                                        (
                                            [function] => _add_post_type_submenus
                                            [accepted_args] => 1
                                        )

Change History (9)

#1 @j3gaming
5 years ago

By the way, the default param is "null"
https://developer.wordpress.org/reference/functions/add_submenu_page/

This is what my call looks like, I'm excluding the 7th param.
add_submenu_page('activeadmin', "Users", "Users", 'administrator', 'Users', 'ActiveAdminUsers');

#2 @j3gaming
5 years ago

Last note, did the ability to pass in an icon get removed?
8 param total:

add_submenu_page('Reporting', 'Labour Hours', 'Labour Hours', 'reporting_dashboard', 'LabourHours', 'ShowLabourHours' , $iconPin, 2);

#3 @garrett-eclipse
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hello @j3gaming thanks for the report.

Looking at your stack trace the _doing_it_wrong error message is being triggered as you're supplying one too many params to add_submenu_page. Specifically, the icon there as only add_menu_page has ever supported an icon parameter. The add_submenu_page to my knowledge never supported an icon, could be an interesting feature though if you want to open an enhancement request for that (It would require UI changes to support a space for icons on submenus).

The reason why you're seeing an error now with the update is previously it was simply ignoring the extra params and now with 5.3 it will detect if the $position param isn't an int or null and throw the error. As your icon is in the place of $position it's what's triggering the error.

I'm going to close this as invalid as you should be able to just correct the function signature by removing $iconPin from the function call to add_submenu_page.
P.S. That being said there is an outstanding bug for add_submenu_page being trac'd here (#48599), but I don't believe it should affect you as your menu_slug and parent_slug are unique in your add_submenu_page call.

#4 follow-up: @j3gaming
5 years ago

@garrett-eclipse

Your explanation, and what is happening are slightly different.
This is my line of code:
add_submenu_page('activeadmin', "Users", "Users", 'administrator', 'Users', 'ActiveAdminUsers');

Notice 6 parameters right? I'm assuming the 7th parameter (position) is being passed as null.
That causes this:
The seventh parameter passed to add_submenu_page() should be an integer representing menu position

null != int

#5 @j3gaming
5 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

#6 @SergeyBiryukov
5 years ago

  • Component changed from General to Administration
  • Description modified (diff)
  • Milestone set to Awaiting Review

#7 in reply to: ↑ 4 ; follow-up: @SergeyBiryukov
5 years ago

Replying to j3gaming:

This is my line of code:
add_submenu_page('activeadmin', "Users", "Users", 'administrator', 'Users', 'ActiveAdminUsers');

Notice 6 parameters right?

Right, but you have 8 parameters here, per comment:2:

add_submenu_page('Reporting', 'Labour Hours', 'Labour Hours', 'reporting_dashboard', 'LabourHours', 'ShowLabourHours' , $iconPin, 2);

It's the $iconPin that triggers a _doing_it_wrong() error message.

I'm assuming the 7th parameter (position) is being passed as null.
That causes this:
The seventh parameter passed to add_submenu_page() should be an integer representing menu position

null != int

The default value of null does not trigger the error message, as it specifically checks for null:

if ( ! is_int( $position ) ) {
	if ( null !== $position ) {
		_doing_it_wrong(
			__FUNCTION__,
			sprintf(
				/* translators: %s: add_submenu_page() */
				__( 'The seventh parameter passed to %s should be an integer representing menu position.' ),
				'<code>add_submenu_page()</code>'
			),
			'5.3.0'
		);
	}

	$submenu[ $parent_slug ][] = $new_sub_menu;
}

#8 in reply to: ↑ 7 @j3gaming
5 years ago

  • Resolution set to worksforme
  • Status changed from reopened to closed

Replying to SergeyBiryukov:
I was confusing 2 different areas of where I use add_submenu_page
Thank you, yes the default null param works as intended.

I'll mark this as closed for you guys. Again thank you for the awesome support.

#9 @garrett-eclipse
5 years ago

  • Milestone Awaiting Review deleted
  • Version 5.3 deleted

Awesome glad to hear @j3gaming and thanks @SergeyBiryukov for responding while I was out to lunch.

Note: See TracTickets for help on using tickets.