Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 替换wordpress中排队脚本的正确方法?_Php_Jquery_Jquery Ui_Wordpress - Fatal编程技术网

Php 替换wordpress中排队脚本的正确方法?

Php 替换wordpress中排队脚本的正确方法?,php,jquery,jquery-ui,wordpress,Php,Jquery,Jquery Ui,Wordpress,我需要从wordpress中删除jquery ui脚本(以及其他一些脚本)。问题是,如果我退出队列并取消注册它们,那么调用它们的插件将无法工作,因为脚本“丢失”,即使我通过googleapis链接用一个脚本加载所有jquery ui 我有以下资料: add_action('wp_print_scripts','remove_excess_scripts', 100); function remove_excess_scripts(){ wp_dequeue_script( 'jquery-u

我需要从wordpress中删除jquery ui脚本(以及其他一些脚本)。问题是,如果我退出队列并取消注册它们,那么调用它们的插件将无法工作,因为脚本“丢失”,即使我通过googleapis链接用一个脚本加载所有jquery ui

我有以下资料:

add_action('wp_print_scripts','remove_excess_scripts', 100);
function remove_excess_scripts(){
  wp_dequeue_script( 'jquery-ui-core' );
  wp_dequeue_script( 'jquery-ui-widget' );
  wp_dequeue_script( 'jquery-ui-mouse' );
  wp_dequeue_script( 'jquery-ui-accordion' );
  wp_dequeue_script( 'jquery-ui-autocomplete' );
  wp_dequeue_script( 'jquery-ui-slider' );
  wp_dequeue_script( 'jquery-ui-progressbar' );
  wp_dequeue_script( 'jquery-ui-tabs' );
  wp_dequeue_script( 'jquery-ui-sortable' );
  wp_dequeue_script( 'jquery-ui-draggable' );
  wp_dequeue_script( 'jquery-ui-droppable' );
  wp_dequeue_script( 'jquery-ui-selectable' );
  wp_dequeue_script( 'jquery-ui-position' );
  wp_dequeue_script( 'jquery-ui-datepicker' );
  wp_dequeue_script( 'jquery-ui-tooltip' );
  wp_dequeue_script( 'jquery-ui-resizable' );
  wp_dequeue_script( 'jquery-ui-dialog' );
  wp_dequeue_script( 'jquery-ui-button' );

  wp_deregister_script( 'jquery-ui-core' );
  wp_deregister_script( 'jquery-ui-widget' );
  wp_deregister_script( 'jquery-ui-mouse' );
  wp_deregister_script( 'jquery-ui-accordion' );
  wp_deregister_script( 'jquery-ui-autocomplete' );
  wp_deregister_script( 'jquery-ui-slider' );
  wp_deregister_script( 'jquery-ui-progressbar' );
  wp_deregister_script( 'jquery-ui-tabs' );
  wp_deregister_script( 'jquery-ui-sortable' );
  wp_deregister_script( 'jquery-ui-draggable' );
  wp_deregister_script( 'jquery-ui-droppable' );
  wp_deregister_script( 'jquery-ui-selectable' );
  wp_deregister_script( 'jquery-ui-position' );
  wp_deregister_script( 'jquery-ui-datepicker' );
  wp_deregister_script( 'jquery-ui-tooltip' );
  wp_deregister_script( 'jquery-ui-resizable' );
  wp_deregister_script( 'jquery-ui-dialog' );
  wp_deregister_script( 'jquery-ui-button' );
}
另外,在前面的函数中,我使用以下方法正确注册jquery ui并使其排队:

wp_register_script(
        'jquery-ui-all',
        "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js",
        array('jquery'),
        false,
        false
    );

(其中引导程序对jquery ui all具有依赖关系)

所有这些都是从google加载jquery ui,不再输出任何单独的ui文件的意义上起作用的——问题是,一个插件WPFullCalendar将它的脚本和一堆jquery ui单独脚本作为依赖项排队,我猜随着它们取消注册和排队,它的脚本不会得到输出缺少依赖项?我得到以下错误(由于它的JS文件没有被输出)

我如何替换脚本,使其他插件仍然可以排队或依赖它们,但它们都输出相同的文件。我可以取消注册所有的名字,然后用googleapis作为源再次注册它们,但是我仍然会收到15个不同的HTTP请求,用于所有相同的googleapi链接。。。我需要所有这些文件指向1个googleapi文件,并且只有一个文件可以输出。这可能吗?(在其他插件已经成功调用/依赖它们之后,不应该让它们退出队列吗?wp_print_脚本发生在所有插件排队之后,不是吗?)

更新:

我已经修改了下面被接受的答案,使之更具体一些,这样就相关性而言,就不会破坏任何其他内容。以下是正确注销脚本并从依赖它的任何脚本中删除它的依赖关系的更新代码。确保如果您这样做,您用来替换取消注册的脚本在HTML中的加载高度足够高(可能是头部),以便其他依赖它的脚本随后出现

//custom deregister scripts
function georgian_deregister_scripts(){
    global $wp_scripts;
    //scripts to deregister
    $deregisteredscripts = array('jquery-ui-core','jquery-ui-widget','jquery-ui-mouse','jquery-ui-accordion','jquery-ui-autocomplete','jquery-ui-slider','jquery-ui-progressbar' ,'jquery-ui-tabs','jquery-ui-sortable','jquery-ui-draggable','jquery-ui-droppable','jquery-ui-selectable','jquery-ui-position','jquery-ui-datepicker','jquery-ui-tooltip','jquery-ui-resizable','jquery-ui-dialog','jquery-ui-button');
    //degregister each script
    foreach($deregisteredscripts as $script)
      wp_deregister_script( $script );
    //remove deregistered scripts as dependencies of any other scripts depending on them  
    if(false != $wp_scripts->queue)
      foreach($wp_scripts->queue as $script)
        if(isset($wp_scripts->registered[$script]))
          $wp_scripts->registered[$script]->deps = array_diff($wp_scripts->registered[$script]->deps, $deregisteredscripts);
}
add_action('wp_enqueue_scripts', 'georgian_deregister_scripts', 101);

如果您取消注册脚本,它就不会排队,所以您有几个无用的命令

现在,如何删除要排队的(所有)脚本的依赖项?这个函数应该可以做到这一点

function customize_scripts_output(){
    global $wp_scripts;

    if(false != $wp_scripts->queue)
        foreach($wp_scripts->queue as $script)
            if(isset($wp_scripts->registered[$script]))
                $wp_scripts->registered[$script]->deps = array();
}
add_action('wp_enqueue_scripts', 'customize_scripts_output', 101);

谢谢这里的思考过程很好,但是,我对它进行了修改,只删除了使用
array\u diff()
替换的依赖项。我将在问题中添加代码,但接受您的答案-请随时为其他有类似问题的人更新您的答案。
//custom deregister scripts
function georgian_deregister_scripts(){
    global $wp_scripts;
    //scripts to deregister
    $deregisteredscripts = array('jquery-ui-core','jquery-ui-widget','jquery-ui-mouse','jquery-ui-accordion','jquery-ui-autocomplete','jquery-ui-slider','jquery-ui-progressbar' ,'jquery-ui-tabs','jquery-ui-sortable','jquery-ui-draggable','jquery-ui-droppable','jquery-ui-selectable','jquery-ui-position','jquery-ui-datepicker','jquery-ui-tooltip','jquery-ui-resizable','jquery-ui-dialog','jquery-ui-button');
    //degregister each script
    foreach($deregisteredscripts as $script)
      wp_deregister_script( $script );
    //remove deregistered scripts as dependencies of any other scripts depending on them  
    if(false != $wp_scripts->queue)
      foreach($wp_scripts->queue as $script)
        if(isset($wp_scripts->registered[$script]))
          $wp_scripts->registered[$script]->deps = array_diff($wp_scripts->registered[$script]->deps, $deregisteredscripts);
}
add_action('wp_enqueue_scripts', 'georgian_deregister_scripts', 101);
function customize_scripts_output(){
    global $wp_scripts;

    if(false != $wp_scripts->queue)
        foreach($wp_scripts->queue as $script)
            if(isset($wp_scripts->registered[$script]))
                $wp_scripts->registered[$script]->deps = array();
}
add_action('wp_enqueue_scripts', 'customize_scripts_output', 101);