/** * Remove a registered CSS file. * * @since r79 * @see WP_Styles::remove() For additional information. * @global object $wp_styles The WP_Styles object for printing styles. * * @param string $handle Name of the stylesheet. */ function wp_deregister_style($handle) { global $wp_styles; if (!is_a($wp_styles, 'WP_Styles')) { $wp_styles = new WP_Styles(); } $wp_styles->remove($handle); }
function sp_combine_plugin_css_files() { global $sp_plugin_styles, $spDevice; if (!is_a($sp_plugin_styles, 'WP_Styles')) { $sp_plugin_styles = new WP_Styles(); } # save copy of styles in case of failure writing $saved_styles = clone $sp_plugin_styles; # check for standard theme or mobile if ($spDevice == 'mobile') { $option = 'sp_css_concat_mobile'; } else { if ($spDevice == 'tablet') { $option = 'sp_css_concat_tablet'; } else { $option = 'sp_css_concat'; } } $css_concat = sp_get_option($option); if (!is_array($css_concat)) { $css_concat = array(); } $css_files_modify = array(); $css_files = array(); if (is_array($sp_plugin_styles->queue)) { # is there anything in the queue? $sp_plugin_styles->all_deps($sp_plugin_styles->queue); # preparing the queue taking dependencies into account foreach ($css_concat as $css => $value) { # going through all the already found css files, checking that they are still required if (!in_array(substr($css, 4), $sp_plugin_styles->to_do) && substr($css, 0, 4) == 'css-') { # if the css is not queued, rewrite the file $css_media = $value['type']; $css_files_modify[$css_media] = true; unset($css_concat[$css]); } } foreach ($sp_plugin_styles->to_do as $css) { $css_src = $sp_plugin_styles->registered[$css]->src; $css_media = $sp_plugin_styles->registered[$css]->args; # is the css is hosted localy AND is a css file? if ((!(strpos($css_src, get_bloginfo('url')) === false) || substr($css_src, 0, 1) === '/' || substr($css_src, 0, 1) === '.') && (substr($css_src, strrpos($css_src, '.'), 4) == '.css' || substr($css_src, strrpos($css_src, '.'), 4) == '.php')) { if (!is_array($css_files) || !array_key_exists($css_media, $css_files)) { $css_files[$css_media] = array(); } if (strpos($css_src, get_bloginfo('url')) === false) { $css_relative_url = substr($css_src, 1); } else { $css_relative_url = substr($css_src, strlen(get_bloginfo('url')) + 1); } if (strpos($css_relative_url, '?')) { $css_relative_url = substr($css_relative_url, 0, strpos($css_relative_url, '?')); } # removing parameters $css_m_time = null; @($css_m_time = filemtime($css_relative_url)); # getting the mofified time of the css file. extracting the file's dir if ($css_m_time) { # only add the file if it's accessible # check for php theme file indicating main theme file and save whole url vs just relative if (substr($css_src, strrpos($css_src, '.'), 4) == '.php') { array_push($css_files[$css_media], $css_src); } else { array_push($css_files[$css_media], $css_relative_url); } if (!file_exists(SP_COMBINED_CACHE_DIR . SP_COMBINED_CSS_BASE_NAME . $css_media . '.css') || isset($css_concat['css-' . $css]) && ($css_m_time != $css_concat['css-' . $css]['modified'] || $css_concat['css-' . $css]['type'] != $css_media) || !isset($css_concat['css-' . $css])) { # css file is first identified $css_files_modify[$css_media] = true; # the combined file containing this media type css should be changed if (isset($css_concat['css-' . $css]) && $css_concat['css-' . $css]['type'] != $css_media) { # if the media type changed - rewrite both css files $tmp = $css_concat['css-' . $css]['type']; $css_files_modify[$tmp] = true; } if (!is_array($css_concat['css-' . $css])) { $css_concat['css-' . $css] = array(); } $css_concat['css-' . $css]['modified'] = $css_m_time; # write the new modified date $css_concat['css-' . $css]['type'] = $css_media; } $sp_plugin_styles->remove($css); # removes the css file from the queue } } } } foreach ($css_files_modify as $key => $value) { $combined_file = fopen(SP_COMBINED_CACHE_DIR . SP_COMBINED_CSS_BASE_NAME . $key . '.css', 'w'); if ($combined_file) { $css_content = ''; if (is_array($css_files[$key])) { foreach ($css_files[$key] as $css_src) { $css_content .= "\n" . sp_get_css_content($css_src) . "\n"; } } if (!isset($css_concat['ver'][$key])) { $css_concat['ver'][$key] = 0; } $css_concat['ver'][$key]++; # compress the css before writing it out require 'sp-api-class-css-compressor.php'; $css_content = Minify_CSS_Compressor::process($css_content); fwrite($combined_file, $css_content); fclose($combined_file); } else { # couldnt open file for writing so revert back to enqueueing all the styles if (!empty($saved_styles)) { foreach ($saved_styles->queue as $handle) { wp_enqueue_style($handle, $saved_styles->registered[$handle]->src); } } return; # enqueued through wp now so bail } } foreach ($css_files as $key => $value) { # enqueue the combined css files wp_enqueue_style(SP_COMBINED_CSS_BASE_NAME . $key, SP_COMBINED_CACHE_URL . SP_COMBINED_CSS_BASE_NAME . $key . '.css', array(), $css_concat['ver'][$key]); } sp_update_option($option, $css_concat); }
/** * Remove a registered stylesheet. * * @see WP_Dependencies::remove() * @global WP_Styles $wp_styles The WP_Styles object for printing styles. * * @since 2.1.0 * * @param string $handle Name of the stylesheet to be removed. */ function wp_deregister_style($handle) { global $wp_styles; if (!is_a($wp_styles, 'WP_Styles')) { if (!did_action('init')) { _doing_it_wrong(__FUNCTION__, sprintf(__('Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.'), '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>'), '3.3'); } $wp_styles = new WP_Styles(); } $wp_styles->remove($handle); }