Jetpack_Custom_CSS_Enhancements::get_themes PHP Method

get_themes() public static method

Get a map of all theme names and theme stylesheets for mapping stuff.
public static get_themes ( ) : array
return array
    public static function get_themes()
    {
        $themes = wp_get_themes(array('errors' => null));
        $all = array();
        foreach ($themes as $theme) {
            $all[$theme->name] = $theme->stylesheet;
        }
        return $all;
    }

Usage Example

 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);
 }