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

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 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?