custom-css.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Module Name: Custom CSS
  4. * Module Description: Tweak your site’s CSS without modifying your theme.
  5. * Sort Order: 2
  6. * First Introduced: 1.7
  7. * Requires Connection: No
  8. * Auto Activate: Yes
  9. * Module Tags: Appearance
  10. * Feature: Appearance
  11. * Additional Search Queries: css, customize, custom, style, editor, less, sass, preprocessor, font, mobile, appearance, theme, stylesheet
  12. */
  13. function jetpack_load_custom_css() {
  14. // If WordPress has the core version of Custom CSS, load our new version.
  15. // @see https://core.trac.wordpress.org/changeset/38829
  16. if ( function_exists( 'wp_get_custom_css' ) ) {
  17. if ( ! function_exists( 'wp_update_custom_css_post' ) ) {
  18. wp_die( 'Please run a SVN up to get the latest version of trunk, or update to at least 4.7 RC1' );
  19. }
  20. if ( ! Jetpack_Options::get_option( 'custom_css_4.7_migration' ) ) {
  21. include_once dirname( __FILE__ ) . '/custom-css/migrate-to-core.php';
  22. }
  23. // TODO: DELETE THIS
  24. else {
  25. if ( defined( 'WP_CLI' ) && WP_CLI ) {
  26. function jetpack_custom_css_undo_data_migration_cli() {
  27. Jetpack_Options::delete_option( 'custom_css_4.7_migration' );
  28. WP_CLI::success( __( 'Option deleted, re-migrate via `wp jetpack custom-css migrate`.', 'jetpack' ) );
  29. }
  30. WP_CLI::add_command( 'jetpack custom-css undo-migrate', 'jetpack_custom_css_undo_data_migration_cli' );
  31. }
  32. }
  33. // TODO: END DELETE THIS
  34. include_once dirname( __FILE__ ) . '/custom-css/custom-css/preprocessors.php';
  35. include_once dirname( __FILE__ ) . '/custom-css/custom-css-4.7.php';
  36. return;
  37. }
  38. include_once dirname( __FILE__ ) . "/custom-css/custom-css.php";
  39. add_action( 'init', array( 'Jetpack_Custom_CSS', 'init' ) );
  40. }
  41. add_action( 'jetpack_modules_loaded', 'custom_css_loaded' );
  42. function custom_css_loaded() {
  43. Jetpack::enable_module_configurable( __FILE__ );
  44. Jetpack::module_configuration_load( __FILE__, 'custom_css_configuration_load' );
  45. }
  46. function custom_css_configuration_load() {
  47. // Redirect to Core's CSS editor in the customizer if the feature is available.
  48. if ( function_exists( 'wp_get_custom_css' ) ) {
  49. $configuration_link = Jetpack_Custom_CSS_Enhancements::customizer_link(
  50. array(
  51. 'return_url' => wp_get_referer(),
  52. )
  53. );
  54. } else {
  55. $configuration_link = admin_url( 'themes.php?page=editcss#settingsdiv' );
  56. }
  57. wp_safe_redirect( $configuration_link );
  58. exit;
  59. }
  60. jetpack_load_custom_css();