diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c24619b60baf5..886049b29ddcb 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -51,7 +51,6 @@ includes: - tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon - tests/phpstan/baselines/offsetAccess.notFound.neon - tests/phpstan/baselines/offsetAssign.valueType.neon - - tests/phpstan/baselines/parameter.defaultValue.neon - tests/phpstan/baselines/parameter.notFound.neon - tests/phpstan/baselines/parameterByRef.type.neon - tests/phpstan/baselines/parameterByRef.unusedType.neon diff --git a/src/wp-admin/includes/class-custom-background.php b/src/wp-admin/includes/class-custom-background.php index e147739162baa..1e3a39da9440d 100644 --- a/src/wp-admin/includes/class-custom-background.php +++ b/src/wp-admin/includes/class-custom-background.php @@ -18,7 +18,9 @@ class Custom_Background { * Callback for administration header. * * @since 3.0.0 - * @var callable + * @var callable|string|null + * + * @phpstan-var ''|(callable(): mixed)|null */ public $admin_header_callback; @@ -26,7 +28,9 @@ class Custom_Background { * Callback for header div. * * @since 3.0.0 - * @var callable + * @var callable|string|null + * + * @phpstan-var ''|(callable(): mixed)|null */ public $admin_image_div_callback; @@ -43,10 +47,13 @@ class Custom_Background { * * @since 3.0.0 * - * @param callable $admin_header_callback Optional. Administration header callback. - * Default empty string. - * @param callable $admin_image_div_callback Optional. Custom image div output callback. - * Default empty string. + * @param callable|string|null $admin_header_callback Optional. Administration header callback. + * Empty string or null for none. Default empty string. + * @param callable|string|null $admin_image_div_callback Optional. Custom image div output callback. + * Empty string or null for none. Default empty string. + * + * @phpstan-param ''|(callable(): mixed)|null $admin_header_callback + * @phpstan-param ''|(callable(): mixed)|null $admin_image_div_callback */ public function __construct( $admin_header_callback = '', $admin_image_div_callback = '' ) { $this->admin_header_callback = $admin_header_callback; diff --git a/src/wp-admin/includes/class-custom-image-header.php b/src/wp-admin/includes/class-custom-image-header.php index a4cf43b1ce26c..147f44cc1057b 100644 --- a/src/wp-admin/includes/class-custom-image-header.php +++ b/src/wp-admin/includes/class-custom-image-header.php @@ -18,7 +18,9 @@ class Custom_Image_Header { * Callback for administration header. * * @since 2.1.0 - * @var callable + * @var callable|string|null + * + * @phpstan-var ''|(callable(): mixed)|null */ public $admin_header_callback; @@ -26,7 +28,9 @@ class Custom_Image_Header { * Callback for header div. * * @since 3.0.0 - * @var callable + * @var callable|string|null + * + * @phpstan-var ''|(callable(): mixed)|null */ public $admin_image_div_callback; @@ -51,9 +55,13 @@ class Custom_Image_Header { * * @since 2.1.0 * - * @param callable $admin_header_callback Administration header callback. - * @param callable $admin_image_div_callback Optional. Custom image div output callback. - * Default empty string. + * @param callable|string|null $admin_header_callback Administration header callback. + * Empty string or null for none. + * @param callable|string|null $admin_image_div_callback Optional. Custom image div output callback. + * Empty string or null for none. Default empty string. + * + * @phpstan-param ''|(callable(): mixed)|null $admin_header_callback + * @phpstan-param ''|(callable(): mixed)|null $admin_image_div_callback */ public function __construct( $admin_header_callback, $admin_image_div_callback = '' ) { $this->admin_header_callback = $admin_header_callback; diff --git a/src/wp-admin/includes/deprecated.php b/src/wp-admin/includes/deprecated.php index 1a7eee4811400..b3aaad1ad9a2f 100644 --- a/src/wp-admin/includes/deprecated.php +++ b/src/wp-admin/includes/deprecated.php @@ -1427,13 +1427,15 @@ function _relocate_children( $old_ID, $new_ID ) { * @see add_menu_page() * @global int $_wp_last_object_menu * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param string $icon_url Optional. The URL to the icon to be used for this menu. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param string $icon_url Optional. The URL to the icon to be used for this menu. * @return string The resulting page's hook_suffix. + * + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $icon_url = '') { _deprecated_function( __FUNCTION__, '4.5.0', 'add_menu_page()' ); @@ -1460,13 +1462,15 @@ function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $ca * @see add_menu_page() * @global int $_wp_last_utility_menu * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param string $icon_url Optional. The URL to the icon to be used for this menu. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param string $icon_url Optional. The URL to the icon to be used for this menu. * @return string The resulting page's hook_suffix. + * + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $icon_url = '') { _deprecated_function( __FUNCTION__, '4.5.0', 'add_menu_page()' ); diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php index 9fc438026ce11..2a68eae362320 100644 --- a/src/wp-admin/includes/plugin.php +++ b/src/wp-admin/includes/plugin.php @@ -1384,25 +1384,26 @@ function uninstall_plugin( $plugin ) { * @global array $_registered_pages * @global array $_parent_pages * - * @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 page 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 string $icon_url Optional. The URL to the icon to be used for this menu. - * * Pass a base64-encoded SVG using a data URI, which will be colored to match - * the color scheme. This should begin with 'data:image/svg+xml;base64,'. - * * Pass the name of a Dashicons helper class to use a font icon, - * e.g. 'dashicons-chart-pie'. - * * Pass the namespaced name of a registered icon to render it as an inline SVG, - * e.g. 'core-admin/pin'. - * * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS. - * @param int|float $position Optional. The position in the menu order this item should appear. + * @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 page and only + * include lowercase alphanumeric, dashes, and underscores characters to be compatible + * with sanitize_key(). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param string $icon_url Optional. The URL to the icon to be used for this menu. + * * Pass a base64-encoded SVG using a data URI, which will be colored to match + * the color scheme. This should begin with 'data:image/svg+xml;base64,'. + * * Pass the name of a Dashicons helper class to use a font icon, + * e.g. 'dashicons-chart-pie'. + * * Pass the namespaced name of a registered icon to render it as an inline SVG, + * e.g. 'core-admin/pin'. + * * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS. + * @param int|float $position Optional. The position in the menu order this item should appear. * @return string The resulting page's hook_suffix. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $icon_url = '', $position = null ) { global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages; @@ -1487,20 +1488,21 @@ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $call * @global array $_registered_pages * @global array $_parent_pages * - * @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. + * @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|string|null $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv, @@ -1608,15 +1610,16 @@ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, * @since 1.5.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1634,15 +1637,16 @@ function add_management_page( $page_title, $menu_title, $capability, $menu_slug, * @since 1.5.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1660,15 +1664,16 @@ function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $c * @since 2.0.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1686,15 +1691,16 @@ function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $cal * @since 3.0.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1712,15 +1718,16 @@ function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $c * @since 2.1.3 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { if ( current_user_can( 'edit_users' ) ) { @@ -1743,15 +1750,16 @@ function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $cal * @since 2.7.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1769,15 +1777,16 @@ function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, * @since 2.7.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1795,15 +1804,16 @@ function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $cal * @since 2.7.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1821,15 +1831,16 @@ function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $cal * @since 2.7.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1847,15 +1858,16 @@ function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $cal * @since 2.7.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); @@ -1873,15 +1885,16 @@ function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $cal * @since 2.7.0 * @since 5.3.0 Added the `$position` parameter. * - * @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). - * @param callable $callback Optional. The function to be called to output the content for this page. - * @param int $position Optional. The position in the menu order this item should appear. + * @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). + * @param callable|string|null $callback Optional. The function to be called to output the content for this page. + * @param int $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. * - * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param non-falsy-string $menu_slug + * @phpstan-param ''|(callable(): mixed)|null $callback */ function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 1d6962a54690f..efe5709c632de 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -3182,9 +3182,11 @@ function register_setting( $option_group, $option_name, $args = array() ) { * @global array $new_allowed_options * @global array $wp_registered_settings * - * @param string $option_group The settings group name used during registration. - * @param string $option_name The name of the option to unregister. - * @param callable $deprecated Optional. Deprecated. + * @param string $option_group The settings group name used during registration. + * @param string $option_name The name of the option to unregister. + * @param string $deprecated Optional. Deprecated. + * + * @phpstan-param '' $deprecated */ function unregister_setting( $option_group, $option_name, $deprecated = '' ) { global $new_allowed_options, $wp_registered_settings; diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index f09f6c264d5a1..38c5884c8b674 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -896,6 +896,8 @@ function plugin_dir_url( $file ) { * * @param string $file The filename of the plugin including the path. * @param callable $callback The function hooked to the 'activate_PLUGIN' action. + * + * @phpstan-param callable(bool): mixed $callback */ function register_activation_hook( $file, $callback ) { $file = plugin_basename( $file ); @@ -919,6 +921,8 @@ function register_activation_hook( $file, $callback ) { * * @param string $file The filename of the plugin including the path. * @param callable $callback The function hooked to the 'deactivate_PLUGIN' action. + * + * @phpstan-param callable(bool): mixed $callback */ function register_deactivation_hook( $file, $callback ) { $file = plugin_basename( $file ); @@ -950,6 +954,8 @@ function register_deactivation_hook( $file, $callback ) { * @param string $file Plugin file. * @param callable $callback The callback to run when the hook is called. Must be * a static method or function. + * + * @phpstan-param (callable-string|array{class-string, non-empty-string})&(callable(): mixed) $callback */ function register_uninstall_hook( $file, $callback ) { if ( is_array( $callback ) && is_object( $callback[0] ) ) { diff --git a/src/wp-includes/rewrite.php b/src/wp-includes/rewrite.php index 93e2b23b50904..485e77921c098 100644 --- a/src/wp-includes/rewrite.php +++ b/src/wp-includes/rewrite.php @@ -248,6 +248,8 @@ function remove_permastruct( $name ) { * @param callable $callback Callback to run on feed display. * @return string Feed action name. * + * @phpstan-param non-empty-string $feedname + * @phpstan-param callable(bool, non-empty-string): mixed $callback * @phpstan-return non-falsy-string */ function add_feed( $feedname, $callback ) { diff --git a/tests/phpstan/baselines/parameter.defaultValue.neon b/tests/phpstan/baselines/parameter.defaultValue.neon deleted file mode 100644 index 34b6b678fc447..0000000000000 --- a/tests/phpstan/baselines/parameter.defaultValue.neon +++ /dev/null @@ -1,105 +0,0 @@ -# PHPStan baseline for the `parameter.defaultValue` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/parameter.defaultValue -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan.neon.dist. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with -# -# composer phpstan:baselines -- --identifier=parameter.defaultValue -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Default value of the parameter \#1 \$admin_header_callback \(''''\) of method Custom_Background\:\:__construct\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/class-custom-background.php - - - message: '#^Default value of the parameter \#2 \$admin_image_div_callback \(''''\) of method Custom_Background\:\:__construct\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/class-custom-background.php - - - message: '#^Default value of the parameter \#2 \$admin_image_div_callback \(''''\) of method Custom_Image_Header\:\:__construct\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/class-custom-image-header.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_comments_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_dashboard_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_links_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_management_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_media_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_menu_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_options_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_pages_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_plugins_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_posts_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_theme_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#5 \$callback \(''''\) of function add_users_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#6 \$callback \(''''\) of function add_submenu_page\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-admin/includes/plugin.php - - - message: '#^Default value of the parameter \#3 \$deprecated \(''''\) of function unregister_setting\(\) is incompatible with type callable\(\)\: mixed\.$#' - identifier: parameter.defaultValue - count: 1 - path: ../../../src/wp-includes/option.php