0

尝试激活我的插件时,wordpress 出现此错误:

插件无法激活,因为它触发了致命错误。解析错误:语法错误,第 79 行的意外 T_FUNCTION

第 79 行是下面代码段的第一行,从调查来看,我认为这是因为 PHP 版本错误,因为我无法控制更新 php,如何使其与早期版本兼容?

add_action('admin_menu', function(){
        Plugin_Options::add_menu_page();
    });
4

2 回答 2

3

Your plugin requires PHP version 5.3.x for function, earlier versions of PHP give you that syntax error message.

Wordpress does not offer a mechanism to make plugins tell which dependency they need so they need to be activated and care on their own (or just fail as in your case).

You can just add it this way instead:

add_action('admin_menu', 'Plugin_Options::add_menu_page');

And done. That's a static class method call (As of PHP 5.2.3, Type 4 callable in the Callback ExampleDocs), PHP 5.2.3 is within the minimum PHP version requirements of wordpress (that's since WordPress 3.1), so this looks like the preferred method.

于 2012-05-06T12:17:34.783 回答
2

很可能,您的 PHP 版本小于 5.3。PHP 5.3 中添加了匿名函数。为了利用这一点,您可以将函数作为回调字符串传递,例如:

function add_menu_callback() {
  Plugin_Options::add_menu_page();
}

add_action('admin_menu', 'add_menu_callback');
于 2012-05-06T12:13:38.457 回答