| @@ -1,5 +1,5 @@ | ||
| 1 | -<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | |
| 1 | +<?php | |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * Module Name: Custom CSS |
| 5 | 5 | * Module Description: Adds options for CSS preprocessor use, disabling the theme's CSS, or custom image width. |
| @@ -11,24 +11,46 @@ | ||
| 11 | 11 | * Feature: Appearance |
| 12 | 12 | * Additional Search Queries: css, customize, custom, style, editor, less, sass, preprocessor, font, mobile, appearance, theme, stylesheet |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -/** | |
| 16 | - * Load custom CSS | |
| 17 | - */ | |
| 18 | 15 | function jetpack_load_custom_css() { |
| 19 | - include_once __DIR__ . '/custom-css/custom-css/preprocessors.php'; | |
| 20 | - include_once __DIR__ . '/custom-css/custom-css.php'; | |
| 16 | + // If WordPress has the core version of Custom CSS, load our new version. | |
| 17 | + // @see https://core.trac.wordpress.org/changeset/38829 | |
| 18 | + if ( function_exists( 'wp_get_custom_css' ) ) { | |
| 19 | + if ( ! function_exists( 'wp_update_custom_css_post' ) ) { | |
| 20 | + wp_die( 'Please run a SVN up to get the latest version of trunk, or update to at least 4.7 RC1' ); | |
| 21 | + } | |
| 22 | + if ( ! Jetpack_Options::get_option( 'custom_css_4.7_migration' ) ) { | |
| 23 | + include_once dirname( __FILE__ ) . '/custom-css/migrate-to-core.php'; | |
| 24 | + } | |
| 25 | + | |
| 26 | + // TODO: DELETE THIS | |
| 27 | + else { | |
| 28 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
| 29 | + function jetpack_custom_css_undo_data_migration_cli() { | |
| 30 | + Jetpack_Options::delete_option( 'custom_css_4.7_migration' ); | |
| 31 | + WP_CLI::success( __( 'Option deleted, re-migrate via `wp jetpack custom-css migrate`.', 'jetpack' ) ); | |
| 32 | + } | |
| 33 | + WP_CLI::add_command( 'jetpack custom-css undo-migrate', 'jetpack_custom_css_undo_data_migration_cli' ); | |
| 34 | + } | |
| 35 | + } | |
| 36 | + // TODO: END DELETE THIS | |
| 37 | + | |
| 38 | + include_once dirname( __FILE__ ) . '/custom-css/custom-css/preprocessors.php'; | |
| 39 | + include_once dirname( __FILE__ ) . '/custom-css/custom-css-4.7.php'; | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + | |
| 43 | + include_once dirname( __FILE__ ) . "/custom-css/custom-css.php"; | |
| 44 | + add_action( 'init', array( 'Jetpack_Custom_CSS', 'init' ) ); | |
| 21 | 45 | } |
| 22 | 46 | |
| 23 | 47 | add_action( 'jetpack_modules_loaded', 'custom_css_loaded' ); |
| 24 | 48 | |
| 25 | -/** | |
| 26 | - * Enable CSS module. | |
| 27 | - */ | |
| 28 | 49 | function custom_css_loaded() { |
| 29 | 50 | Jetpack::enable_module_configurable( __FILE__ ); |
| 30 | 51 | add_filter( 'jetpack_module_configuration_url_custom-css', 'jetpack_custom_css_configuration_url' ); |
| 52 | + | |
| 31 | 53 | } |
| 32 | 54 | |
| 33 | 55 | /** |
| 34 | 56 | * Overrides default configuration url |
| @@ -33,15 +55,14 @@ | ||
| 33 | 55 | /** |
| 34 | 56 | * Overrides default configuration url |
| 35 | 57 | * |
| 36 | 58 | * @uses admin_url |
| 37 | - * | |
| 38 | - * @param string $default_url - the default URL. | |
| 39 | 59 | * @return string module settings URL |
| 40 | 60 | */ |
| 41 | -function jetpack_custom_css_configuration_url( $default_url ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 61 | +function jetpack_custom_css_configuration_url( $default_url ) { | |
| 42 | 62 | return Jetpack_Custom_CSS_Enhancements::customizer_link( |
| 43 | 63 | array( 'return_url' => wp_get_referer() ) |
| 44 | 64 | ); |
| 45 | 65 | } |
| 66 | + | |
| 46 | 67 | |
| 47 | 68 | jetpack_load_custom_css(); |