diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e61c7d525fe91..fc68bf3237b23 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -58,7 +58,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 7f8f23485086a..c8b686d27d6fc 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 WP_Optional_Callback */ 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 WP_Optional_Callback */ 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 WP_Optional_Callback $admin_header_callback + * @phpstan-param WP_Optional_Callback $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 367ba04cdc340..e31919d5945cc 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 WP_Optional_Callback */ 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 WP_Optional_Callback */ 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 WP_Optional_Callback $admin_header_callback + * @phpstan-param WP_Optional_Callback $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/plugin.php b/src/wp-admin/includes/plugin.php index c627e6d8f55d5..cedc7e49a89f6 100644 --- a/src/wp-admin/includes/plugin.php +++ b/src/wp-admin/includes/plugin.php @@ -1384,23 +1384,24 @@ 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 '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 '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 WP_Optional_Callback $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; @@ -1484,20 +1485,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 WP_Optional_Callback $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, @@ -1604,15 +1606,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 WP_Optional_Callback $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 ); @@ -1630,15 +1633,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 WP_Optional_Callback $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 ); @@ -1656,15 +1660,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 WP_Optional_Callback $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 ); @@ -1682,15 +1687,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 WP_Optional_Callback $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 ); @@ -1708,15 +1714,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 WP_Optional_Callback $callback */ function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { if ( current_user_can( 'edit_users' ) ) { @@ -1739,15 +1746,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 WP_Optional_Callback $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 ); @@ -1765,15 +1773,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 WP_Optional_Callback $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 ); @@ -1791,15 +1800,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 WP_Optional_Callback $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 ); @@ -1817,15 +1827,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 WP_Optional_Callback $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 ); @@ -1843,15 +1854,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 WP_Optional_Callback $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 ); @@ -1869,15 +1881,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 WP_Optional_Callback $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 49ecfb65977f4..459b666397994 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -3120,9 +3120,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 a3e9afacdb8dc..23d8351bd90b3 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 06c4a96507d75..a59ec79f66d5f 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/base.neon b/tests/phpstan/base.neon index 863d2b684d0ac..25cb011c4492a 100644 --- a/tests/phpstan/base.neon +++ b/tests/phpstan/base.neon @@ -271,6 +271,12 @@ parameters: } ''' + # An optional callback that is called without arguments, such as an admin page or + # custom header callback. Core treats an empty string or null as no callback. + WP_Optional_Callback: ''' + ''|(callable(): mixed)|null + ''' + # The properties of a block style as WP_Block_Styles_Registry stores them, which is # more than its register() hash accepts: `name` is required for a style to be # registered at all, and `label` is filled in from the name when the caller omits 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