doudongdang4483 2015-10-20 21:43
浏览 110

PHP functions.php 500错误意外[]

My PHP code below works great locally but as soon as I put this on the live server it takes the whole site down. After investigation error logs, it has an issue with the [] used in this line of code:

wp_enqueue_script( 'jquery', '//fake-jquery-script.js', [], null );

Here's the php in full, how do I get around this issue?

/**
 * @desc De-register WP jquery
 **/
 add_action( 'wp_print_scripts', 'de_script', 100 );

 function de_script() {
     wp_dequeue_script( 'jquery' );
     wp_deregister_script( 'jquery' );

 }

 /**
  * Inject jQuery early if there's a Gravity Form
  */
 function gc_gform_inject_jquery( $content = '' ) {
     global $gc_jquery_loaded_before_gform;

     if ( !isset( $gc_jquery_loaded_before_gform )) {

         // set global variable so jQuery isn't loaded twice
         $gc_jquery_loaded_before_gform = true;

         // inject jQuery code
         echo '<!-- loading jquery before Gravity Form inline scripts -->';
         gc_load_jquery_cdn_and_fallback();
     }
     return $content;
 }
 add_filter( 'gform_cdata_open', 'gc_gform_inject_jquery' );

 /**
  * Load jQuery in the footer or before the first Gravity Form.
  * Include a local fallback if the Google CDN fails (e.g. User is in China)
  */
     function gc_load_jquery_cdn_and_fallback() {
     // Google CDN
     echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery'. (SCRIPT_DEBUG ? '.js' : '.min.js') .'"></script>';
     // Local fallback
     echo '<script>if (!window.jQuery) { document.write(\'<script src="'. get_stylesheet_directory_uri() .'/js/vendor/jquery-1.11.2'. (SCRIPT_DEBUG ? '.js' : '.min.js') .'"><\/script>\'); }</script>';
     }

 /**
  * Loading jQuery and jQuery-dependent scripts
  * If jQuery was not already loaded before a Gravity Form, load it
  * Also enqueue a fake version of it (for dependencies) and then
  * remove this fake script
  */
 function gc_load_javascript_in_footer() {
     global $gc_jquery_loaded_before_gform;

     // If jQuery has not been loaded already, load it
     if ($gc_jquery_loaded_before_gform !== true) {
         gc_load_jquery_cdn_and_fallback();
     }

     // Enqueue a fake script called "jquery" to for dependent enqueued scripts
     // HERE'S THE PROBLEM
     wp_enqueue_script( 'jquery', '//fake-jquery-script.js', [], null );

     // Remove the fake script
     function gc_remove_fake_jquery_script($tag) {
         $tag = ( strpos($tag, 'fake-jquery-script') !== false ) ? '' : $tag;
         return $tag;
     }
     add_filter( 'script_loader_tag', 'gc_remove_fake_jquery_script' );
 }
 add_action('wp_footer', 'gc_load_javascript_in_footer');
  • 写回答

2条回答 默认 最新

  • doufen9815 2015-10-20 21:47
    关注

    [] is PHP short hand for an empty array. http://php.net/manual/en/language.types.array.php

    But you require PHP 5.4+ for it to work.

    If it works locally but fails remotely, chances are your remote server is running < PHP 5.4

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么