Making WordPress.org


Ignore:
Timestamp:
11/22/2016 12:12:31 AM (8 years ago)
Author:
coreymckrill
Message:

Site Cloner: prepend Remote CSS rules to Custom CSS stylesheet

Check the source site for a cached version of a Remote CSS stylesheet
and combine it with any Jetpack Custom CSS before applying to the
recipient site.

Fixes #1113

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-site-cloner/includes/source-site-id-setting.php

    r4280 r4398  
    33namespace WordCamp\Site_Cloner;
    44defined( 'WPINC' ) or die();
     5
     6use \WordCamp\RemoteCSS;
    57
    68/**
     
    4850
    4951        switch_to_blog( $this->preview_source_site_id );
    50         printf( '<style id="wcsc-source-site-custom-css">%s</style>', \Jetpack_Custom_CSS::get_css( true ) );
     52
     53        printf(
     54            '<style id="wcsc-source-site-custom-css">%s %s</style>',
     55            $this->get_cached_remote_css(),
     56            \Jetpack_Custom_CSS::get_css( true )
     57        );
     58
    5159        restore_current_blog();
    5260    }
     
    107115
    108116    /**
     117     * Get the cached remote CSS for the current blog.
     118     *
     119     * @return string
     120     */
     121    public function get_cached_remote_css() {
     122        $remote_css = '';
     123
     124        if ( ! function_exists( '\WordCamp\RemoteCSS\get_safe_css_post' ) ) {
     125            return $remote_css;
     126        }
     127
     128        $post = RemoteCSS\get_safe_css_post();
     129
     130        if ( $post instanceof \WP_Post ) {
     131            // Sanitization copied from \Jetpack_Custom_CSS::get_css()
     132            // so that there is parity with how Jetpack outputs the CSS
     133            $remote_css = str_replace(
     134                array( '\\\00BB \\\0020', '\0BB \020', '0BB 020' ),
     135                '\00BB \0020',
     136                $post->post_content_filtered
     137            );
     138        }
     139
     140        return $remote_css;
     141    }
     142
     143    /**
    109144     * Clone the source site into the current site
    110145     *
     
    124159        }
    125160
    126         $source_site_css           = \Jetpack_Custom_CSS::get_css( false );
     161        $source_site_css = '';
     162
     163        // Add Remote CSS first
     164        // This maintains the correct cascading order of stylesheet rules
     165        if ( $remote_css = $this->get_cached_remote_css() ) {
     166            $source_site_css .= sprintf(
     167                "/* %s */\n%s\n\n",
     168                sprintf(
     169                    esc_html__( 'Remote CSS from %s', 'wordcamporg' ),
     170                    esc_url( get_option( 'wcrcss_remote_css_url' ) )
     171                ),
     172                $remote_css
     173            );
     174        }
     175
     176        // Add Jetpack Custom CSS second
     177        if ( $custom_css = \Jetpack_Custom_CSS::get_css( false ) ) {
     178            $source_site_css .= sprintf(
     179                "/* %s */\n%s\n\n",
     180                sprintf(
     181                    esc_html__( 'Custom CSS from %s', 'wordcamporg' ),
     182                    get_bloginfo( 'name' )
     183                ),
     184                $custom_css
     185            );
     186        }
     187
    127188        $source_site_preprocessor  = get_post_meta( $source_cite_css_post['ID'], 'custom_css_preprocessor', true );
    128189        $source_site_mode          = get_post_meta( $source_cite_css_post['ID'], 'custom_css_add', true );
Note: See TracChangeset for help on using the changeset viewer.