From 30a3bde940cac973a6ac7b2acccec981d8ce34f5 Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Tue, 13 Jun 2023 11:07:22 +0200 Subject: [PATCH] Unify add menu/submenu parameters with WP [MAILPOET-5383] --- mailpoet/lib/WP/Functions.php | 15 +++++---------- mailpoet/tasks/phpstan/phpstan.neon | 5 +++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mailpoet/lib/WP/Functions.php b/mailpoet/lib/WP/Functions.php index 704c103369..8ea073b691 100644 --- a/mailpoet/lib/WP/Functions.php +++ b/mailpoet/lib/WP/Functions.php @@ -77,17 +77,12 @@ class Functions { * @param string $menuTitle * @param string $capability * @param string $menuSlug - * @param callable $callback|null + * @param callable|'' $callback * @param string $iconUrl * @param int $position - * @return string The resulting page's hook_suffix. * @return string */ - public function addMenuPage($pageTitle, $menuTitle, $capability, $menuSlug, callable $callback = null, $iconUrl = '', $position = null) { - if (is_null($callback)) { - $callback = function () { - }; - } + public function addMenuPage($pageTitle, $menuTitle, $capability, $menuSlug, $callback = '', $iconUrl = '', $position = null) { return add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $callback, $iconUrl, $position); } @@ -109,12 +104,12 @@ class Functions { * @param string $menuTitle * @param string $capability * @param string $menuSlug - * @param callable $function + * @param callable|'' $callback * @param int $position * @return string|false */ - public function addSubmenuPage($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, callable $function, $position = null) { - return add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function, $position); + public function addSubmenuPage($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $callback = '', $position = null) { + return add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $callback, $position); } public function adminUrl($path = '', $scheme = 'admin') { diff --git a/mailpoet/tasks/phpstan/phpstan.neon b/mailpoet/tasks/phpstan/phpstan.neon index f7ad30fef7..abe4afb48d 100644 --- a/mailpoet/tasks/phpstan/phpstan.neon +++ b/mailpoet/tasks/phpstan/phpstan.neon @@ -96,6 +96,11 @@ parameters: message: "#^Cannot cast string|void to string\\.$#" count: 2 path: ../../lib/Automation/Integrations/WooCommerce/Fields/CustomerReviewFieldsFactory.php + - + # WP annotates parameter as callable, but passes empty string as a default. + message: '/function add_(sub)?menu_page expects callable\(\): mixed, ''''\|\(callable\(\): mixed\) given/' + count: 2 + path: ../../lib/WP/Functions.php reportUnmatchedIgnoredErrors: true dynamicConstantNames: