public static function do_migration() { Jetpack_Options::update_option('custom_css_4.7_migration', true); Jetpack::log('custom_css_4.7_migration', 'start'); if (!post_type_exists('safecss')) { self::register_legacy_post_type(); } /** This filter is documented in modules/custom-css/custom-css.php */ $preprocessors = apply_filters('jetpack_custom_css_preprocessors', array()); $core_css_post = wp_get_custom_css_post(); $jetpack_css_post = self::get_post(); $revisions = self::get_all_revisions(); // Migrate the settings from revision meta to theme mod. $options = self::get_options($jetpack_css_post->ID); set_theme_mod('jetpack_custom_css', $options); if (empty($revisions) || !is_array($revisions)) { if ($jetpack_css_post instanceof WP_Post) { // Feed in the raw, if the current setting is Sass/LESS, it'll filter it inside. wp_update_custom_css_post($jetpack_css_post->post_content); return 1; } return null; } $revisions = array_reverse($revisions); $themes = Jetpack_Custom_CSS_Enhancements::get_themes(); $migrated = array(); foreach ($revisions as $post_id => $post) { // Jetpack had stored the theme Name, not the stylesheet directory, for ... reasons. // Get the stylesheet. If null, the theme is no longer available. Skip. $stylesheet = isset($themes[$post->post_excerpt]) ? $themes[$post->post_excerpt] : null; if (empty($stylesheet)) { continue; } $migrated[] = $post->ID; $preprocessor = get_post_meta($post->ID, 'custom_css_preprocessor', true); $css = $post->post_content; $pre = ''; // Do a revision by revision parsing. if ($preprocessor && isset($preprocessors[$preprocessor])) { $pre = $css; $css = call_user_func($preprocessors[$preprocessor]['callback'], $pre); } // Do we need to remove any filters here for users without `unfiltered_html` ? wp_update_custom_css_post($css, array('stylesheet' => $stylesheet, 'preprocessed' => $pre)); } // If we've migrated some CSS for the current theme and there was already something there in the Core dataset ... if ($core_css_post && $jetpack_css_post) { $preprocessor = $options['preprocessor']; $css = $core_css_post->post_content; $pre = $core_css_post->post_content_filtered; if ($preprocessor) { if ($pre) { $pre .= "\r\n\r\n/*\r\n\t" . esc_js(__('CSS Migrated from Jetpack:', 'jetpack')) . "\r\n*/\r\n\r\n"; } $pre .= $jetpack_css_post->post_content; $css .= "\r\n\r\n/*\r\n\t" . esc_js(__('CSS Migrated from Jetpack:', 'jetpack')) . "\r\n*/\r\n\r\n"; $css .= call_user_func($preprocessors[$preprocessor]['callback'], $jetpack_css_post->post_content); } else { $css .= "\r\n\r\n/*\r\n\t" . esc_js(__('CSS Migrated from Jetpack:', 'jetpack')) . "\r\n*/\r\n\r\n"; $css .= $jetpack_css_post->post_content; } wp_update_custom_css_post($css, array('preprocessed' => $pre)); } Jetpack::log('custom_css_4.7_migration', sizeof($migrated) . 'revisions migrated'); return sizeof($migrated); }
printf(esc_html__('(modified %s ago)', 'jetpack'), human_time_diff(strtotime($data['post']->post_modified_gmt))); ?> </option> <?php } ?> </select> <button class="button" id="other_theme_custom_css_switcher"><?php esc_html_e('Switch', 'jetpack'); ?> </button> </div> <?php } } Jetpack_Custom_CSS_Enhancements::add_hooks(); if (!function_exists('safecss_class')) { /** * Load in the class only when needed. Makes lighter load by having one less class in memory. */ function safecss_class() { // Wrapped so we don't need the parent class just to load the plugin. if (class_exists('safecss')) { return; } require_once dirname(__FILE__) . '/csstidy/class.csstidy.php'; /** * Class safecss */ class safecss extends csstidy_optimise