/** * Minifies collected scripts */ private function flush_collected($last_script_tag) { if (count($this->files_to_minify) <= 0) { return; } $do_flush_collected = apply_filters('w3tc_minify_js_do_flush_collected', true, $last_script_tag, $this); if (!$do_flush_collected) { return; } // find embed position $embed_pos = $this->embed_pos; if ($this->minify_group_number <= 0) { // try forced embed position $forced_embed_pos = strpos($this->buffer, '<!-- W3TC-include-js-head -->'); if ($forced_embed_pos !== false) { $this->buffer = str_replace('<!-- W3TC-include-js-head -->', '', $this->buffer); $embed_pos = $forced_embed_pos; } } // build minified script tag $data = array('files_to_minify' => $this->files_to_minify, 'embed_pos' => $embed_pos, 'embed_type' => $this->embed_type[$this->group_type], 'buffer' => $this->buffer); $data = apply_filters('w3tc_minify_js_step', $data); $this->buffer = $data['buffer']; if (!empty($data['files_to_minify'])) { $url = $this->minify_helpers->get_minify_url_for_files($data['files_to_minify'], 'js'); $script = ''; if (!is_null($url)) { $script .= $this->minify_helpers->generate_script_tag($url, $data['embed_type']); } $data['script_to_embed_url'] = $url; $data['script_to_embed_body'] = $script; $data = apply_filters('w3tc_minify_js_step_script_to_embed', $data); $this->buffer = $data['buffer']; // replace $this->buffer = substr_replace($this->buffer, $data['script_to_embed_body'], $data['embed_pos'], 0); } $this->files_to_minify = array(); $this->minify_group_number++; }
/** * Minifies collected scripts */ private function flush_collected() { if (count($this->files_to_minify) <= 0) { return; } // find embed position $embed_pos = $this->embed_pos; if ($this->minify_group_number <= 0 && $this->group_type == 'head') { // try forced embed position $forced_embed_pos = strpos($this->buffer, '<!-- W3TC-include-js-head -->'); if ($forced_embed_pos !== false) { $this->buffer = str_replace('<!-- W3TC-include-js-head -->', '', $this->buffer); $embed_pos = $forced_embed_pos; } } // build minified script tag $urls = $this->minify_helpers->get_minify_urls_for_files($this->files_to_minify, 'js'); $script = ''; if (is_array($urls)) { foreach ($urls as $url) { $script .= $this->minify_helpers->generate_script_tag($url, $this->embed_type); } } // replace $this->buffer = substr_replace($this->buffer, $script, $embed_pos, 0); $this->files_to_minify = array(); $this->minify_group_number++; }