admin管理员组文章数量:1122846
I get messages in the debug.log for PHP Deprecated:
Optional parameter $function declared before required parameter $page is implicitly treated as a required parameter
code
function add_meta_box($id, $title, $function = '', $page, $context = 'advanced', $priority = 'default'): void
{
require_once(ABSPATH . 'wp-admin/includes/template.php');
add_meta_box($id, $title, array(&$this, $function == '' ? $id : $function), $page, $context, $priority);
}
I get messages in the debug.log for PHP Deprecated:
Optional parameter $function declared before required parameter $page is implicitly treated as a required parameter
code
function add_meta_box($id, $title, $function = '', $page, $context = 'advanced', $priority = 'default'): void
{
require_once(ABSPATH . 'wp-admin/includes/template.php');
add_meta_box($id, $title, array(&$this, $function == '' ? $id : $function), $page, $context, $priority);
}
Share
Improve this question
asked Jun 25, 2024 at 11:54
Vincenzo PiromalliVincenzo Piromalli
1989 bronze badges
1
|
1 Answer
Reset to default 3At your function declaration you need to set the required parameters first, the optional second, because you couldn't skip $function
if $page
has to be given:
function add_meta_box($id, $title, $page, $function = '', $context = 'advanced', $priority = 'default'): void
{
require_once(ABSPATH . 'wp-admin/includes/template.php');
add_meta_box($id, $title, array(&$this, $function == '' ? $id : $function), $page, $context, $priority);
}
Or make the $page
variable optional too:
function add_meta_box($id, $title, $function = '', $page = null, $context = 'advanced', $priority = 'default'): void
{
require_once(ABSPATH . 'wp-admin/includes/template.php');
add_meta_box($id, $title, array(&$this, $function == '' ? $id : $function), $page, $context, $priority);
}
Or make both required:
function add_meta_box($id, $title, $function, $page, $context = 'advanced', $priority = 'default'): void
{
require_once(ABSPATH . 'wp-admin/includes/template.php');
add_meta_box($id, $title, array(&$this, $function == '' ? $id : $function), $page, $context, $priority);
}
本文标签: pluginsPHP Deprecated function Optional parameter function
版权声明:本文标题:plugins - PHP Deprecated function Optional parameter $function 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302646a1931611.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_meta_box
exist outside the admin? Also&$this
is unnecessary and a holdover from PHP 4.x, you should never add a&
in any WordPress code written in the last 15 years, it can be removed safely with no downsides, all you need is$this
without the ampersand. Also isis_admin()
is false should it not return early? – Tom J Nowell ♦ Commented Jun 25, 2024 at 12:22