wordpress-stubs icon indicating copy to clipboard operation
wordpress-stubs copied to clipboard

`add_submenu_page` parameter `$callback` should accept `''|callable`

Open lipemat opened this issue 1 year ago • 1 comments

The definition for the add_submenu_page in WP core is as follows:

/**
 * @param string    $parent_slug The slug name for the parent menu (or the file name of a standard
 *                               WordPress admin page).
 * @param string    $page_title  The text to be displayed in the title tags of the page when the menu
 *                               is selected.
 * @param string    $menu_title  The text to be used for the menu.
 * @param string    $capability  The capability required for this menu to be displayed to the user.
 * @param string    $menu_slug   The slug name to refer to this menu by. Should be unique for this menu
 *                               and only include lowercase alphanumeric, dashes, and underscores characters
 *                               to be compatible with sanitize_key().
 * @param callable  $callback    Optional. The function to be called to output the content for this page.
 * @param int|float $position    Optional. The position in the menu order this item should appear.
 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
 */
function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {

It works fine unless you need to change the $position without adding a $callback. If you pass a callable which returns something empty, the page's output is not shown.

https://phpstan.org/r/637542cd-836e-46a5-af42-ac3111483242

lipemat avatar Jan 31 '24 20:01 lipemat