Changeset 4577 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-site-cloner/includes/source-site-id-setting.php
- Timestamp:
- 12/23/2016 05:27:38 PM (8 years ago)
- 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
r4398 r4577 2 2 3 3 namespace WordCamp\Site_Cloner; 4 use \WordCamp\RemoteCSS; 5 use Jetpack_Custom_CSS_Enhancements; 6 4 7 defined( 'WPINC' ) or die(); 5 6 use \WordCamp\RemoteCSS;7 8 8 9 /** … … 12 13 * the site that that will be cloned. There are actually many data points that we'll import, but they don't fit 13 14 * into the default model that the Customizer expects. 15 * 16 * @todo - We may no longer need a setting; see https://make.wordpress.org/core/2016/03/10/customizer-improvements-in-4-5/ 14 17 */ 15 18 class Source_Site_ID_Setting extends \WP_Customize_Setting { … … 29 32 30 33 add_action( 'wp_head', array( $this, 'preview_source_site_css' ), 99 ); // wp_print_styles is too early; the theme's stylesheet would get enqueued later and take precedence 31 add_filter( 'get_post_metadata', array( $this, 'preview_jetpack_postmeta' ), 10, 4 ); 32 add_filter( 'safecss_skip_stylesheet', array( $this, 'preview_skip_stylesheet' ) ); 34 add_filter( 'safecss_skip_stylesheet', array( $this, 'preview_skip_stylesheet' ), 15 ); // After Jetpack_Custom_CSS_Enhancements::preview_skip_stylesheet() 33 35 34 36 // Disable the current site's Custom CSS from being output 35 remove_action( 'wp_head', array( 'Jetpack_Custom_CSS', 'link_tag' ), 101 ); 37 remove_action( 'wp_head', 'wp_custom_css_cb', 11 ); // todo compat with WP 4.7. this line can be removed when r39616 is merged to the 4.7 branch 38 remove_action( 'wp_head', 'wp_custom_css_cb', 101 ); 36 39 } 37 40 38 41 /** 39 42 * Print the source site's custom CSS in an inline style block 40 *41 * It can't be easily enqueued as an external stylesheet because Jetpack_Custom_CSS::link_tag() returns early42 * in the Customizer if the theme being previewed is different from the live theme.43 43 */ 44 44 public function preview_source_site_css() { 45 if ( method_exists( '\Jetpack', 'get_module_path' ) ) {46 require_once( \Jetpack::get_module_path( 'custom-css' ) );47 } else {48 return;49 }50 51 45 switch_to_blog( $this->preview_source_site_id ); 52 46 … … 54 48 '<style id="wcsc-source-site-custom-css">%s %s</style>', 55 49 $this->get_cached_remote_css(), 56 \Jetpack_Custom_CSS::get_css( true)50 wp_get_custom_css() 57 51 ); 58 52 … … 61 55 62 56 /** 63 * Overwrite the previewing site's Custom CSS settings with values from the source site64 *65 * @param mixed $pre_filter_value66 * @param int $post_id67 * @param string $meta_key68 * @param bool $return_single_value69 *70 * @return mixed71 */72 public function preview_jetpack_postmeta( $pre_filter_value, $post_id, $meta_key, $return_single_value ) {73 if ( ! in_array( $meta_key, array( 'content_width' ) ) ) {74 return $pre_filter_value;75 }76 77 remove_filter( 'get_post_metadata', array( $this, 'preview_jetpack_postmeta' ), 10, 4 ); // avoid infinite recursion78 switch_to_blog( $this->preview_source_site_id );79 80 if ( $source_cite_css_post = \Jetpack_Custom_CSS::get_current_revision() ) {81 $pre_filter_value = get_post_meta( $source_cite_css_post['ID'], $meta_key, $return_single_value );82 }83 84 restore_current_blog();85 add_filter( 'get_post_metadata', array( $this, 'preview_jetpack_postmeta' ), 10, 4 );86 87 return $pre_filter_value;88 }89 90 /**91 57 * Determine whether or not to skip the primary stylesheet 92 58 * 93 * When the Custom CSS value for `Mode` is `Replacement`, Jetpack will prevent the primary stylesheet from59 * When the `Start Fresh` theme mod is set, Jetpack will prevent the primary stylesheet from 94 60 * being enqueued. We need to trigger that behavior based on the value on the source site, rather than the 95 61 * current site. 96 *97 * This could be actually handled along with other Jetpack options in preview_jetpack_postmeta(), if it98 * weren't for the fact that Jetpack_Custom_CSS::skip_stylesheet always returns false in the Previewer.99 62 * 100 63 * @param bool $skip … … 103 66 */ 104 67 public function preview_skip_stylesheet( $skip ) { 68 remove_filter( 'safecss_skip_stylesheet', array( $this, 'preview_skip_stylesheet' ), 15 ); // Avoid infinite recursion. Also, use same priority as originally set in preview() 105 69 switch_to_blog( $this->preview_source_site_id ); 106 70 107 if ( $source_cite_css_post = \Jetpack_Custom_CSS::get_current_revision() ) { 108 $skip = 'no' === get_post_meta( $source_cite_css_post['ID'], 'custom_css_add', true ); 109 } 71 $skip = Jetpack_Custom_CSS_Enhancements::skip_stylesheet(); 110 72 111 73 restore_current_blog(); 74 add_filter( 'safecss_skip_stylesheet', array( $this, 'preview_skip_stylesheet' ), 15 ); 112 75 113 76 return $skip; … … 134 97 array( '\\\00BB \\\0020', '\0BB \020', '0BB 020' ), 135 98 '\00BB \0020', 136 $post->post_content _filtered99 $post->post_content 137 100 ); 138 101 } … … 154 117 switch_to_blog( $source_site_id ); 155 118 156 if ( ! $source_cite_css_post = \Jetpack_Custom_CSS::get_current_revision() ) { 157 restore_current_blog(); 158 return; 159 } 160 119 $source_site_theme_mods = get_theme_mod( 'jetpack_custom_css' ); 161 120 $source_site_css = ''; 162 121 … … 174 133 } 175 134 176 // Add Jetpack Custom CSS second 177 if ( $custom_css = \Jetpack_Custom_CSS::get_css( false ) ) { 135 /* 136 * Add Core Custom CSS second to maintain correct cascading order. 137 * 138 * Processed CSS and vanilla CSS are stored in `post_content`, but pre-processed CSS is stored in 139 * `post_content_filtered`. 140 */ 141 if ( $custom_css_post = wp_get_custom_css_post() ) { 142 if ( empty( $source_site_theme_mods['preprocessor'] ) ) { 143 $custom_css = $custom_css_post->post_content; 144 } else { 145 $custom_css = $custom_css_post->post_content_filtered; 146 } 147 178 148 $source_site_css .= sprintf( 179 149 "/* %s */\n%s\n\n", 180 150 sprintf( 181 151 esc_html__( 'Custom CSS from %s', 'wordcamporg' ), 182 get_bloginfo( 'name')152 parse_url( home_url(), PHP_URL_HOST ) 183 153 ), 184 154 $custom_css … … 186 156 } 187 157 188 $source_site_preprocessor = get_post_meta( $source_cite_css_post['ID'], 'custom_css_preprocessor', true );189 $source_site_mode = get_post_meta( $source_cite_css_post['ID'], 'custom_css_add', true );190 $source_site_content_width = get_post_meta( $source_cite_css_post['ID'], 'content_width', true );191 192 158 restore_current_blog(); 193 159 194 \Jetpack_Custom_CSS::save( array( 195 'css' => $source_site_css, 196 'is_preview' => false, 197 'preprocessor' => $source_site_preprocessor, 198 'add_to_existing' => 'yes' === $source_site_mode ? true : false, 199 'content_width' => $source_site_content_width, 200 ) ); 160 wp_update_custom_css_post( $source_site_css ); 161 set_theme_mod( 'jetpack_custom_css', $source_site_theme_mods ); 201 162 } 202 163 }
Note: See TracChangeset
for help on using the changeset viewer.