function enqueue_styles()
 {
     if (is_admin()) {
         return;
     }
     // The user chooses a grid.
     $versions = array('grid960' => '20110221', 'grid720' => '20110221');
     $grid = wcb_get_option('grid');
     // Check whethec Custom CSS mode is set to Add or Replace.
     if (class_exists('Jetpack_Custom_CSS') && method_exists('Jetpack_Custom_CSS', 'get_current_revision')) {
         $safecss_post = Jetpack_Custom_CSS::get_current_revision();
         if (get_post_meta($safecss_post['ID'], 'custom_css_add', true) == 'no') {
             return;
         }
     }
     $start_fresh = apply_filters('wcb_start_fresh', false);
     $child_recs = array();
     if (!$start_fresh) {
         wp_enqueue_style('wcb-foundation', WCB_URL . '/style.css', array(), '20110212');
         $version = isset($versions[$grid]) ? $versions[$grid] : false;
         wp_enqueue_style("wcb-{$grid}", wcb_dev_url(WCB_URL . "/css/{$grid}.css"), array('wcb-foundation'), $version);
         wp_enqueue_style("wcb-style", wcb_dev_url(WCB_URL . '/css/default.css'), array('wcb-foundation', "wcb-{$grid}"), '20110421');
         $child_recs = array('wcb-foundation', "wcb-{$grid}", 'wcb-style');
     }
     if (is_child_theme()) {
         $child_version = apply_filters('wcb_child_css_version', false);
         wp_enqueue_style("wcb-child", get_stylesheet_uri(), $child_recs, $child_version);
     }
 }
 /**
  * API callback.
  */
 function callback($path = '', $blog_id = 0)
 {
     // Switch to the given blog.
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     $args = array('css' => Jetpack_Custom_CSS::get_css(), 'preprocessor' => Jetpack_Custom_CSS::get_preprocessor_key(), 'add_to_existing' => !Jetpack_Custom_CSS::skip_stylesheet());
     $defaults = array('css' => '', 'preprocessor' => '', 'add_to_existing' => true);
     return wp_parse_args($args, $defaults);
 }
 /**
  * API callback.
  */
 function callback($path = '', $blog_id = 0)
 {
     // Switch to the given blog.
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     if (!current_user_can('edit_theme_options')) {
         return new WP_Error('unauthorized', 'User is not authorized to access custom css', 403);
     }
     $args = $this->input();
     if (empty($args) || !is_array($args)) {
         return new WP_Error('no_data', 'No data was provided.', 400);
     }
     $save_args = array('css' => $args['css'], 'preprocessor' => $args['preprocessor'], 'add_to_existing' => $args['add_to_existing']);
     Jetpack_Custom_CSS::save($save_args);
     $current = array('css' => Jetpack_Custom_CSS::get_css(), 'preprocessor' => Jetpack_Custom_CSS::get_preprocessor_key(), 'add_to_existing' => !Jetpack_Custom_CSS::skip_stylesheet());
     $defaults = array('css' => '', 'preprocessor' => '', 'add_to_existing' => true);
     return wp_parse_args($current, $defaults);
 }
Example #4
0
 /**
  * Custom Colors
  *
  * This feature is experimental. It relies on Jetpack's Custom CSS module
  * and the availability of a SASS preprocessor function.
  */
 public static function custom_colors()
 {
     $colors = get_theme_mod('semicolon-colors', self::$defaults['colors']);
     $colors = wp_parse_args($colors, self::$defaults['colors']);
     $custom = false;
     foreach (self::$defaults['colors'] as $key => $default) {
         if (strtolower($colors[$key]) != $default) {
             $custom = true;
             break;
         }
     }
     if (get_theme_mod('semicolon-colors-auto-contrast', true) && get_background_color() != get_theme_support('custom-background', 'default-color')) {
         $custom = true;
     }
     // At least one custom color should be set for an override.
     if (!$custom) {
         return;
     }
     $css = get_theme_mod('semicolon-colors-css', false);
     $hash = get_theme_mod('semicolon-colors-hash', false);
     $new_hash = md5(serialize(array_merge($colors, array('version' => self::$colors_css_version, 'background-color' => get_background_color(), 'auto-contrast' => get_theme_mod('semicolon-colors-auto-contrast', true)))));
     // Cache with a hash and then smash.
     if ($hash !== $new_hash) {
         // Somebody can preview Semicolon without activating it, let's not
         // pollute the database with our theme mods.
         if (!self::is_customize_preview()) {
             // Set these early, just in case everything else fails or fatals.
             set_theme_mod('semicolon-colors-hash', $new_hash);
             set_theme_mod('semicolon-colors-css', '');
         }
         // There's a special semicolon-override marker in the .sass file.
         $override = sprintf('$color-background: #%s;' . PHP_EOL, get_background_color());
         foreach ($colors as $key => $value) {
             $override .= sprintf('$color-%s: %s;' . PHP_EOL, $key, $value);
         }
         if (get_theme_mod('semicolon-colors-auto-contrast', true)) {
             $override .= '$auto-contrast: true;' . PHP_EOL;
         }
         // Retrieve the Sass file and then run some replacements.
         $sass = self::custom_colors_get_sass();
         if (empty($sass)) {
             return;
         }
         $sass = preg_replace('/^.*?semicolon-override.*$/im', $override, $sass);
         $css = jetpack_sass_css_preprocess($sass);
         // Something went wrong, so don't display raw sass.
         if (empty($css) || strpos($css, 'this string should never appear in the compiled stylesheet') !== false) {
             return;
         }
         // Minify the CSS if possible.
         if (method_exists('Jetpack_Custom_CSS', 'minify')) {
             $css = Jetpack_Custom_CSS::minify($css);
         }
         // Don't write to the db in preview mode.
         if (!self::is_customize_preview()) {
             set_theme_mod('semicolon-colors-css', $css);
         }
     }
     // Dequeue the default colors css.
     wp_dequeue_style('semicolon-colors');
     return $css;
 }
