/modules/custom-css/custom-css.php

  1. <?php 
  2.  
  3. class Jetpack_Custom_CSS { 
  4. static function init() { 
  5. add_action( 'switch_theme', array( __CLASS__, 'reset' ) ); 
  6. add_action( 'wp_restore_post_revision', array( __CLASS__, 'restore_revision' ), 10, 2 ); 
  7.  
  8. // Save revisions for posts of type safecss. 
  9. add_filter( 'revision_redirect', array( __CLASS__, 'revision_redirect' ) ); 
  10.  
  11. // Override the edit link, the default link causes a redirect loop 
  12. add_filter( 'get_edit_post_link', array( __CLASS__, 'revision_post_link' ), 10, 3 ); 
  13.  
  14. // Overwrite the content width global variable if one is set in the custom css 
  15. add_action( 'template_redirect', array( __CLASS__, 'set_content_width' ) ); 
  16. add_action( 'admin_init', array( __CLASS__, 'set_content_width' ) ); 
  17.  
  18. if ( ! is_admin() ) 
  19. add_filter( 'stylesheet_uri', array( __CLASS__, 'style_filter' ) ); 
  20.  
  21. define( 
  22. 'SAFECSS_USE_ACE',  
  23. ! jetpack_is_mobile() && 
  24. ! Jetpack_User_Agent_Info::is_ipad() && 
  25. /** 
  26. * Should the Custom CSS module use ACE to process CSS. 
  27. * @see http://ace.c9.io/ 
  28. * 
  29. * @module custom-css 
  30. * 
  31. * @since 1.7.0 
  32. * 
  33. * @param bool true Use ACE to process the Custom CSS. Default to true. 
  34. */ 
  35. apply_filters( 'safecss_use_ace', true ) 
  36. ); 
  37.  
  38. // Register safecss as a custom post_type 
  39. // Explicit capability definitions are largely unnecessary because the posts are manipulated in code via an options page, managing CSS revisions does check the capabilities, so let's ensure that the proper caps are checked. 
  40. register_post_type( 'safecss', array( 
  41. // These are the defaults 
  42. // 'exclude_from_search' => true,  
  43. // 'public' => false,  
  44. // 'publicly_queryable' => false,  
  45. // 'show_ui' => false,  
  46. 'supports' => array( 'revisions' ),  
  47. 'label' => 'Custom CSS',  
  48. 'can_export' => false,  
  49. 'rewrite' => false,  
  50. 'capabilities' => array( 
  51. 'edit_post' => 'edit_theme_options',  
  52. 'read_post' => 'read',  
  53. 'delete_post' => 'edit_theme_options',  
  54. 'edit_posts' => 'edit_theme_options',  
  55. 'edit_others_posts' => 'edit_theme_options',  
  56. 'publish_posts' => 'edit_theme_options',  
  57. 'read_private_posts' => 'read' 
  58. ) ); 
  59.  
  60. // Short-circuit WP if this is a CSS stylesheet request 
  61. if ( isset( $_GET['custom-css'] ) ) { 
  62. header( 'Content-Type: text/css', true, 200 ); 
  63. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 31536000) . ' GMT' ); // 1 year 
  64. Jetpack_Custom_CSS::print_css(); 
  65. exit; 
  66.  
  67. add_action( 'admin_enqueue_scripts', array( 'Jetpack_Custom_CSS', 'enqueue_scripts' ) ); 
  68.  
  69. if ( isset( $_GET['page'] ) && 'editcss' == $_GET['page'] && is_admin() ) { 
  70. // Do migration routine if necessary 
  71. Jetpack_Custom_CSS::upgrade(); 
  72.  
  73. /** 
  74. * Allows additional work when migrating safecss from wp_options to wp_post. 
  75. * 
  76. * @module custom-css 
  77. * 
  78. * @since 1.7.0 
  79. */ 
  80. do_action( 'safecss_migrate_post' ); 
  81.  
  82. /** 
  83. * Never embed the style in the head on wpcom. 
  84. * Yes, this filter should be added to an unsynced file on wpcom, but 
  85. * there is no good syntactically-correct location to put it yet. 
  86. * @link https://github.com/Automattic/jetpack/commit/a1be114e9179f64d147124727a58e2cf76c7e5a1#commitcomment-7763921 
  87. */ 
  88. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  89. add_filter( 'safecss_embed_style', '__return_false' ); 
  90. } else { 
  91. add_filter( 'safecss_embed_style', array( 'Jetpack_Custom_CSS', 'should_we_inline_custom_css' ), 10, 2 ); 
  92.  
  93. add_action( 'wp_head', array( 'Jetpack_Custom_CSS', 'link_tag' ), 101 ); 
  94.  
  95. add_filter( 'jetpack_content_width', array( 'Jetpack_Custom_CSS', 'jetpack_content_width' ) ); 
  96. add_filter( 'editor_max_image_size', array( 'Jetpack_Custom_CSS', 'editor_max_image_size' ), 10, 3 ); 
  97.  
  98. if ( !current_user_can( 'switch_themes' ) && !is_super_admin() ) 
  99. return; 
  100.  
  101. add_action( 'admin_menu', array( 'Jetpack_Custom_CSS', 'menu' ) ); 
  102.  
  103. if ( isset( $_POST['safecss'] ) && false == strstr( $_SERVER[ 'REQUEST_URI' ], 'options.php' ) ) { 
  104. check_admin_referer( 'safecss' ); 
  105.  
  106. $save_result = self::save( array( 
  107. 'css' => stripslashes( $_POST['safecss'] ),  
  108. 'is_preview' => isset( $_POST['action'] ) && $_POST['action'] == 'preview',  
  109. 'preprocessor' => isset( $_POST['custom_css_preprocessor'] ) ? $_POST['custom_css_preprocessor'] : '',  
  110. 'add_to_existing' => isset( $_POST['add_to_existing'] ) ? $_POST['add_to_existing'] == 'true' : true,  
  111. 'content_width' => isset( $_POST['custom_content_width'] ) ? $_POST['custom_content_width'] : false,  
  112. ) ); 
  113.  
  114. if ( $_POST['action'] == 'preview' ) { 
  115. wp_safe_redirect( add_query_arg( 'csspreview', 'true', get_option( 'home' ) ) ); 
  116. exit; 
  117.  
  118. if ( $save_result ) 
  119. add_action( 'admin_notices', array( 'Jetpack_Custom_CSS', 'saved_message' ) ); 
  120.  
  121. // Prevent content filters running on CSS when restoring revisions 
  122. if ( isset( $_REQUEST[ 'action' ] ) && 'restore' === $_REQUEST[ 'action' ] && false !== strstr( $_SERVER[ 'REQUEST_URI' ], 'revision.php' ) ) { 
  123. $parent_post = get_post( wp_get_post_parent_id( intval( $_REQUEST[ 'revision' ] ) ) ); 
  124. if ( $parent_post && ! is_wp_error( $parent_post ) && 'safecss' === $parent_post->post_type ) { 
  125. // Remove wp_filter_post_kses, this causes CSS escaping issues 
  126. remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); 
  127. remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' ); 
  128. remove_all_filters( 'content_save_pre' ); 
  129.  
  130. // Modify all internal links so that preview state persists 
  131. if ( Jetpack_Custom_CSS::is_preview() ) 
  132. ob_start( array( 'Jetpack_Custom_CSS', 'buffer' ) ); 
  133.  
  134. /** 
  135. * Save new custom CSS. This should be the entry point for any third-party code using Jetpack_Custom_CSS 
  136. * to save CSS. 
  137. * 
  138. * @param array $args Array of arguments: 
  139. * string $css The CSS (or LESS or Sass) 
  140. * bool $is_preview Whether this CSS is preview or published 
  141. * string preprocessor Which CSS preprocessor to use 
  142. * bool $add_to_existing Whether this CSS replaces the theme's CSS or supplements it. 
  143. * int $content_width A custom $content_width to go along with this CSS. 
  144. * @return int The post ID of the saved Custom CSS post. 
  145. */ 
  146. public static function save( $args = array() ) { 
  147. $defaults = array( 
  148. 'css' => '',  
  149. 'is_preview' => false,  
  150. 'preprocessor' => '',  
  151. 'add_to_existing' => true,  
  152. 'content_width' => false,  
  153. ); 
  154.  
  155. $args = wp_parse_args( $args, $defaults ); 
  156.  
  157. if ( $args['content_width'] && intval( $args['content_width']) > 0 && ( ! isset( $GLOBALS['content_width'] ) || $args['content_width'] != $GLOBALS['content_width'] ) ) 
  158. $args['content_width'] = intval( $args['content_width'] ); 
  159. else 
  160. $args['content_width'] = false; 
  161.  
  162. // Remove wp_filter_post_kses, this causes CSS escaping issues 
  163. remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); 
  164. remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' ); 
  165. remove_all_filters( 'content_save_pre' ); 
  166.  
  167. /** 
  168. * Fires prior to saving custom css values. Necessitated because the 
  169. * core WordPress save_pre filters were removed: 
  170. * - content_save_pre 
  171. * - content_filtered_save_pre 
  172. * 
  173. * @module custom-css 
  174. * 
  175. * @since 1.7.0 
  176. * 
  177. * @param array $args { 
  178. * Array of custom CSS arguments. 
  179. * @type string $css The CSS (or LESS or Sass). 
  180. * @type bool $is_preview Whether this CSS is preview or published. 
  181. * @type string preprocessor Which CSS preprocessor to use. 
  182. * @type bool $add_to_existing Whether this CSS replaces the theme's CSS or supplements it. 
  183. * @type int $content_width A custom $content_width to go along with this CSS. 
  184. * } 
  185. */ 
  186. do_action( 'safecss_save_pre', $args ); 
  187.  
  188. $warnings = array(); 
  189.  
  190. safecss_class(); 
  191. $csstidy = new csstidy(); 
  192. $csstidy->optimise = new safecss( $csstidy ); 
  193.  
  194. $csstidy->set_cfg( 'remove_bslash', false ); 
  195. $csstidy->set_cfg( 'compress_colors', false ); 
  196. $csstidy->set_cfg( 'compress_font-weight', false ); 
  197. $csstidy->set_cfg( 'optimise_shorthands', 0 ); 
  198. $csstidy->set_cfg( 'remove_last_;', false ); 
  199. $csstidy->set_cfg( 'case_properties', false ); 
  200. $csstidy->set_cfg( 'discard_invalid_properties', true ); 
  201. $csstidy->set_cfg( 'css_level', 'CSS3.0' ); 
  202. $csstidy->set_cfg( 'preserve_css', true ); 
  203. $csstidy->set_cfg( 'template', dirname( __FILE__ ) . '/csstidy/wordpress-standard.tpl' ); 
  204.  
  205. $css = $orig = $args['css']; 
  206.  
  207. $css = preg_replace( '/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $prev = $css ); 
  208.  
  209. if ( $css != $prev ) 
  210. $warnings[] = 'preg_replace found stuff'; 
  211.  
  212. // Some people put weird stuff in their CSS, KSES tends to be greedy 
  213. $css = str_replace( '<=', '<=', $css ); 
  214. // Why KSES instead of strip_tags? Who knows? 
  215. $css = wp_kses_split( $prev = $css, array(), array() ); 
  216. $css = str_replace( '>', '>', $css ); // kses replaces lone '>' with > 
  217. // Why both KSES and strip_tags? Because we just added some '>'. 
  218. $css = strip_tags( $css ); 
  219.  
  220. if ( $css != $prev ) 
  221. $warnings[] = 'kses found stuff'; 
  222.  
  223. // if we're not using a preprocessor 
  224. if ( ! $args['preprocessor'] ) { 
  225.  
  226. /** 
  227. * Fires before parsing the css with CSSTidy, but only if 
  228. * the preprocessor is not configured for use. 
  229. * 
  230. * @module custom-css 
  231. * 
  232. * @since 1.7.0 
  233. * 
  234. * @param obj $csstidy The csstidy object. 
  235. * @param string $css Custom CSS. 
  236. * @param array $args Array of custom CSS arguments. 
  237. */ 
  238. do_action( 'safecss_parse_pre', $csstidy, $css, $args ); 
  239.  
  240. $csstidy->parse( $css ); 
  241.  
  242. /** 
  243. * Fires after parsing the css with CSSTidy, but only if 
  244. * the preprocessor is not cinfigured for use. 
  245. * 
  246. * @module custom-css 
  247. * 
  248. * @since 1.7.0 
  249. * 
  250. * @param obj $csstidy The csstidy object. 
  251. * @param array $warnings Array of warnings. 
  252. * @param array $args Array of custom CSS arguments. 
  253. */ 
  254. do_action( 'safecss_parse_post', $csstidy, $warnings, $args ); 
  255.  
  256. $css = $csstidy->print->plain(); 
  257.  
  258. if ( $args['add_to_existing'] ) 
  259. $add_to_existing = 'yes'; 
  260. else 
  261. $add_to_existing = 'no'; 
  262.  
  263. if ( $args['is_preview'] || Jetpack_Custom_CSS::is_freetrial() ) { 
  264. // Save the CSS 
  265. $safecss_revision_id = Jetpack_Custom_CSS::save_revision( $css, true, $args['preprocessor'] ); 
  266.  
  267. // Cache Buster 
  268. update_option( 'safecss_preview_rev', intval( get_option( 'safecss_preview_rev' ) ) + 1); 
  269.  
  270. update_metadata( 'post', $safecss_revision_id, 'custom_css_add', $add_to_existing ); 
  271. update_metadata( 'post', $safecss_revision_id, 'content_width', $args['content_width'] ); 
  272. update_metadata( 'post', $safecss_revision_id, 'custom_css_preprocessor', $args['preprocessor'] ); 
  273.  
  274. delete_option( 'safecss_add' ); 
  275. delete_option( 'safecss_content_width' ); 
  276.  
  277. if ( $args['is_preview'] ) { 
  278. return $safecss_revision_id; 
  279.  
  280. /** 
  281. * Fires after saving Custom CSS. 
  282. * 
  283. * @module custom-css 
  284. * 
  285. * @since 1.7.0 
  286. */ 
  287. do_action( 'safecss_save_preview_post' ); 
  288.  
  289. // Save the CSS 
  290. $safecss_post_id = Jetpack_Custom_CSS::save_revision( $css, false, $args['preprocessor'] ); 
  291.  
  292. $safecss_post_revision = Jetpack_Custom_CSS::get_current_revision(); 
  293.  
  294. update_option( 'safecss_rev', intval( get_option( 'safecss_rev' ) ) + 1 ); 
  295.  
  296. update_post_meta( $safecss_post_id, 'custom_css_add', $add_to_existing ); 
  297. update_post_meta( $safecss_post_id, 'content_width', $args['content_width'] ); 
  298. update_post_meta( $safecss_post_id, 'custom_css_preprocessor', $args['preprocessor'] ); 
  299.  
  300. delete_option( 'safecss_add' ); 
  301. delete_option( 'safecss_content_width' ); 
  302.  
  303. update_metadata( 'post', $safecss_post_revision['ID'], 'custom_css_add', $add_to_existing ); 
  304. update_metadata( 'post', $safecss_post_revision['ID'], 'content_width', $args['content_width'] ); 
  305. update_metadata( 'post', $safecss_post_revision['ID'], 'custom_css_preprocessor', $args['preprocessor'] ); 
  306.  
  307. delete_option( 'safecss_preview_add' ); 
  308.  
  309. return $safecss_post_id; 
  310.  
  311. /** 
  312. * Get the published custom CSS post. 
  313. * 
  314. * @return array 
  315. */ 
  316. static function get_post() { 
  317. $custom_css_post_id = Jetpack_Custom_CSS::post_id(); 
  318.  
  319. if ( $custom_css_post_id ) 
  320. return get_post( $custom_css_post_id, ARRAY_A ); 
  321.  
  322. return array(); 
  323.  
  324. /** 
  325. * Get the post ID of the published custom CSS post. 
  326. * 
  327. * @return int|bool The post ID if it exists; false otherwise. 
  328. */ 
  329. static function post_id() { 
  330. $custom_css_post_id = wp_cache_get( 'custom_css_post_id' ); 
  331.  
  332. if ( false === $custom_css_post_id ) { 
  333. $custom_css_posts = get_posts( array( 
  334. 'posts_per_page' => 1,  
  335. 'post_type' => 'safecss',  
  336. 'post_status' => 'publish',  
  337. 'orderby' => 'date',  
  338. 'order' => 'DESC' 
  339. ) ); 
  340.  
  341. if ( count( $custom_css_posts ) > 0 ) 
  342. $custom_css_post_id = $custom_css_posts[0]->ID; 
  343. else 
  344. $custom_css_post_id = 0; 
  345.  
  346. // Save post_id=0 to note that no safecss post exists. 
  347. wp_cache_set( 'custom_css_post_id', $custom_css_post_id ); 
  348.  
  349. if ( ! $custom_css_post_id ) 
  350. return false; 
  351.  
  352. return $custom_css_post_id; 
  353.  
  354. /** 
  355. * Get the current revision of the original safecss record 
  356. * 
  357. * @return object 
  358. */ 
  359. static function get_current_revision() { 
  360. $safecss_post = Jetpack_Custom_CSS::get_post(); 
  361.  
  362. if ( empty( $safecss_post ) ) { 
  363. return false; 
  364.  
  365. $revisions = wp_get_post_revisions( $safecss_post['ID'], array( 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC' ) ); 
  366.  
  367. // Empty array if no revisions exist 
  368. if ( empty( $revisions ) ) { 
  369. // Return original post 
  370. return $safecss_post; 
  371. } else { 
  372. // Return the first entry in $revisions, this will be the current revision 
  373. $current_revision = get_object_vars( array_shift( $revisions ) ); 
  374. return $current_revision; 
  375.  
  376. /** 
  377. * Save new revision of CSS 
  378. * Checks to see if content was modified before really saving 
  379. * 
  380. * @param string $css 
  381. * @param bool $is_preview 
  382. * @return bool|int If nothing was saved, returns false. If a post 
  383. * or revision was saved, returns the post ID. 
  384. */ 
  385. static function save_revision( $css, $is_preview = false, $preprocessor = '' ) { 
  386. $safecss_post = Jetpack_Custom_CSS::get_post(); 
  387.  
  388. $compressed_css = Jetpack_Custom_CSS::minify( $css, $preprocessor ); 
  389.  
  390. // If null, there was no original safecss record, so create one 
  391. if ( null == $safecss_post ) { 
  392. if ( ! $css ) 
  393. return false; 
  394.  
  395. $post = array(); 
  396. $post['post_content'] = $css; 
  397. $post['post_title'] = 'safecss'; 
  398. $post['post_status'] = 'publish'; 
  399. $post['post_type'] = 'safecss'; 
  400. $post['post_content_filtered'] = $compressed_css; 
  401.  
  402. // Set excerpt to current theme, for display in revisions list 
  403. if ( function_exists( 'wp_get_theme' ) ) { 
  404. $current_theme = wp_get_theme(); 
  405. $post['post_excerpt'] = $current_theme->Name; 
  406. else { 
  407. $post['post_excerpt'] = get_current_theme(); 
  408.  
  409. // Insert the CSS into wp_posts 
  410. $post_id = wp_insert_post( $post ); 
  411. wp_cache_set( 'custom_css_post_id', $post_id ); 
  412. return $post_id; 
  413.  
  414. // Update CSS in post array with new value passed to this function 
  415. $safecss_post['post_content'] = $css; 
  416. $safecss_post['post_content_filtered'] = $compressed_css; 
  417.  
  418. // Set excerpt to current theme, for display in revisions list 
  419. if ( function_exists( 'wp_get_theme' ) ) { 
  420. $current_theme = wp_get_theme(); 
  421. $safecss_post['post_excerpt'] = $current_theme->Name; 
  422. else { 
  423. $safecss_post['post_excerpt'] = get_current_theme(); 
  424.  
  425. // Don't carry over last revision's timestamps, otherwise revisions all have matching timestamps 
  426. unset( $safecss_post['post_date'] ); 
  427. unset( $safecss_post['post_date_gmt'] ); 
  428. unset( $safecss_post['post_modified'] ); 
  429. unset( $safecss_post['post_modified_gmt'] ); 
  430.  
  431. // Do not update post if we are only saving a preview 
  432. if ( false === $is_preview ) { 
  433. $post_id = wp_update_post( $safecss_post ); 
  434. wp_cache_set( 'custom_css_post_id', $post_id ); 
  435. return $post_id; 
  436. else if ( ! defined( 'DOING_MIGRATE' ) ) { 
  437. return _wp_put_post_revision( $safecss_post ); 
  438.  
  439. static function skip_stylesheet() { 
  440. /** 
  441. * Prevent the Custom CSS stylesheet from being enqueued. 
  442. * 
  443. * @module custom-css 
  444. * 
  445. * @since 2.2.1 
  446. * 
  447. * @param null Should the stylesheet be skipped. Default to null. Anything else will force the stylesheet to be skipped. 
  448. */ 
  449. $skip_stylesheet = apply_filters( 'safecss_skip_stylesheet', null ); 
  450.  
  451. if ( null !== $skip_stylesheet ) { 
  452. return $skip_stylesheet; 
  453. } elseif ( Jetpack_Custom_CSS::is_customizer_preview() ) { 
  454. return false; 
  455. } else { 
  456. if ( Jetpack_Custom_CSS::is_preview() ) { 
  457. $safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  458.  
  459. if ( $safecss_post ) 
  460. return (bool) ( get_post_meta( $safecss_post['ID'], 'custom_css_add', true ) == 'no' ); 
  461. else 
  462. return (bool) ( get_option( 'safecss_preview_add' ) == 'no' ); 
  463. else { 
  464. $custom_css_post_id = Jetpack_Custom_CSS::post_id(); 
  465.  
  466. if ( $custom_css_post_id ) { 
  467. $custom_css_add = get_post_meta( $custom_css_post_id, 'custom_css_add', true ); 
  468.  
  469. // It is possible for the CSS to be stored in a post but for the safecss_add option 
  470. // to have not been upgraded yet if the user hasn't opened their Custom CSS editor 
  471. // since October 2012. 
  472. if ( ! empty( $custom_css_add ) ) 
  473. return (bool) ( $custom_css_add === 'no' ); 
  474.  
  475. return (bool) ( get_option( 'safecss_add' ) == 'no' ); 
  476.  
  477. static function is_preview() { 
  478. return isset( $_GET['csspreview'] ) && $_GET['csspreview'] === 'true'; 
  479.  
  480. /** 
  481. * Currently this filter function gets called on 
  482. * 'template_redirect' action and 
  483. * 'admin_init' action 
  484. */ 
  485. static function set_content_width() { 
  486. // Don't apply this filter on the Edit CSS page 
  487. if ( isset( $_GET ) && isset( $_GET['page'] ) && 'editcss' == $_GET['page'] && is_admin() ) { 
  488. return; 
  489.  
  490. $GLOBALS['content_width'] = Jetpack::get_content_width(); 
  491.  
  492. /** 
  493. * False when the site has the Custom Design upgrade. 
  494. * Used only on WordPress.com. 
  495. */ 
  496. static function is_freetrial() { 
  497. /** 
  498. * Determine if a WordPress.com site uses a Free trial of the Custom Design Upgrade. 
  499. * Used only on WordPress.com. 
  500. * 
  501. * @module custom-css 
  502. * 
  503. * @since 1.7.0 
  504. * 
  505. * @param bool false Does the site use a Free trial of the Custom Design Upgrade. Default to false. 
  506. */ 
  507. return apply_filters( 'safecss_is_freetrial', false ); 
  508.  
  509. static function get_preprocessor_key() { 
  510. $safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  511. return get_post_meta( $safecss_post['ID'], 'custom_css_preprocessor', true ); 
  512.  
  513. static function get_preprocessor() { 
  514. /** This filter is documented in modules/custom-css/custom-css.php */ 
  515. $preprocessors = apply_filters( 'jetpack_custom_css_preprocessors', array() ); 
  516. $selected_preprocessor_key = self::get_preprocessor_key(); 
  517. $selected_preprocessor = isset( $preprocessors[ $selected_preprocessor_key ] ) ? $preprocessors[ $selected_preprocessor_key ] : null; 
  518. return $selected_preprocessor; 
  519.  
  520. static function get_css( $compressed = false ) { 
  521. /** 
  522. * Filter the Custom CSS returned. 
  523. * Can be used to return an error, or no CSS at all. 
  524. * 
  525. * @module custom-css 
  526. * 
  527. * @since 1.7.0 
  528. * 
  529. * @param bool false Should we return an error instead of the Custom CSS. Default to false. 
  530. */ 
  531. $default_css = apply_filters( 'safecss_get_css_error', false ); 
  532.  
  533. if ( $default_css !== false ) 
  534. return $default_css; 
  535.  
  536. $option = ( Jetpack_Custom_CSS::is_preview() || Jetpack_Custom_CSS::is_freetrial() ) ? 'safecss_preview' : 'safecss'; 
  537. $css = ''; 
  538.  
  539. if ( 'safecss' == $option ) { 
  540. // Don't bother checking for a migrated 'safecss' option if it never existed. 
  541. if ( false === get_option( 'safecss' ) || get_option( 'safecss_revision_migrated' ) ) { 
  542. $safecss_post = Jetpack_Custom_CSS::get_post(); 
  543. if ( ! empty( $safecss_post ) ) { 
  544. $css = ( $compressed && $safecss_post['post_content_filtered'] ) ? $safecss_post['post_content_filtered'] : $safecss_post['post_content']; 
  545. } else { 
  546. $current_revision = Jetpack_Custom_CSS::get_current_revision(); 
  547. if ( false === $current_revision ) { 
  548. $css = ''; 
  549. } else { 
  550. $css = ( $compressed && $current_revision['post_content_filtered'] ) ? $current_revision['post_content_filtered'] : $current_revision['post_content']; 
  551.  
  552. // Fix for un-migrated Custom CSS 
  553. if ( empty( $safecss_post ) ) { 
  554. $_css = get_option( 'safecss' ); 
  555. if ( !empty( $_css ) ) { 
  556. $css = $_css; 
  557. else if ( 'safecss_preview' == $option ) { 
  558. $safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  559. $css = $safecss_post['post_content']; 
  560. $css = stripslashes( $css ); 
  561. $css = Jetpack_Custom_CSS::minify( $css, get_post_meta( $safecss_post['ID'], 'custom_css_preprocessor', true ) ); 
  562.  
  563. $css = str_replace( array( '\\\00BB \\\0020', '\0BB \020', '0BB 020' ), '\00BB \0020', $css ); 
  564.  
  565. if ( empty( $css ) ) { 
  566. $css = "/*\n" 
  567. . wordwrap( 
  568. /** 
  569. * Filter the default message displayed in the Custom CSS editor. 
  570. * 
  571. * @module custom-css 
  572. * 
  573. * @since 1.7.0 
  574. * 
  575. * @param string $str Default Custom CSS editor content. 
  576. */ 
  577. apply_filters( 
  578. 'safecss_default_css',  
  579. __( 
  580. "Welcome to Custom CSS!\n\nTo learn how this works, see http://wp.me/PEmnE-Bt",  
  581. 'jetpack' 
  582. . "\n*/"; 
  583.  
  584. /** 
  585. * Filter the Custom CSS returned from the editor. 
  586. * 
  587. * @module custom-css 
  588. * 
  589. * @since 1.7.0 
  590. * 
  591. * @param string $css Custom CSS. 
  592. */ 
  593. $css = apply_filters( 'safecss_css', $css ); 
  594.  
  595. return $css; 
  596.  
  597. static function replace_insecure_urls( $css ) { 
  598. if ( ! function_exists( '_sa_get_frontend_https_url_replacement_map' ) ) { 
  599. return $css; 
  600. list( $http_urls, $secure_urls ) = _sa_get_frontend_https_url_replacement_map(); 
  601.  
  602. return str_replace( $http_urls, $secure_urls, $css ); 
  603.  
  604. static function print_css() { 
  605.  
  606. /** 
  607. * Fires right before printing the custom CSS inside the <head> element. 
  608. * 
  609. * @module custom-css 
  610. * 
  611. * @since 1.7.0 
  612. */ 
  613. do_action( 'safecss_print_pre' ); 
  614. $css = Jetpack_Custom_CSS::get_css( true ); 
  615. echo self::replace_insecure_urls( $css ); 
  616.  
  617. static function should_we_inline_custom_css( $should_we, $css ) { 
  618. // If the CSS is less than 2, 000 characters, inline it! otherwise return what was passed in. 
  619. return ( strlen( $css ) < 2000 ) ? true : $should_we; 
  620.  
  621. static function link_tag() { 
  622. global $blog_id, $current_blog; 
  623.  
  624. if ( 
  625. /** 
  626. * Do not include any CSS on the page if the CSS includes an error. 
  627. * Setting this filter to true stops any Custom CSS from being enqueued. 
  628. * 
  629. * @module custom-css 
  630. * 
  631. * @since 1.7.0 
  632. * 
  633. * @param bool false Does the CSS include an error. Default to false. 
  634. */ 
  635. apply_filters( 'safecss_style_error', false ) 
  636. ) { 
  637. return; 
  638.  
  639. if ( ! is_super_admin() && isset( $current_blog ) && ( 1 == $current_blog->spam || 1 == $current_blog->deleted ) ) 
  640. return; 
  641.  
  642. if ( Jetpack_Custom_CSS::is_customizer_preview() ) 
  643. return; 
  644.  
  645. $css = ''; 
  646. $option = Jetpack_Custom_CSS::is_preview() ? 'safecss_preview' : 'safecss'; 
  647.  
  648. if ( 'safecss' == $option ) { 
  649. if ( get_option( 'safecss_revision_migrated' ) ) { 
  650. $safecss_post = Jetpack_Custom_CSS::get_post(); 
  651.  
  652. if ( ! empty( $safecss_post['post_content'] ) ) { 
  653. $css = $safecss_post['post_content']; 
  654. } else { 
  655. $current_revision = Jetpack_Custom_CSS::get_current_revision(); 
  656.  
  657. if ( ! empty( $current_revision['post_content'] ) ) { 
  658. $css = $current_revision['post_content']; 
  659.  
  660. // Fix for un-migrated Custom CSS 
  661. if ( empty( $safecss_post ) ) { 
  662. $_css = get_option( 'safecss' ); 
  663. if ( !empty( $_css ) ) { 
  664. $css = $_css; 
  665.  
  666. if ( 'safecss_preview' == $option ) { 
  667. $safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  668.  
  669. if ( !empty( $safecss_post['post_content'] ) ) { 
  670. $css = $safecss_post['post_content']; 
  671.  
  672. $css = str_replace( array( '\\\00BB \\\0020', '\0BB \020', '0BB 020' ), '\00BB \0020', $css ); 
  673.  
  674. if ( $css == '' ) 
  675. return; 
  676.  
  677. if ( 
  678. /** 
  679. * Allow inserting CSS inline instead of through a separate file. 
  680. * 
  681. * @module custom-css 
  682. * 
  683. * @since 3.4.0 
  684. * 
  685. * @param bool false Should the CSS be added inline instead of through a separate file. Default to false. 
  686. * @param string $css Custom CSS. 
  687. */ 
  688. apply_filters( 'safecss_embed_style', false, $css ) 
  689. ) { 
  690.  
  691. echo "\r\n" . '<style id="custom-css-css">' . Jetpack_Custom_CSS::get_css( true ) . "</style>\r\n"; 
  692.  
  693. } else { 
  694.  
  695. $href = home_url( '/' ); 
  696. $href = add_query_arg( 'custom-css', 1, $href ); 
  697. $href = add_query_arg( 'csblog', $blog_id, $href ); 
  698. $href = add_query_arg( 'cscache', 6, $href ); 
  699. $href = add_query_arg( 'csrev', (int) get_option( $option . '_rev' ), $href ); 
  700.  
  701. /** 
  702. * Filter the Custom CSS link enqueued in the head. 
  703. * 
  704. * @module custom-css 
  705. * 
  706. * @since 1.7.0 
  707. * 
  708. * @param string $href Custom CSS link enqueued in the head. 
  709. * @param string $blog_id Blog ID. 
  710. */ 
  711. $href = apply_filters( 'safecss_href', $href, $blog_id ); 
  712.  
  713. if ( Jetpack_Custom_CSS::is_preview() ) 
  714. $href = add_query_arg( 'csspreview', 'true', $href ); 
  715.  
  716. ?> 
  717. <link rel="stylesheet" id="custom-css-css" type="text/css" href="<?php echo esc_url( $href ); ?>" /> 
  718. <?php 
  719.  
  720.  
  721. /** 
  722. * Fires after creating the <link> in the <head> element for the custom css stylesheet. 
  723. * 
  724. * @module custom-css 
  725. * 
  726. * @since 2.2.2 
  727. */ 
  728. do_action( 'safecss_link_tag_post' ); 
  729.  
  730. static function style_filter( $current ) { 
  731. if ( Jetpack_Custom_CSS::is_freetrial() && ( ! Jetpack_Custom_CSS::is_preview() || ! current_user_can( 'switch_themes' ) ) ) 
  732. return $current; 
  733. else if ( Jetpack_Custom_CSS::skip_stylesheet() ) 
  734. /** 
  735. * Filter the default blank Custom CSS URL. 
  736. * 
  737. * @module custom-css 
  738. * 
  739. * @since 2.2.1 
  740. * 
  741. * @param string $url Default blank Custom CSS URL. 
  742. */ 
  743. return apply_filters( 'safecss_style_filter_url', plugins_url( 'custom-css/css/blank.css', __FILE__ ) ); 
  744.  
  745. return $current; 
  746.  
  747. static function buffer( $html ) { 
  748. $html = str_replace( '</body>', Jetpack_Custom_CSS::preview_flag(), $html ); 
  749. return preg_replace_callback( '!href=([\'"])(.*?)\\1!', array( 'Jetpack_Custom_CSS', 'preview_links' ), $html ); 
  750.  
  751. static function preview_links( $matches ) { 
  752. if ( 0 !== strpos( $matches[2], get_option( 'home' ) ) ) 
  753. return $matches[0]; 
  754.  
  755. $link = wp_specialchars_decode( $matches[2] ); 
  756. $link = add_query_arg( 'csspreview', 'true', $link ); 
  757. $link = esc_url( $link ); 
  758. return "href={$matches[1]}$link{$matches[1]}"; 
  759.  
  760. /** 
  761. * Places a black bar above every preview page 
  762. */ 
  763. static function preview_flag() { 
  764. if ( is_admin() ) 
  765. return; 
  766.  
  767. $message = esc_html__( 'Preview: changes must be saved or they will be lost', 'jetpack' ); 
  768. /** 
  769. * Filter the Preview message displayed on the site when previewing custom CSS, before to save it. 
  770. * 
  771. * @module custom-css 
  772. * 
  773. * @since 1.7.0 
  774. * 
  775. * @param string $message Custom CSS preview message. 
  776. */ 
  777. $message = apply_filters( 'safecss_preview_message', $message ); 
  778.  
  779. $preview_flag_js = "var flag = document.createElement('div'); 
  780. flag.innerHTML = " . json_encode( $message ) . "; 
  781. flag.style.background = '#FF6600'; 
  782. flag.style.color = 'white'; 
  783. flag.style.textAlign = 'center'; 
  784. flag.style.fontSize = '15px'; 
  785. flag.style.padding = '2px'; 
  786. flag.style.fontFamily = 'sans-serif'; 
  787. document.body.style.paddingTop = '0px'; 
  788. document.body.insertBefore(flag, document.body.childNodes[0]); 
  789. "; 
  790.  
  791. /** 
  792. * Filter the Custom CSS preview message JS styling. 
  793. * 
  794. * @module custom-css 
  795. * 
  796. * @since 1.7.0 
  797. * 
  798. * @param string $preview_flag_js Custom CSS preview message JS styling. 
  799. */ 
  800. $preview_flag_js = apply_filters( 'safecss_preview_flag_js', $preview_flag_js ); 
  801. if ( $preview_flag_js ) { 
  802. $preview_flag_js = '<script type="text/javascript"> 
  803. // <![CDATA[ 
  804. ' . $preview_flag_js . ' 
  805. // ]]> 
  806. </script>'; 
  807.  
  808. return $preview_flag_js; 
  809.  
  810. static function menu() { 
  811. $parent = 'themes.php'; 
  812. $title = __( 'Edit CSS', 'jetpack' ); 
  813. $hook = add_theme_page( $title, $title, 'edit_theme_options', 'editcss', array( 'Jetpack_Custom_CSS', 'admin' ) ); 
  814.  
  815. add_action( "load-revision.php", array( 'Jetpack_Custom_CSS', 'prettify_post_revisions' ) ); 
  816. add_action( "load-$hook", array( 'Jetpack_Custom_CSS', 'update_title' ) ); 
  817.  
  818. /** 
  819. * Adds a menu item in the appearance section for this plugin's administration 
  820. * page. Also adds hooks to enqueue the CSS and JS for the admin page. 
  821. */ 
  822. static function update_title() { 
  823. global $title; 
  824. $title = __( 'CSS', 'jetpack' ); 
  825.  
  826. static function prettify_post_revisions() { 
  827. add_filter( 'the_title', array( 'Jetpack_Custom_CSS', 'post_title' ), 10, 2 ); 
  828.  
  829. static function post_title( $title, $post_id ) { 
  830. if ( !$post_id = (int) $post_id ) { 
  831. return $title; 
  832.  
  833. if ( !$post = get_post( $post_id ) ) { 
  834. return $title; 
  835.  
  836. if ( 'safecss' != $post->post_type ) { 
  837. return $title; 
  838.  
  839. return __( 'Custom CSS Stylesheet', 'jetpack' ); 
  840.  
  841. static function enqueue_scripts( $hook ) { 
  842. if ( 'appearance_page_editcss' != $hook ) 
  843. return; 
  844.  
  845. wp_enqueue_script( 'postbox' ); 
  846. wp_enqueue_script( 'custom-css-editor', plugins_url( 'custom-css/js/css-editor.js', __FILE__ ), 'jquery', '20130325', true ); 
  847. wp_enqueue_style( 'custom-css-editor', plugins_url( 'custom-css/css/css-editor.css', __FILE__ ) ); 
  848.  
  849. if ( defined( 'SAFECSS_USE_ACE' ) && SAFECSS_USE_ACE ) { 
  850. wp_register_style( 'jetpack-css-codemirror', plugins_url( 'custom-css/css/codemirror.css', __FILE__ ), array(), '20120905' ); 
  851. wp_enqueue_style( 'jetpack-css-use-codemirror', plugins_url( 'custom-css/css/use-codemirror.css', __FILE__ ), array( 'jetpack-css-codemirror' ), '20120905' ); 
  852.  
  853. wp_register_script( 'jetpack-css-codemirror', plugins_url( 'custom-css/js/codemirror.min.js', __FILE__ ), array(), '3.16', true ); 
  854. wp_enqueue_script( 'jetpack-css-use-codemirror', plugins_url( 'custom-css/js/use-codemirror.js', __FILE__ ), array( 'jquery', 'underscore', 'jetpack-css-codemirror' ), '20131009', true ); 
  855.  
  856. static function saved_message() { 
  857. echo '<div id="message" class="updated fade"><p><strong>' . __( 'Stylesheet saved.', 'jetpack' ) . '</strong></p></div>'; 
  858.  
  859. static function admin() { 
  860. add_meta_box( 'submitdiv', __( 'Publish', 'jetpack' ), array( __CLASS__, 'publish_box' ), 'editcss', 'side' ); 
  861. add_action( 'custom_css_submitbox_misc_actions', array( __CLASS__, 'content_width_settings' ) ); 
  862.  
  863. $safecss_post = Jetpack_Custom_CSS::get_post(); 
  864.  
  865. if ( ! empty( $safecss_post ) && 0 < $safecss_post['ID'] && wp_get_post_revisions( $safecss_post['ID'] ) ) 
  866. add_meta_box( 'revisionsdiv', __( 'CSS Revisions', 'jetpack' ), array( __CLASS__, 'revisions_meta_box' ), 'editcss', 'side' ); 
  867. ?> 
  868. <div class="wrap"> 
  869. <?php 
  870.  
  871. /** 
  872. * Fires right before the custom css page begins. 
  873. * 
  874. * @module custom-css 
  875. * 
  876. * @since 1.7.0 
  877. */ 
  878. do_action( 'custom_design_header' ); 
  879.  
  880. ?> 
  881. <h1><?php _e( 'CSS Stylesheet Editor', 'jetpack' ); ?></h1> 
  882. <form id="safecssform" action="" method="post"> 
  883. <?php wp_nonce_field( 'safecss' ) ?> 
  884. <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> 
  885. <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> 
  886. <input type="hidden" name="action" value="save" /> 
  887. <div id="poststuff"> 
  888. <p class="css-support"> 
  889. <?php 
  890. /** 
  891. * Filter the intro text appearing above the Custom CSS Editor. 
  892. * 
  893. * @module custom-css 
  894. * 
  895. * @since 1.7.0 
  896. * 
  897. * @param string $str Intro text appearing above the Custom CSS editor. 
  898. */ 
  899. echo apply_filters( 'safecss_intro_text', __( 'New to CSS? Start with a <a href="http://www.htmldog.com/guides/cssbeginner/">beginner tutorial</a>. Questions? 
  900. Ask in the <a href="http://wordpress.org/support/forum/themes-and-templates">Themes and Templates forum</a>.', 'jetpack' ) ); 
  901. ?></p> 
  902. <p class="css-support"><?php echo __( 'Note: Custom CSS will be reset when changing themes.', 'jetpack' ); ?></p> 
  903.  
  904. <div id="post-body" class="metabox-holder columns-2"> 
  905. <div id="post-body-content"> 
  906. <div class="postarea"> 
  907. <textarea id="safecss" name="safecss"<?php if ( SAFECSS_USE_ACE ) echo ' class="hide-if-js"'; ?>><?php echo esc_textarea( Jetpack_Custom_CSS::get_css() ); ?></textarea> 
  908. <div class="clear"></div> 
  909. </div> 
  910. </div> 
  911. <div id="postbox-container-1" class="postbox-container"> 
  912. <?php do_meta_boxes( 'editcss', 'side', $safecss_post ); ?> 
  913. </div> 
  914. </div> 
  915. <br class="clear" /> 
  916. </div> 
  917. </form> 
  918. </div> 
  919. <?php 
  920.  
  921. /** 
  922. * Content width setting callback 
  923. */ 
  924. static function content_width_settings() { 
  925. $safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  926.  
  927. $custom_content_width = get_post_meta( $safecss_post['ID'], 'content_width', true ); 
  928.  
  929. // If custom content width hasn't been overridden and the theme has a content_width value, use that as a default. 
  930. if ( $custom_content_width <= 0 && ! empty( $GLOBALS['content_width'] ) ) 
  931. $custom_content_width = $GLOBALS['content_width']; 
  932.  
  933. if ( ! $custom_content_width || ( isset( $GLOBALS['content_width'] ) && $custom_content_width == $GLOBALS['content_width'] ) ) 
  934. $custom_content_width = ''; 
  935.  
  936. ?> 
  937. <div class="misc-pub-section"> 
  938. <label><?php esc_html_e( 'Media Width:', 'jetpack' ); ?></label> 
  939. <span id="content-width-display" data-default-text="<?php esc_attr_e( 'Default', 'jetpack' ); ?>" data-custom-text="<?php esc_attr_e( '%s px', 'jetpack' ); ?>"><?php echo $custom_content_width ? sprintf( esc_html__( '%s px', 'jetpack' ), $custom_content_width ) : esc_html_e( 'Default', 'jetpack' ); ?></span> 
  940. <a class="edit-content-width hide-if-no-js" href="#content-width"><?php echo esc_html_e( 'Edit', 'jetpack' ); ?></a> 
  941. <div id="content-width-select" class="hide-if-js"> 
  942. <input type="hidden" name="custom_content_width" id="custom_content_width" value="<?php echo esc_attr( $custom_content_width ); ?>" /> 
  943. <p> 
  944. <?php 
  945.  
  946. printf( 
  947. __( 'Limit width to %1$s pixels for full size images. (<a href="%2$s">More info</a>.)', 'jetpack' ),  
  948. '<input type="text" id="custom_content_width_visible" value="' . esc_attr( $custom_content_width ) . '" size="4" />',  
  949. /** 
  950. * Filter the Custom CSS limited width's support doc URL. 
  951. * 
  952. * @module custom-css 
  953. * 
  954. * @since 2.2.3 
  955. * 
  956. * @param string $url Custom CSS limited width's support doc URL. 
  957. */ 
  958. apply_filters( 'safecss_limit_width_link', 'http://jetpack.me/support/custom-css/#limited-width' ) 
  959. ); 
  960.  
  961. ?> 
  962. </p> 
  963. <?php 
  964.  
  965. if ( !empty( $GLOBALS['content_width'] ) && $custom_content_width != $GLOBALS['content_width'] ) { 
  966. if ( function_exists( 'wp_get_theme' ) ) 
  967. $current_theme = wp_get_theme()->Name; 
  968. else 
  969. $current_theme = get_current_theme(); 
  970.  
  971. ?> 
  972. <p><?php printf( __( 'The default content width for the %s theme is %d pixels.', 'jetpack' ), $current_theme, intval( $GLOBALS['content_width'] ) ); ?></p> 
  973. <?php 
  974.  
  975. ?> 
  976. <a class="save-content-width hide-if-no-js button" href="#content-width"><?php esc_html_e( 'OK', 'jetpack' ); ?></a> 
  977. <a class="cancel-content-width hide-if-no-js" href="#content-width"><?php esc_html_e( 'Cancel', 'jetpack' ); ?></a> 
  978. </div> 
  979. <script type="text/javascript"> 
  980. jQuery( function ( $ ) { 
  981. var defaultContentWidth = <?php echo isset( $GLOBALS['content_width'] ) ? json_encode( intval( $GLOBALS['content_width'] ) ) : 0; ?>; 
  982.  
  983. $( '.edit-content-width' ).bind( 'click', function ( e ) { 
  984. e.preventDefault(); 
  985.  
  986. $( '#content-width-select' ).slideDown(); 
  987. $( this ).hide(); 
  988. } ); 
  989.  
  990. $( '.cancel-content-width' ).bind( 'click', function ( e ) { 
  991. e.preventDefault(); 
  992.  
  993. $( '#content-width-select' ).slideUp( function () { 
  994. $( '.edit-content-width' ).show(); 
  995. $( '#custom_content_width_visible' ).val( $( '#custom_content_width' ).val() ); 
  996. } ); 
  997. } ); 
  998.  
  999. $( '.save-content-width' ).bind( 'click', function ( e ) { 
  1000. e.preventDefault(); 
  1001.  
  1002. $( '#content-width-select' ).slideUp(); 
  1003.  
  1004. var newContentWidth = parseInt( $( '#custom_content_width_visible' ).val(), 10 ); 
  1005.  
  1006. if ( newContentWidth && newContentWidth != defaultContentWidth ) { 
  1007. $( '#content-width-display' ).text( 
  1008. $( '#content-width-display' ) 
  1009. .data( 'custom-text' ) 
  1010. .replace( '%s', $( '#custom_content_width_visible' ).val() ) 
  1011. ); 
  1012. else { 
  1013. $( '#content-width-display' ).text( $( '#content-width-display' ).data( 'default-text' ) ); 
  1014.  
  1015. $( '#custom_content_width' ).val( $( '#custom_content_width_visible' ).val() ); 
  1016. $( '.edit-content-width' ).show(); 
  1017. } ); 
  1018. } ); 
  1019. </script> 
  1020. </div> 
  1021. <?php 
  1022.  
  1023. static function publish_box() { 
  1024. ?> 
  1025. <div id="minor-publishing"> 
  1026. <div id="misc-publishing-actions"> 
  1027. <?php 
  1028.  
  1029. /** 
  1030. * Filter the array of available Custom CSS preprocessors. 
  1031. * 
  1032. * @module custom-css 
  1033. * 
  1034. * @since 2.0.3 
  1035. * 
  1036. * @param array array() Empty by default. 
  1037. */ 
  1038. $preprocessors = apply_filters( 'jetpack_custom_css_preprocessors', array() ); 
  1039.  
  1040. if ( ! empty( $preprocessors ) ) { 
  1041. $safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  1042. $selected_preprocessor_key = get_post_meta( $safecss_post['ID'], 'custom_css_preprocessor', true ); 
  1043. $selected_preprocessor = isset( $preprocessors[$selected_preprocessor_key] ) ? $preprocessors[$selected_preprocessor_key] : null; 
  1044.  
  1045. ?> 
  1046. <div class="misc-pub-section"> 
  1047. <label><?php esc_html_e( 'Preprocessor:', 'jetpack' ); ?></label> 
  1048. <span id="preprocessor-display"><?php echo esc_html( $selected_preprocessor ? $selected_preprocessor['name'] : __( 'None', 'jetpack' ) ); ?></span> 
  1049. <a class="edit-preprocessor hide-if-no-js" href="#preprocessor"><?php echo esc_html_e( 'Edit', 'jetpack' ); ?></a> 
  1050. <div id="preprocessor-select" class="hide-if-js"> 
  1051. <input type="hidden" name="custom_css_preprocessor" id="custom_css_preprocessor" value="<?php echo esc_attr( $selected_preprocessor_key ); ?>" /> 
  1052. <select id="preprocessor_choices"> 
  1053. <option value=""><?php esc_html_e( 'None', 'jetpack' ); ?></option> 
  1054. <?php 
  1055.  
  1056. foreach ( $preprocessors as $preprocessor_key => $preprocessor ) { 
  1057. ?> 
  1058. <option value="<?php echo esc_attr( $preprocessor_key ); ?>" <?php selected( $selected_preprocessor_key, $preprocessor_key ); ?>><?php echo esc_html( $preprocessor['name'] ); ?></option> 
  1059. <?php 
  1060.  
  1061. ?> 
  1062. </select> 
  1063. <a class="save-preprocessor hide-if-no-js button" href="#preprocessor"><?php esc_html_e( 'OK', 'jetpack' ); ?></a> 
  1064. <a class="cancel-preprocessor hide-if-no-js" href="#preprocessor"><?php esc_html_e( 'Cancel', 'jetpack' ); ?></a> 
  1065. </div> 
  1066. </div> 
  1067. <?php 
  1068.  
  1069. $safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  1070.  
  1071. $add_css = ( get_post_meta( $safecss_post['ID'], 'custom_css_add', true ) != 'no' ); 
  1072.  
  1073. ?> 
  1074. <div class="misc-pub-section"> 
  1075. <label><?php esc_html_e( 'Mode:', 'jetpack' ); ?></label> 
  1076. <span id="css-mode-display"><?php echo esc_html( $add_css ? __( 'Add-on', 'jetpack' ) : __( 'Replacement', 'jetpack' ) ); ?></span> 
  1077. <a class="edit-css-mode hide-if-no-js" href="#css-mode"><?php echo esc_html_e( 'Edit', 'jetpack' ); ?></a> 
  1078. <div id="css-mode-select" class="hide-if-js"> 
  1079. <input type="hidden" name="add_to_existing" id="add_to_existing" value="<?php echo $add_css ? 'true' : 'false'; ?>" /> 
  1080. <p> 
  1081. <label> 
  1082. <input type="radio" name="add_to_existing_display" value="true" <?php checked( $add_css ); ?>/> 
  1083. <?php _e( 'Add-on CSS <b>(Recommended)</b>', 'jetpack' ); ?> 
  1084. </label> 
  1085. <br /> 
  1086. <label> 
  1087. <input type="radio" name="add_to_existing_display" value="false" <?php checked( ! $add_css ); ?>/> 
  1088. <?php printf( 
  1089. __( 'Replace <a href="%s">theme\'s CSS</a> <b>(Advanced)</b>', 'jetpack' ),  
  1090. /** 
  1091. * Filter the theme's stylesheet URL. 
  1092. * 
  1093. * @module custom-css 
  1094. * 
  1095. * @since 1.7.0 
  1096. * 
  1097. * @param string $url Active theme's stylesheet URL. Default to get_stylesheet_uri(). 
  1098. */ 
  1099. apply_filters( 'safecss_theme_stylesheet_url', get_stylesheet_uri() ) 
  1100. ); ?> 
  1101. </label> 
  1102. </p> 
  1103. <a class="save-css-mode hide-if-no-js button" href="#css-mode"><?php esc_html_e( 'OK', 'jetpack' ); ?></a> 
  1104. <a class="cancel-css-mode hide-if-no-js" href="#css-mode"><?php esc_html_e( 'Cancel', 'jetpack' ); ?></a> 
  1105. </div> 
  1106. </div> 
  1107. <?php 
  1108.  
  1109. /** 
  1110. * Allows addition of elements to the submit box for custom css on the wp-admin side. 
  1111. * 
  1112. * @module custom-css 
  1113. * 
  1114. * @since 2.0.3 
  1115. */ 
  1116. do_action( 'custom_css_submitbox_misc_actions' ); 
  1117.  
  1118. ?> 
  1119. </div> 
  1120. </div> 
  1121. <div id="major-publishing-actions"> 
  1122. <input type="button" class="button" id="preview" name="preview" value="<?php esc_attr_e( 'Preview', 'jetpack' ) ?>" /> 
  1123. <div id="publishing-action"> 
  1124. <input type="submit" class="button-primary" id="save" name="save" value="<?php ( Jetpack_Custom_CSS::is_freetrial() ) ? esc_attr_e( 'Save & Buy Upgrade', 'jetpack' ) : esc_attr_e( 'Save Stylesheet', 'jetpack' ); ?>" /> 
  1125. </div> 
  1126. </div> 
  1127. <?php 
  1128.  
  1129. /** 
  1130. * Render metabox listing CSS revisions and the themes that correspond to the revisions. 
  1131. * Called by safecss_admin 
  1132. * 
  1133. * @global $post 
  1134. * @param array $safecss_post 
  1135. * @uses wp_revisions_to_keep 
  1136. * @uses WP_Query 
  1137. * @uses wp_post_revision_title 
  1138. * @uses esc_html 
  1139. * @uses add_query_arg 
  1140. * @uses menu_page_url 
  1141. * @uses wp_reset_query 
  1142. * @return string 
  1143. */ 
  1144. static function revisions_meta_box( $safecss_post ) { 
  1145.  
  1146. $show_all_revisions = isset( $_GET['show_all_rev'] ); 
  1147.  
  1148. if ( function_exists( 'wp_revisions_to_keep' ) ) { 
  1149. $max_revisions = wp_revisions_to_keep( (object) $safecss_post ); 
  1150. } else { 
  1151. $max_revisions = defined( 'WP_POST_REVISIONS' ) && is_numeric( WP_POST_REVISIONS ) ? (int) WP_POST_REVISIONS : 25; 
  1152.  
  1153. $posts_per_page = $show_all_revisions ? $max_revisions : 6; 
  1154.  
  1155. $revisions = new WP_Query( array( 
  1156. 'posts_per_page' => $posts_per_page,  
  1157. 'post_type' => 'revision',  
  1158. 'post_status' => 'inherit',  
  1159. 'post_parent' => $safecss_post['ID'],  
  1160. 'orderby' => 'date',  
  1161. 'order' => 'DESC' 
  1162. ) ); 
  1163.  
  1164. if ( $revisions->have_posts() ) { ?> 
  1165. <ul class="post-revisions"><?php 
  1166.  
  1167. global $post; 
  1168.  
  1169. while ( $revisions->have_posts() ) : 
  1170. $revisions->the_post(); 
  1171.  
  1172. ?><li> 
  1173. <?php 
  1174. echo wp_post_revision_title( $post ); 
  1175.  
  1176. if ( ! empty( $post->post_excerpt ) ) 
  1177. echo ' (' . esc_html( $post->post_excerpt ) . ')'; 
  1178. ?> 
  1179. </li><?php 
  1180.  
  1181. endwhile; 
  1182.  
  1183. ?></ul><?php 
  1184.  
  1185. if ( $revisions->found_posts > 6 && !$show_all_revisions ) { 
  1186. ?> 
  1187. <br> 
  1188. <a href="<?php echo add_query_arg( 'show_all_rev', 'true', menu_page_url( 'editcss', false ) ); ?>"><?php esc_html_e( 'Show all', 'jetpack' ); ?></a> 
  1189. <?php 
  1190.  
  1191. wp_reset_query(); 
  1192.  
  1193. /** 
  1194. * Hook in init at priority 11 to disable custom CSS. 
  1195. */ 
  1196. static function disable() { 
  1197. remove_action( 'wp_head', array( 'Jetpack_Custom_CSS', 'link_tag' ), 101 ); 
  1198. remove_filter( 'stylesheet_uri', array( 'Jetpack_Custom_CSS', 'style_filter' ) ); 
  1199.  
  1200. /** 
  1201. * Reset all aspects of Custom CSS on a theme switch so that changing 
  1202. * themes is a sure-fire way to get a clean start. 
  1203. */ 
  1204. static function reset() { 
  1205. $safecss_post_id = Jetpack_Custom_CSS::save_revision( '' ); 
  1206. $safecss_revision = Jetpack_Custom_CSS::get_current_revision(); 
  1207.  
  1208. update_option( 'safecss_rev', intval( get_option( 'safecss_rev' ) ) + 1 ); 
  1209.  
  1210. update_post_meta( $safecss_post_id, 'custom_css_add', 'yes' ); 
  1211. update_post_meta( $safecss_post_id, 'content_width', false ); 
  1212. update_post_meta( $safecss_post_id, 'custom_css_preprocessor', '' ); 
  1213.  
  1214. delete_option( 'safecss_add' ); 
  1215. delete_option( 'safecss_content_width' ); 
  1216.  
  1217. update_metadata( 'post', $safecss_revision['ID'], 'custom_css_add', 'yes' ); 
  1218. update_metadata( 'post', $safecss_revision['ID'], 'content_width', false ); 
  1219. update_metadata( 'post', $safecss_revision['ID'], 'custom_css_preprocessor', '' ); 
  1220.  
  1221. delete_option( 'safecss_preview_add' ); 
  1222.  
  1223. static function is_customizer_preview() { 
  1224. if ( isset ( $GLOBALS['wp_customize'] ) ) 
  1225. return ! $GLOBALS['wp_customize']->is_theme_active(); 
  1226.  
  1227. return false; 
  1228.  
  1229. static function minify( $css, $preprocessor = '' ) { 
  1230. if ( ! $css ) 
  1231. return ''; 
  1232.  
  1233. if ( $preprocessor ) { 
  1234. /** This filter is documented in modules/custom-css/custom-css.php */ 
  1235. $preprocessors = apply_filters( 'jetpack_custom_css_preprocessors', array() ); 
  1236.  
  1237. if ( isset( $preprocessors[$preprocessor] ) ) { 
  1238. $css = call_user_func( $preprocessors[$preprocessor]['callback'], $css ); 
  1239.  
  1240. safecss_class(); 
  1241. $csstidy = new csstidy(); 
  1242. $csstidy->optimise = new safecss( $csstidy ); 
  1243.  
  1244. $csstidy->set_cfg( 'remove_bslash', false ); 
  1245. $csstidy->set_cfg( 'compress_colors', true ); 
  1246. $csstidy->set_cfg( 'compress_font-weight', true ); 
  1247. $csstidy->set_cfg( 'remove_last_;', true ); 
  1248. $csstidy->set_cfg( 'case_properties', true ); 
  1249. $csstidy->set_cfg( 'discard_invalid_properties', true ); 
  1250. $csstidy->set_cfg( 'css_level', 'CSS3.0' ); 
  1251. $csstidy->set_cfg( 'template', 'highest'); 
  1252. $csstidy->parse( $css ); 
  1253.  
  1254. return $csstidy->print->plain(); 
  1255.  
  1256. /** 
  1257. * When restoring a SafeCSS post revision, also copy over the 
  1258. * content_width and custom_css_add post metadata. 
  1259. */ 
  1260. static function restore_revision( $_post_id, $_revision_id ) { 
  1261. $_post = get_post( $_post_id ); 
  1262.  
  1263. if ( 'safecss' != $_post->post_type ) 
  1264. return; 
  1265.  
  1266. $safecss_revision = Jetpack_Custom_CSS::get_current_revision(); 
  1267.  
  1268. $content_width = get_post_meta( $_revision_id, 'content_width', true ); 
  1269. $custom_css_add = get_post_meta( $_revision_id, 'custom_css_add', true ); 
  1270. $preprocessor = get_post_meta( $_revision_id, 'custom_css_preprocessor', true ); 
  1271.  
  1272. update_metadata( 'post', $safecss_revision['ID'], 'content_width', $content_width ); 
  1273. update_metadata( 'post', $safecss_revision['ID'], 'custom_css_add', $custom_css_add ); 
  1274. update_metadata( 'post', $safecss_revision['ID'], 'custom_css_preprocessor', $preprocessor ); 
  1275.  
  1276. delete_option( 'safecss_add' ); 
  1277. delete_option( 'safecss_content_width' ); 
  1278.  
  1279. update_post_meta( $_post->ID, 'content_width', $content_width ); 
  1280. update_post_meta( $_post->ID, 'custom_css_add', $custom_css_add ); 
  1281. update_post_meta( $_post->ID, 'custom_css_preprocessor', $preprocessor ); 
  1282.  
  1283. delete_option( 'safecss_preview_add' ); 
  1284.  
  1285. /** 
  1286. * Migration routine for moving safecss from wp_options to wp_posts to support revisions 
  1287. * 
  1288. * @return void 
  1289. */ 
  1290. static function upgrade() { 
  1291. $css = get_option( 'safecss' ); 
  1292.  
  1293. if ( get_option( 'safecss_revision_migrated' ) ) { 
  1294. return false; 
  1295.  
  1296. // Check if CSS is stored in wp_options 
  1297. if ( $css ) { 
  1298. // Remove the async actions from publish_post 
  1299. remove_action( 'publish_post', 'queue_publish_post' ); 
  1300.  
  1301. $post = array(); 
  1302. $post['post_content'] = $css; 
  1303. $post['post_title'] = 'safecss'; 
  1304. $post['post_status'] = 'publish'; 
  1305. $post['post_type'] = 'safecss'; 
  1306.  
  1307. // Insert the CSS into wp_posts 
  1308. $post_id = wp_insert_post( $post ); 
  1309. // Check for errors 
  1310. if ( !$post_id or is_wp_error( $post_id ) ) 
  1311. die( $post_id->get_error_message() ); 
  1312.  
  1313. // Delete safecss option 
  1314. delete_option( 'safecss' ); 
  1315.  
  1316. unset( $css ); 
  1317.  
  1318. // Check if we have already done this 
  1319. if ( !get_option( 'safecss_revision_migrated' ) ) { 
  1320. define( 'DOING_MIGRATE', true ); 
  1321.  
  1322. // Get hashes of safecss post and current revision 
  1323. $safecss_post = Jetpack_Custom_CSS::get_post(); 
  1324.  
  1325. if ( empty( $safecss_post ) ) 
  1326. return; 
  1327.  
  1328. $safecss_post_hash = md5( $safecss_post['post_content'] ); 
  1329. $current_revision = Jetpack_Custom_CSS::get_current_revision(); 
  1330.  
  1331. if ( null == $current_revision ) 
  1332. return; 
  1333.  
  1334. $current_revision_hash = md5( $current_revision['post_content'] ); 
  1335.  
  1336. // If hashes are not equal, set safecss post with content from current revision 
  1337. if ( $safecss_post_hash !== $current_revision_hash ) { 
  1338. Jetpack_Custom_CSS::save_revision( $current_revision['post_content'] ); 
  1339. // Reset post_content to display the migrated revsion 
  1340. $safecss_post['post_content'] = $current_revision['post_content']; 
  1341.  
  1342. // Set option so that we dont keep doing this 
  1343. update_option( 'safecss_revision_migrated', time() ); 
  1344.  
  1345. $newest_safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  1346.  
  1347. if ( $newest_safecss_post ) { 
  1348. if ( get_option( 'safecss_content_width' ) ) { 
  1349. // Add the meta to the post and the latest revision. 
  1350. update_post_meta( $newest_safecss_post['ID'], 'content_width', get_option( 'safecss_content_width' ) ); 
  1351. update_metadata( 'post', $newest_safecss_post['ID'], 'content_width', get_option( 'safecss_content_width' ) ); 
  1352.  
  1353. delete_option( 'safecss_content_width' ); 
  1354.  
  1355. if ( get_option( 'safecss_add' ) ) { 
  1356. update_post_meta( $newest_safecss_post['ID'], 'custom_css_add', get_option( 'safecss_add' ) ); 
  1357. update_metadata( 'post', $newest_safecss_post['ID'], 'custom_css_add', get_option( 'safecss_add' ) ); 
  1358.  
  1359. delete_option( 'safecss_add' ); 
  1360.  
  1361. static function revision_redirect( $redirect ) { 
  1362. global $post; 
  1363.  
  1364. if ( 'safecss' == $post->post_type ) { 
  1365. if ( strstr( $redirect, 'action=edit' ) ) { 
  1366. return 'themes.php?page=editcss'; 
  1367.  
  1368. if ( 'edit.php' == $redirect ) { 
  1369. return ''; 
  1370.  
  1371. return $redirect; 
  1372.  
  1373. static function revision_post_link( $post_link, $post_id, $context ) { 
  1374. if ( !$post_id = (int) $post_id ) { 
  1375. return $post_link; 
  1376.  
  1377. if ( !$post = get_post( $post_id ) ) { 
  1378. return $post_link; 
  1379.  
  1380. if ( 'safecss' != $post->post_type ) { 
  1381. return $post_link; 
  1382.  
  1383. $post_link = admin_url( 'themes.php?page=editcss' ); 
  1384.  
  1385. if ( 'display' == $context ) { 
  1386. return esc_url( $post_link ); 
  1387.  
  1388. return esc_url_raw( $post_link ); 
  1389.  
  1390. /** 
  1391. * When on the edit screen, make sure the custom content width 
  1392. * setting is applied to the large image size. 
  1393. */ 
  1394. static function editor_max_image_size( $dims, $size = 'medium', $context = null ) { 
  1395. list( $width, $height ) = $dims; 
  1396.  
  1397. if ( 'large' == $size && 'edit' == $context ) 
  1398. $width = Jetpack::get_content_width(); 
  1399.  
  1400. return array( $width, $height ); 
  1401.  
  1402. /** 
  1403. * Override the content_width with a custom value if one is set. 
  1404. */ 
  1405. static function jetpack_content_width( $content_width ) { 
  1406. $custom_content_width = 0; 
  1407.  
  1408. if ( Jetpack_Custom_CSS::is_preview() ) { 
  1409. $safecss_post = Jetpack_Custom_CSS::get_current_revision(); 
  1410. $custom_content_width = intval( get_post_meta( $safecss_post['ID'], 'content_width', true ) ); 
  1411. } else if ( ! Jetpack_Custom_CSS::is_freetrial() ) { 
  1412. $custom_css_post_id = Jetpack_Custom_CSS::post_id(); 
  1413. if ( $custom_css_post_id ) 
  1414. $custom_content_width = intval( get_post_meta( $custom_css_post_id, 'content_width', true ) ); 
  1415.  
  1416. if ( $custom_content_width > 0 ) 
  1417. $content_width = $custom_content_width; 
  1418.  
  1419. return $content_width; 
  1420.  
  1421. class Jetpack_Safe_CSS { 
  1422. static function filter_attr( $css, $element = 'div' ) { 
  1423. safecss_class(); 
  1424.  
  1425. $css = $element . ' {' . $css . '}'; 
  1426.  
  1427. $csstidy = new csstidy(); 
  1428. $csstidy->optimise = new safecss( $csstidy ); 
  1429. $csstidy->set_cfg( 'remove_bslash', false ); 
  1430. $csstidy->set_cfg( 'compress_colors', false ); 
  1431. $csstidy->set_cfg( 'compress_font-weight', false ); 
  1432. $csstidy->set_cfg( 'discard_invalid_properties', true ); 
  1433. $csstidy->set_cfg( 'merge_selectors', false ); 
  1434. $csstidy->set_cfg( 'remove_last_;', false ); 
  1435. $csstidy->set_cfg( 'css_level', 'CSS3.0' ); 
  1436.  
  1437. $css = preg_replace( '/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $css ); 
  1438. $css = wp_kses_split( $css, array(), array() ); 
  1439. $csstidy->parse( $css ); 
  1440.  
  1441. $css = $csstidy->print->plain(); 
  1442.  
  1443. $css = str_replace( array( "\n", "\r", "\t" ), '', $css ); 
  1444.  
  1445. preg_match( "/^{$element}\s*{(.*)}\s*$/", $css, $matches ); 
  1446.  
  1447. if ( empty( $matches[1] ) ) 
  1448. return ''; 
  1449.  
  1450. return $matches[1]; 
  1451.  
  1452. function migrate() { 
  1453. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::upgrade()' ); 
  1454.  
  1455. return Jetpack_Custom_CSS::upgrade(); 
  1456.  
  1457. function safecss_revision_redirect( $redirect ) { 
  1458. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::revision_redirect()' ); 
  1459.  
  1460. return Jetpack_Custom_CSS::revision_redirect( $redirect ); 
  1461.  
  1462. function safecss_revision_post_link( $post_link, $post_id, $context ) { 
  1463. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::revision_post_link()' ); 
  1464.  
  1465. return Jetpack_Custom_CSS::revision_post_link( $post_link, $post_id, $context ); 
  1466.  
  1467. function get_safecss_post() { 
  1468. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::get_post()' ); 
  1469.  
  1470. return Jetpack_Custom_CSS::get_post(); 
  1471.  
  1472. function custom_css_post_id() { 
  1473. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::post_id()' ); 
  1474.  
  1475. return Jetpack_Custom_CSS::post_id(); 
  1476.  
  1477. function get_current_revision() { 
  1478. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::get_current_revision()' ); 
  1479.  
  1480. return Jetpack_Custom_CSS::get_current_revision(); 
  1481.  
  1482. function save_revision( $css, $is_preview = false, $preprocessor = '' ) { 
  1483. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::save_revision()' ); 
  1484.  
  1485. return Jetpack_Custom_CSS::save_revision( $css, $is_preview, $preprocessor ); 
  1486.  
  1487. function safecss_skip_stylesheet() { 
  1488. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::skip_stylesheet()' ); 
  1489.  
  1490. return Jetpack_Custom_CSS::skip_stylesheet(); 
  1491.  
  1492. function safecss_init() { 
  1493. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::init()' ); 
  1494.  
  1495. return Jetpack_Custom_CSS::init(); 
  1496.  
  1497. function safecss_is_preview() { 
  1498. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::is_preview()' ); 
  1499.  
  1500. return Jetpack_Custom_CSS::is_preview(); 
  1501.  
  1502. function safecss_is_freetrial() { 
  1503. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::is_freetrial()' ); 
  1504.  
  1505. return Jetpack_Custom_CSS::is_freetrial(); 
  1506.  
  1507. function safecss( $compressed = false ) { 
  1508. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::get_css()' ); 
  1509.  
  1510. return Jetpack_Custom_CSS::get_css( $compressed ); 
  1511.  
  1512. function safecss_print() { 
  1513. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::print_css()' ); 
  1514.  
  1515. return Jetpack_Custom_CSS::print_css(); 
  1516.  
  1517. function safecss_style() { 
  1518. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::link_tag()' ); 
  1519.  
  1520. return Jetpack_Custom_CSS::link_tag(); 
  1521.  
  1522. function safecss_style_filter( $current ) { 
  1523. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::style_filter()' ); 
  1524.  
  1525. return Jetpack_Custom_CSS::style_filter( $current ); 
  1526.  
  1527. function safecss_buffer( $html ) { 
  1528. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::buffer()' ); 
  1529.  
  1530. return Jetpack_Custom_CSS::buffer( $html ); 
  1531.  
  1532. function safecss_preview_links( $matches ) { 
  1533. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::preview_links()' ); 
  1534.  
  1535. return Jetpack_Custom_CSS::preview_links( $matches ); 
  1536.  
  1537. function safecss_preview_flag() { 
  1538. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::preview_flag()' ); 
  1539.  
  1540. return Jetpack_Custom_CSS::preview_flag(); 
  1541.  
  1542. function safecss_menu() { 
  1543. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::menu()' ); 
  1544.  
  1545. return Jetpack_Custom_CSS::menu(); 
  1546.  
  1547. function update_title() { 
  1548. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::update_title()' ); 
  1549.  
  1550. return Jetpack_Custom_CSS::update_title(); 
  1551.  
  1552. function safecss_prettify_post_revisions() { 
  1553. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::prettify_post_revisions()' ); 
  1554.  
  1555. return Jetpack_Custom_CSS::prettify_post_revisions(); 
  1556.  
  1557. function safecss_remove_title_excerpt_from_revisions() { 
  1558. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::remove_title_excerpt_from_revisions()' ); 
  1559.  
  1560. return Jetpack_Custom_CSS::remove_title_excerpt_from_revisions(); 
  1561.  
  1562. function safecss_post_title( $title, $post_id ) { 
  1563. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::post_title()' ); 
  1564.  
  1565. return Jetpack_Custom_CSS::post_title( $title, $post_id ); 
  1566.  
  1567. function safe_css_enqueue_scripts() { 
  1568. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::enqueue_scripts()' ); 
  1569.  
  1570. return Jetpack_Custom_CSS::enqueue_scripts(); 
  1571.  
  1572. function safecss_admin_head() { 
  1573. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::admin_head()' ); 
  1574.  
  1575. return Jetpack_Custom_CSS::admin_head(); 
  1576.  
  1577. function safecss_saved() { 
  1578. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::saved_message()' ); 
  1579.  
  1580. return Jetpack_Custom_CSS::saved_message(); 
  1581.  
  1582. function safecss_admin() { 
  1583. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::admin()' ); 
  1584.  
  1585. return Jetpack_Custom_CSS::admin(); 
  1586.  
  1587. function custom_css_meta_box() { 
  1588. _deprecated_function( __FUNCTION__, '2.1', 'add_meta_box( $id, $title, $callback, \'editcss\', \'side\' )' ); 
  1589.  
  1590. function custom_css_post_revisions_meta_box( $safecss_post ) { 
  1591. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::revisions_meta_box()' ); 
  1592.  
  1593. return Jetpack_Custom_CSS::revisions_meta_box( $safecss_post ); 
  1594.  
  1595. function disable_safecss_style() { 
  1596. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::disable()' ); 
  1597.  
  1598. return Jetpack_Custom_CSS::disable(); 
  1599.  
  1600. function custom_css_reset() { 
  1601. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::reset()' ); 
  1602.  
  1603. return Jetpack_Custom_CSS::reset(); 
  1604.  
  1605. function custom_css_is_customizer_preview() { 
  1606. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::is_customizer_preview()' ); 
  1607.  
  1608. return Jetpack_Custom_CSS::is_customizer_preview(); 
  1609.  
  1610. function custom_css_minify( $css, $preprocessor = '' ) { 
  1611. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::minify()' ); 
  1612.  
  1613. return Jetpack_Custom_CSS::minify( $css, $preprocessor ); 
  1614.  
  1615. function custom_css_restore_revision( $_post_id, $_revision_id ) { 
  1616. _deprecated_function( __FUNCTION__, '2.1', 'Jetpack_Custom_CSS::restore_revision()' ); 
  1617.  
  1618. return Jetpack_Custom_CSS::restore_revision( $_post_id, $_revision_id ); 
  1619.  
  1620. function safecss_class() { 
  1621. // Wrapped so we don't need the parent class just to load the plugin 
  1622. if ( class_exists('safecss') ) 
  1623. return; 
  1624.  
  1625. require_once( dirname( __FILE__ ) . '/csstidy/class.csstidy.php' ); 
  1626.  
  1627. class safecss extends csstidy_optimise { 
  1628. function __construct( &$css ) { 
  1629. return $this->csstidy_optimise( $css ); 
  1630.  
  1631. function postparse() { 
  1632.  
  1633. /** 
  1634. * Fires after parsing the css. 
  1635. * 
  1636. * @module custom-css 
  1637. * 
  1638. * @since 1.8.0 
  1639. * 
  1640. * @param obj $this CSSTidy object. 
  1641. */ 
  1642. do_action( 'csstidy_optimize_postparse', $this ); 
  1643.  
  1644. return parent::postparse(); 
  1645.  
  1646. function subvalue() { 
  1647.  
  1648. /** 
  1649. * Fires before optimizing the Custom CSS subvalue. 
  1650. * 
  1651. * @module custom-css 
  1652. * 
  1653. * @since 1.8.0 
  1654. * 
  1655. * @param obj $this CSSTidy object. 
  1656. **/ 
  1657. do_action( 'csstidy_optimize_subvalue', $this ); 
  1658.  
  1659. return parent::subvalue(); 
  1660.  
  1661. if ( ! function_exists( 'safecss_filter_attr' ) ) { 
  1662. function safecss_filter_attr( $css, $element = 'div' ) { 
  1663. return Jetpack_Safe_CSS::filter_attr( $css, $element ); 
  1664.  
  1665. add_action( 'init', array( 'Jetpack_Custom_CSS', 'init' ) ); 
  1666.  
  1667. include dirname( __FILE__ ) . '/custom-css/preprocessors.php'; 
.