| @@ -10,22 +10,14 @@ | ||
| 10 | 10 | protected static $instance = null; |
| 11 | 11 | |
| 12 | 12 | protected function __construct() { |
| 13 | 13 | |
| 14 | - add_action( 'customify_create_custom_control', array( $this, 'cle_create_custom_control' ), 10, 1 ); | |
| 15 | - add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_admin_customizer_styles' ), 10 ); | |
| 16 | - $load_location = PixCustomifyPlugin()->get_plugin_setting( 'style_resources_location', 'wp_head' ); | |
| 14 | + add_action( 'customify_create_custom_control', array( $this,'cle_create_custom_control'), 10, 1 ); | |
| 17 | 15 | |
| 18 | - if ( function_exists( 'wp_custom_css_cb' ) ) { | |
| 19 | -// remove_action( 'wp_head', 'wp_custom_css_cb', 101 ); | |
| 20 | -// add_action( $load_location, 'wp_custom_css_cb', 999999999 ); | |
| 21 | - } else { | |
| 22 | - // keep this for wordpress versions lower than 4.7 | |
| 23 | - add_action( $load_location, array( $this, 'output_dynamic_style' ), 99 ); | |
| 24 | - } | |
| 16 | + add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_admin_customizer_styles' ), 10); | |
| 25 | 17 | |
| 26 | - //Check the WordPress version and if there are known problems disable it | |
| 27 | - add_filter( 'customify_css_live_editor_enabled', array( $this, 'disable_if_wp_incompatible' ), 10, 1 ); | |
| 18 | + $load_location = PixCustomifyPlugin::get_plugin_option( 'style_resources_location', 'wp_head' ); | |
| 19 | + add_action( $load_location, array( $this, 'output_dynamic_style' ), 999999999 ); | |
| 28 | 20 | } |
| 29 | 21 | |
| 30 | 22 | /** |
| 31 | 23 | * Return an instance of this class. |
| @@ -34,9 +26,9 @@ | ||
| 34 | 26 | */ |
| 35 | 27 | public static function get_instance() { |
| 36 | 28 | |
| 37 | 29 | // If the single instance hasn't been set, set it now. |
| 38 | - if ( is_null( self::$instance ) ) { | |
| 30 | + if ( null == self::$instance ) { | |
| 39 | 31 | self::$instance = new self; |
| 40 | 32 | } |
| 41 | 33 | |
| 42 | 34 | return self::$instance; |
| @@ -41,94 +33,34 @@ | ||
| 41 | 33 | |
| 42 | 34 | return self::$instance; |
| 43 | 35 | } |
| 44 | 36 | |
| 45 | - function enqueue_admin_customizer_styles() { | |
| 37 | + function enqueue_admin_customizer_styles(){ | |
| 38 | + $dir = plugin_dir_url( __FILE__ ); | |
| 46 | 39 | |
| 47 | - $dir = plugin_dir_url( __FILE__ ); | |
| 48 | 40 | $dir = rtrim( $dir, 'features/' ); |
| 49 | 41 | |
| 50 | - wp_enqueue_script( 'customify-ace-editor', $dir . '/js/ace/ace.js', array( 'jquery' ), false, true ); | |
| 42 | + wp_register_script('customify-ace-editor', $dir . '/js/ace/ace.js', array('jquery'), false, true); | |
| 43 | + wp_enqueue_script('live-css-editor', $dir . '/js/live_css_editor.js', array('customify-ace-editor'), false, true); | |
| 51 | 44 | |
| 52 | - if ( ! apply_filters( 'customify_css_live_editor_enabled', true ) ) { | |
| 53 | - return ; | |
| 54 | - } | |
| 55 | - | |
| 56 | - wp_enqueue_script( 'live-css-editor', $dir . '/js/live_css_editor.js', array( 'customify-ace-editor' ), false, true ); | |
| 57 | 45 | } |
| 58 | 46 | |
| 59 | 47 | function cle_create_custom_control( $wp_customize ) { |
| 60 | - // Allow others to short-circuit us | |
| 61 | - if ( ! apply_filters( 'customify_css_live_editor_enabled', true ) ) { | |
| 62 | 48 | |
| 63 | - // port CSS if | |
| 64 | - if ( function_exists( 'wp_update_custom_css_post' ) ) { | |
| 65 | - // Migrate any existing theme CSS to the core option added in WordPress 4.7. | |
| 66 | - $store_type = PixCustomifyPlugin()->get_plugin_setting( 'values_store_mod', 'option' ); | |
| 67 | - | |
| 68 | - $default_css = __( "/* | |
| 69 | - * Welcome to the Custom CSS Editor | |
| 70 | - * | |
| 71 | - * CSS (Cascading Style Sheets) is a language that helps | |
| 72 | - * the browser render your website. You may remove these | |
| 73 | - * lines and get started with your own customizations. | |
| 74 | - * | |
| 75 | - * The generated code will be placed after the theme | |
| 76 | - * stylesheets, which means that your rules can take | |
| 77 | - * precedence and override the theme CSS rules. Just | |
| 78 | - * write here what you want to change, you don't need | |
| 79 | - * to copy all your theme's stylesheet content. | |
| 80 | - * | |
| 81 | - * Getting started with CSS (tutorial): | |
| 82 | - * http://bit.ly/css-getting-started | |
| 83 | - */ | |
| 84 | - | |
| 85 | -/* An example of a Custom CSS Snippet */ | |
| 86 | -selector { | |
| 87 | - color: green; | |
| 88 | -}", 'customify' ); | |
| 89 | - | |
| 90 | - if ( $store_type === 'option' ) { | |
| 91 | - $CSS = get_option( 'live_css_edit' ); | |
| 92 | - } elseif ( $store_type === 'theme_mod' ) { | |
| 93 | - $CSS = get_theme_mod( 'live_css_edit' ); | |
| 94 | - } | |
| 95 | - | |
| 96 | - if ( ! empty( $CSS ) && $default_css !== $CSS ) { | |
| 97 | - | |
| 98 | - $CSS = str_replace( $default_css, '', $CSS ); | |
| 99 | - | |
| 100 | - $core_css = wp_get_custom_css(); // Preserve any CSS already added to the core option. | |
| 101 | - $return = wp_update_custom_css_post( $core_css . $CSS ); | |
| 102 | - if ( ! is_wp_error( $return ) ) { | |
| 103 | - // Remove the old theme_mod, so that the CSS is stored in only one place moving forward. | |
| 104 | - remove_theme_mod( 'custom_theme_css' ); | |
| 105 | - if ( $store_type === 'option' ) { | |
| 106 | - $CSS = delete_option( 'live_css_edit' ); | |
| 107 | - } elseif ( $store_type === 'theme_mod' ) { | |
| 108 | - $CSS = remove_theme_mod( 'live_css_edit' ); | |
| 109 | - } | |
| 110 | - } | |
| 111 | - } | |
| 112 | - } | |
| 113 | - | |
| 114 | - return; | |
| 115 | - } | |
| 116 | - | |
| 117 | 49 | $wp_customize->add_section( 'live_css_edit_section', array( |
| 118 | 50 | 'priority' => 11, |
| 119 | 51 | 'capability' => 'edit_theme_options', |
| 120 | - 'title' => __( 'CSS Editor', 'customify' ), | |
| 52 | + 'title' => __('CSS Editor', 'customify_txtd'), | |
| 121 | 53 | ) ); |
| 122 | 54 | |
| 123 | - $saving_type = PixCustomifyPlugin()->get_plugin_setting( 'values_store_mod', 'option' ); | |
| 55 | + $saving_type = PixCustomifyPlugin::get_plugin_option( 'values_store_mod', 'option' ); | |
| 124 | 56 | |
| 125 | 57 | $wp_customize->add_setting( 'live_css_edit', array( |
| 126 | - 'type' => $saving_type, | |
| 127 | - 'label' => __( 'CSS Editor', 'customify' ), | |
| 58 | + 'type' => $saving_type, | |
| 59 | + 'label' => __('CSS Editor', 'customify_txtd'), | |
| 128 | 60 | 'capability' => 'edit_theme_options', |
| 129 | - 'transport' => 'postMessage', | |
| 130 | - 'default' => __( "/* | |
| 61 | + 'transport' => 'postMessage', | |
| 62 | + 'default' => __("/* | |
| 131 | 63 | * Welcome to the Custom CSS Editor |
| 132 | 64 | * |
| 133 | 65 | * CSS (Cascading Style Sheets) is a language that helps |
| 134 | 66 | * the browser render your website. You may remove these |
| @@ -146,9 +78,9 @@ | ||
| 146 | 78 | |
| 147 | 79 | /* An example of a Custom CSS Snippet */ |
| 148 | 80 | selector { |
| 149 | 81 | color: green; |
| 150 | -}", 'customify' ) | |
| 82 | +}", 'customify_txtd') | |
| 151 | 83 | ) ); |
| 152 | 84 | |
| 153 | 85 | $this_control = new Pix_Customize_CSS_Editor_Control( |
| 154 | 86 | $wp_customize, |
| @@ -153,9 +85,9 @@ | ||
| 153 | 85 | $this_control = new Pix_Customize_CSS_Editor_Control( |
| 154 | 86 | $wp_customize, |
| 155 | 87 | 'live_css_edit_control', |
| 156 | 88 | array( |
| 157 | - 'label' => __( 'Edit Live Css', 'customify' ), | |
| 89 | + 'label' => __('Edit Live Css', 'customify_txtd'), | |
| 158 | 90 | 'section' => 'live_css_edit_section', |
| 159 | 91 | 'settings' => 'live_css_edit', |
| 160 | 92 | ) |
| 161 | 93 | ); |
| @@ -162,18 +94,13 @@ | ||
| 162 | 94 | $wp_customize->add_control( $this_control ); |
| 163 | 95 | } |
| 164 | 96 | |
| 165 | 97 | function output_dynamic_style() { |
| 166 | - // Allow others to short-circuit us | |
| 167 | - if ( ! apply_filters( 'customify_css_live_editor_enabled', true ) ) { | |
| 168 | - return; | |
| 169 | - } | |
| 170 | - | |
| 171 | - $store_type = PixCustomifyPlugin()->get_plugin_setting( 'values_store_mod', 'option' ); | |
| 98 | + $store_type = PixCustomifyPlugin::get_plugin_option( 'values_store_mod', 'option' ); | |
| 172 | 99 | if ( $store_type === 'option' ) { |
| 173 | 100 | $output = get_option( 'live_css_edit' ); |
| 174 | 101 | } elseif ( $store_type === 'theme_mod' ) { |
| 175 | - $output = get_theme_mod( 'live_css_edit' ); | |
| 102 | + $output = get_theme_mod( 'live_css_edit' ); | |
| 176 | 103 | } |
| 177 | 104 | |
| 178 | 105 | if ( empty( $output ) ) { |
| 179 | 106 | return; |
| @@ -181,22 +108,8 @@ | ||
| 181 | 108 | <style id="customify_css_editor_output"> |
| 182 | 109 | <?php echo $output; ?> |
| 183 | 110 | </style> |
| 184 | 111 | <?php |
| 185 | - } | |
| 186 | - | |
| 187 | - function disable_if_wp_incompatible( $enabled ) { | |
| 188 | - global $wp_version; | |
| 189 | - | |
| 190 | - // WordPress 4.7 introduced a Customizer CSS editor that conflicts with our own | |
| 191 | - // It's best to leave only the one in core | |
| 192 | - // So only load our CSS editor for WP version smaller than 4.7 | |
| 193 | - // We use 4.6.9 to catch the release candidates also | |
| 194 | - if ( version_compare( $wp_version, '4.6.9', '>=' ) ) { | |
| 195 | - return false; | |
| 196 | - } | |
| 197 | - | |
| 198 | - return $enabled; | |
| 199 | 112 | } |
| 200 | 113 | } |
| 201 | 114 | |
| 202 | 115 | $customify_CSS_Editor = Customify_CSS_Live_Editor::get_instance(); |