PHP functions.php 500错误意外[]

时间:2015-10-20 21:43:48

标签: php wordpress function

我的PHP代码在本地运行良好,但只要我将它放在实时服务器上就会占用整个网站。在调查错误日志之后,这行代码中使用的[]存在问题:

/**
 * @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');

这里有完整的php,我该如何解决这个问题?

{{1}}

2 个答案:

答案 0 :(得分:2)

[]是一个空数组的PHP简写。 http://php.net/manual/en/language.types.array.php

但是你需要PHP 5.4以上才能工作。

如果它在本地工作但远程失败,则远程服务器可能正在运行&lt; PHP 5.4

答案 1 :(得分:-1)

Please call javascript with thid code
wp_enqueue_script( 'jquery', '//fake-jquery-script.js', array('jquery'), '2015-10-26' );
and Please download fake-jquery-script.js .and put on the projects js template folder and call javascript in 
wp_enqueue_script( 'jquery', '//fake-jquery-script.js', array('jquery'), '2015-10-26' );