donkey111111 2013-01-24 11:31
浏览 42
已采纳

wordpress插件错误在服务器上

i wrote a plugin and it successfully works on my localhost.But when i install it my server and want to activate it fails.

Plugin could not be activated because it triggered a fatal error.

Parse error: syntax error, unexpected T_FUNCTION in /home/ozcanco/public_html/said/wp-content/plugins/Archive/my-plugin.php on line 22

But when i run this plugin on my local it successfully works.By the way my wordpress versions are same,on local and server.How come this happen?

The line 22 is like that:

   add_action('loop_start', function($query) use ($allContent){     
  • 写回答

1条回答 默认 最新

  • dpii73380 2013-01-24 11:38
    关注

    That inline function you have is called an anonymous function, or a closure. Closures only became part of PHP in version 5.3, so if your servier is running 5.2 or lower it will not support them.

    http://php.net/manual/en/functions.anonymous.php

    If upgrading the server is not an option, then as krike suggested in the comment, you could use a callback function instead:

    add_action('loop_start', 'loopStartCallback');
    
    function loopStartCallback($query) {
        global $allContent;
        // body of the closure goes here
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决