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

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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度