/**
 * Prints the script queue in the HTML head on admin pages.
 *
 * Postpones the scripts that were queued for the footer.
 * print_footer_scripts() is called in the footer to print these scripts.
 *
 * @since 2.8
 * @see wp_print_scripts()
 */
function print_head_scripts()
{
    global $wp_scripts, $concatenate_scripts;
    if (!did_action('wp_print_scripts')) {
        do_action('wp_print_scripts');
    }
    if (!is_a($wp_scripts, 'WP_Scripts')) {
        $wp_scripts = new WP_Scripts();
    }
    script_concat_settings();
    $wp_scripts->do_concat = $concatenate_scripts;
    $wp_scripts->do_head_items();
    if (apply_filters('print_head_scripts', true)) {
        _print_scripts();
    }
    $wp_scripts->reset();
    return $wp_scripts->done;
}
Exemple #2
0
/**
 * Prints the script queue in the HTML head on admin pages.
 *
 * Postpones the scripts that were queued for the footer.
 * print_footer_scripts() is called in the footer to print these scripts.
 *
 * @since 2.8
 *
 * @see wp_print_scripts()
 */
function print_head_scripts()
{
    global $wp_scripts, $concatenate_scripts;
    if (!did_action('wp_print_scripts')) {
        /** This action is documented in wp-includes/functions.wp-scripts.php */
        do_action('wp_print_scripts');
    }
    if (!is_a($wp_scripts, 'WP_Scripts')) {
        $wp_scripts = new WP_Scripts();
    }
    script_concat_settings();
    $wp_scripts->do_concat = $concatenate_scripts;
    $wp_scripts->do_head_items();
    if (apply_filters('print_head_scripts', true)) {
        _print_scripts();
    }
    $wp_scripts->reset();
    return $wp_scripts->done;
}
Exemple #3
0
/**
 * Prints the script queue in the HTML head on admin pages.
 *
 * Postpones the scripts that were queued for the footer.
 * print_footer_scripts() is called in the footer to print these scripts.
 *
 * @since 2.8.0
 *
 * @see wp_print_scripts()
 */
function print_head_scripts()
{
    global $wp_scripts, $concatenate_scripts;
    if (!did_action('wp_print_scripts')) {
        /** This action is documented in wp-includes/functions.wp-scripts.php */
        do_action('wp_print_scripts');
    }
    if (!is_a($wp_scripts, 'WP_Scripts')) {
        $wp_scripts = new WP_Scripts();
    }
    script_concat_settings();
    $wp_scripts->do_concat = $concatenate_scripts;
    $wp_scripts->do_head_items();
    /**
     * Filter whether to print the head scripts.
     *
     * @since 2.8.0
     *
     * @param bool $print Whether to print the head scripts. Default true.
     */
    if (apply_filters('print_head_scripts', true)) {
        _print_scripts();
    }
    $wp_scripts->reset();
    return $wp_scripts->done;
}
Exemple #4
0
 /**
  * process_scripts()
  *
  * @param bool $header_scripts
  * @return void
  **/
 static function process_scripts($header_scripts = true)
 {
     global $wp_scripts;
     if (!$wp_scripts instanceof WP_Scripts) {
         $wp_scripts = new WP_Scripts();
     }
     $queue = $wp_scripts->queue;
     $wp_scripts->all_deps($queue);
     if (!$wp_scripts->to_do) {
         return;
     }
     $todo = array();
     $js = array();
     $dirs = array(content_url(), plugins_url());
     foreach ($wp_scripts->to_do as $key => $handle) {
         if (!empty($wp_scripts->registered[$handle]->args)) {
             continue;
         }
         // bail if is a footer script and we're doing headers
         if ($header_scripts && $wp_scripts->groups[$handle] > 0) {
             continue;
         }
         $jsPath = $wp_scripts->registered[$handle]->src;
         // bail if alias
         if (!$jsPath) {
             continue;
         }
         if (!asset_cache::startsWith($jsPath, site_url())) {
             $jsPath = site_url() . $jsPath;
         }
         $inDir = false;
         foreach ($dirs as $dir) {
             if (asset_cache::startsWith($jsPath, $dir)) {
                 $inDir = true;
                 break;
             }
         }
         $suffixMatch = asset_cache::endsWith($jsPath, ".js");
         if ($inDir && $suffixMatch) {
             $js[$handle] = $wp_scripts->registered[$handle]->ver;
             $todo[] = $handle;
             unset($wp_scripts->to_do[$key]);
             $wp_scripts->done[] = $handle;
         }
     }
     if ($todo) {
         $file = '/assets/' . md5(serialize($js)) . '.js';
         if (!cache_fs::exists($file)) {
             asset_cache::concat_scripts($file, $todo);
         }
         $wp_scripts->default_version = null;
         if ($header_scripts) {
             wp_enqueue_script('scripts_concat', content_url() . '/cache' . $file);
         } else {
             wp_enqueue_script('footer_scripts_concat', content_url() . '/cache' . $file, array(), false, true);
             $wp_scripts->groups['footer_scripts_concat'] = 1;
             $wp_scripts->in_footer[] = 'footer_scripts_concat';
         }
     }
     $wp_scripts->do_concat = true;
     $header_scripts ? $wp_scripts->do_head_items() : $wp_scripts->do_footer_items();
     if ($wp_scripts->print_code) {
         echo "<script type='text/javascript'>\n";
         echo "/* <![CDATA[ */\n";
         echo $wp_scripts->print_code;
         echo "/* ]]> */\n";
         echo "</script>\n";
     }
     //		$wp_scripts->reset();
 }