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