Example #5
0
 /**
  * Override the content_width with a custom value if one is set.
  */
 static function jetpack_content_width($content_width)
 {
     $custom_content_width = 0;
     if (Jetpack_Custom_CSS::is_preview()) {
         $safecss_post = Jetpack_Custom_CSS::get_current_revision();
         $custom_content_width = intval(get_post_meta($safecss_post['ID'], 'content_width', true));
     } else {
         if (!Jetpack_Custom_CSS::is_freetrial()) {
             $custom_css_post_id = Jetpack_Custom_CSS::post_id();
             if ($custom_css_post_id) {
                 $custom_content_width = intval(get_post_meta($custom_css_post_id, 'content_width', true));
             }
         }
     }
     if ($custom_content_width > 0) {
         $content_width = $custom_content_width;
     }
     return $content_width;
 }
Example #6
0
 /**
  * Migration routine for moving safecss from wp_options to wp_posts to support revisions
  *
  * @return void
  */
 static function upgrade()
 {
     $css = get_option('safecss');
     // Check if CSS is stored in wp_options
     if ($css) {
         // Remove the async actions from publish_post
         remove_action('publish_post', 'queue_publish_post');
         $post = array();
         $post['post_content'] = $css;
         $post['post_title'] = 'safecss';
         $post['post_status'] = 'publish';
         $post['post_type'] = 'safecss';
         // Insert the CSS into wp_posts
         $post_id = wp_insert_post($post);
         // Check for errors
         if (!$post_id or is_wp_error($post_id)) {
             die($post_id->get_error_message());
         }
         // Delete safecss option
         delete_option('safecss');
     }
     unset($css);
     // Check if we have already done this
     if (!get_option('safecss_revision_migrated')) {
         define('DOING_MIGRATE', true);
         // Get hashes of safecss post and current revision
         $safecss_post = Jetpack_Custom_CSS::get_post();
         if (empty($safecss_post)) {
             return;
         }
         $safecss_post_hash = md5($safecss_post['post_content']);
         $current_revision = Jetpack_Custom_CSS::get_current_revision();
         if (null == $current_revision) {
             return;
         }
         $current_revision_hash = md5($current_revision['post_content']);
         // If hashes are not equal, set safecss post with content from current revision
         if ($safecss_post_hash !== $current_revision_hash) {
             Jetpack_Custom_CSS::save_revision($current_revision['post_content']);
             // Reset post_content to display the migrated revsion
             $safecss_post['post_content'] = $current_revision['post_content'];
         }
         // Set option so that we dont keep doing this
         update_option('safecss_revision_migrated', time());
     }
     $newest_safecss_post = Jetpack_Custom_CSS::get_current_revision();
     if ($newest_safecss_post) {
         if (get_option('safecss_content_width')) {
             // Add the meta to the post and the latest revision.
             update_post_meta($newest_safecss_post['ID'], 'content_width', get_option('safecss_content_width'));
             update_metadata('post', $newest_safecss_post['ID'], 'content_width', get_option('safecss_content_width'));
             delete_option('safecss_content_width');
         }
         if (get_option('safecss_add')) {
             update_post_meta($newest_safecss_post['ID'], 'custom_css_add', get_option('safecss_add'));
             update_metadata('post', $newest_safecss_post['ID'], 'custom_css_add', get_option('safecss_add'));
             delete_option('safecss_add');
         }
     }
 }
 /**
  * Copy the custom CSS from Jetpack to theme_mod
  */
 function custom_css_jetpack_to_theme_mod()
 {
     $css = Jetpack_Custom_CSS::get_css();
     if ($css != get_theme_mod('css', '')) {
         set_theme_mod('css', $css);
     }
 }
 public function embed_css()
 {
     printf('<style type="text/css" id="jetpack-custom-css">%s</style>', Jetpack_Custom_CSS::get_css(true));
 }
 /**
  * Parse some CSS and make sure it's valid before outputting it in the page
  */
 function parse_css($css = null)
 {
     if (empty($css)) {
         return null;
     }
     if (!defined('JETPACK__VERSION')) {
         return $this->inst_css_parser($css);
     } else {
         if (!class_exists('Jetpack_Custom_CSS', false)) {
             if (function_exists('jetpack_load_custom_css')) {
                 jetpack_load_custom_css();
             }
             // Still here? Load module manually.
             if (!class_exists('Jetpack_Custom_CSS', false)) {
                 require JETPACK__PLUGIN_DIR . 'modules/custom-css/custom-css.php';
             }
         }
         $css = @Jetpack_Custom_CSS::minify($css, 'sass');
         if (empty($css)) {
             return null;
         }
         return $css;
     }
 }