Child Theme Configurator - Version 2.0.5

Version Description

  • Updated child theme preview class to use is_theme_active and other methods to eliminate conflicts with Jetpack and any other plugin that references the customize manager.
Download this release

Release Info

Developer lilaeamedia
Plugin Icon 128x128 Child Theme Configurator
Version 2.0.5
Comparing to
See all releases

Code changes from version 2.0.4 to 2.0.5

child-theme-configurator.php CHANGED
@@ -6,7 +6,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
6
  Plugin Name: Child Theme Configurator
7
  Plugin URI: http://www.childthemeconfigurator.com
8
  Description: When using the Customizer is not enough - Create child themes and customize styles, templates, functions and more.
9
- Version: 2.0.4
10
  Author: Lilaea Media
11
  Author URI: http://www.lilaeamedia.com
12
  Text Domain: child-theme-configurator
@@ -27,10 +27,9 @@ if ( !defined( 'ABSPATH' ) ) exit;
27
  include_once( dirname( __FILE__ ) . '/includes/class-ctc.php' );
28
 
29
  if ( isset( $_GET['preview_ctc'] ) ):
30
- include_once( dirname( __FILE__ ) . '/includes/class-ctc-preview.php' );
31
  // replace core preview function with CTCP function for quick preview
32
  remove_action( 'setup_theme', 'preview_theme' );
33
- add_action( 'setup_theme', 'ChildThemeConfiguratorPreview::preview_theme' );
34
  endif;
35
 
36
  add_filter( 'style_loader_src', 'chld_thm_cfg_version', 10, 2 );
6
  Plugin Name: Child Theme Configurator
7
  Plugin URI: http://www.childthemeconfigurator.com
8
  Description: When using the Customizer is not enough - Create child themes and customize styles, templates, functions and more.
9
+ Version: 2.0.5
10
  Author: Lilaea Media
11
  Author URI: http://www.lilaeamedia.com
12
  Text Domain: child-theme-configurator
27
  include_once( dirname( __FILE__ ) . '/includes/class-ctc.php' );
28
 
29
  if ( isset( $_GET['preview_ctc'] ) ):
 
30
  // replace core preview function with CTCP function for quick preview
31
  remove_action( 'setup_theme', 'preview_theme' );
32
+ include_once( dirname( __FILE__ ) . '/includes/class-ctc-preview.php' );
33
  endif;
34
 
35
  add_filter( 'style_loader_src', 'chld_thm_cfg_version', 10, 2 );
includes/class-ctc-admin.php CHANGED
@@ -6,7 +6,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
6
  Class: Child_Theme_Configurator
7
  Plugin URI: http://www.childthemeconfigurator.com/
8
  Description: Main Controller Class
9
- Version: 2.0.4
10
  Author: Lilaea Media
11
  Author URI: http://www.lilaeamedia.com/
12
  Text Domain: child-theme-configurator
6
  Class: Child_Theme_Configurator
7
  Plugin URI: http://www.childthemeconfigurator.com/
8
  Description: Main Controller Class
9
+ Version: 2.0.5
10
  Author: Lilaea Media
11
  Author URI: http://www.lilaeamedia.com/
12
  Text Domain: child-theme-configurator
includes/class-ctc-css.php CHANGED
@@ -6,7 +6,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
6
  Class: ChildThemeConfiguratorCSS
7
  Plugin URI: http://www.childthemeconfigurator.com/
8
  Description: Handles all CSS input, output, parsing, normalization and storage
9
- Version: 2.0.4
10
  Author: Lilaea Media
11
  Author URI: http://www.lilaeamedia.com/
12
  Text Domain: chld_thm_cfg
6
  Class: ChildThemeConfiguratorCSS
7
  Plugin URI: http://www.childthemeconfigurator.com/
8
  Description: Handles all CSS input, output, parsing, normalization and storage
9
+ Version: 2.0.5
10
  Author: Lilaea Media
11
  Author URI: http://www.lilaeamedia.com/
12
  Text Domain: chld_thm_cfg
includes/class-ctc-preview.php CHANGED
@@ -5,27 +5,24 @@ if ( !defined( 'ABSPATH' ) ) exit;
5
  error_reporting( E_ALL );
6
  ini_set( 'display_errors', 1 );
7
 
8
- class ChildThemeConfiguratorPreview {
9
- /**
10
- * Replaces core function to start preview theme output buffer.
11
- */
12
- static function preview_theme() {
13
- // are we previewing?
14
- if ( ! isset( $_GET[ 'template' ] ) || !wp_verify_nonce( $_GET['preview_ctc'] ) )
15
- return;
16
- // can user preview?
17
- if ( !current_user_can( 'switch_themes' ) )
18
- return;
19
- // hide admin bar in preview
20
- if ( isset( $_GET[ 'preview_iframe' ] ) )
21
- show_admin_bar( false );
22
- // sanitize template param
23
- $_GET[ 'template' ] = preg_replace( '|[^a-z0-9_./-]|i', '', $_GET[ 'template' ] );
24
- // check for manipulations
25
- if ( validate_file( $_GET[ 'template' ] ) )
26
- return;
27
-
28
- // Do not spawn cron (especially the alternate cron) while running the Customizer.
29
  remove_action( 'init', 'wp_cron' );
30
 
31
  // Do not run update checks when rendering the controls.
@@ -33,69 +30,51 @@ ini_set( 'display_errors', 1 );
33
  remove_action( 'admin_init', '_maybe_update_plugins' );
34
  remove_action( 'admin_init', '_maybe_update_themes' );
35
 
36
- // replace future get_template calls with preview template
37
- add_filter( 'template', 'ChildThemeConfiguratorPreview::preview_theme_template_filter' );
38
-
39
- if ( isset( $_GET[ 'stylesheet' ] ) ):
40
- // sanitize stylesheet param
41
- $_GET['stylesheet'] = preg_replace( '|[^a-z0-9_./-]|i', '', $_GET['stylesheet'] );
42
- // check for manipulations
43
- if ( validate_file( $_GET['stylesheet'] ) )
44
- return;
45
- // replace future get_stylesheet calls with preview stylesheet
46
- add_filter( 'stylesheet', 'ChildThemeConfiguratorPreview::preview_theme_stylesheet_filter' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  endif;
48
- // swap out theme mods with preview theme mods
49
- add_filter( 'pre_option_theme_mods_' . get_option( 'stylesheet' ),
50
- 'ChildThemeConfiguratorPreview::preview_mods' );
51
-
52
- // let themes and plugins do their thing
53
- add_action( 'wp_loaded', 'ChildThemeConfiguratorPreview::customize_preview_init' );
54
-
55
- //add_filter( 'woocommerce_unforce_ssl_checkout', 'ChildThemeConfiguratorPreview::woocommerce_unforce_ssl_checkout', 1000 );
56
- // Run wp_redirect_status late to make sure we override the status last.
57
- add_action( 'wp_redirect_status', 'ChildThemeConfiguratorPreview::redirect_status', 1000 );
58
-
59
  // impossibly high priority to test for stylesheets loaded after wp_head()
60
- add_action( 'wp_print_styles', 'ChildThemeConfiguratorPreview::test_css', 999999 );
61
  // pass the wp_styles queue back to use for stylesheet handle verification
62
- add_action( 'wp_footer', 'ChildThemeConfiguratorPreview::parse_stylesheet' );
63
-
64
- send_origin_headers();
 
65
  }
66
 
67
  /**
68
  * Retrieves child theme mods for preview
69
  */
70
- static function preview_mods() {
71
- if ( ! isset( $_GET[ 'stylesheet' ] ) || get_option( 'stylesheet' ) == $_GET[ 'stylesheet' ] ) return false;
72
- return get_option( 'theme_mods_' . preg_replace('|[^a-z0-9_./-]|i', '', $_GET['stylesheet']) );
73
- }
74
-
75
- /**
76
- * Function to modify the current template when previewing a theme
77
- *
78
- * @return string
79
- */
80
- static function preview_theme_template_filter() {
81
- return ( isset($_GET['template']) && current_user_can( 'switch_themes' ) ) ? $_GET['template'] : '';
82
- }
83
-
84
- /**
85
- * Function to modify the current stylesheet when previewing a theme
86
- *
87
- * @return string
88
- */
89
- static function preview_theme_stylesheet_filter() {
90
- return ( isset( $_GET['stylesheet'] ) && current_user_can( 'switch_themes' ) ) ? $_GET['stylesheet'] : '';
91
- }
92
-
93
- // enqueue dummy stylesheet with extremely high priority to test wp_head()
94
- static function test_css() {
95
- wp_enqueue_style( 'ctc-test', get_stylesheet_directory_uri() . '/ctc-test.css' );
96
  }
97
 
98
- static function parse_stylesheet() {
99
  echo '<script>/*<![CDATA[' . LF;
100
  global $wp_styles, $wp_filter;
101
  $queue = implode( "\n", $wp_styles->queue );
@@ -155,29 +134,74 @@ ini_set( 'display_errors', 1 );
155
  echo 'END CTC IRREGULAR' . LF;
156
  echo '*/]]></script>' . LF;
157
  }
158
- /**
159
- * Prevents AJAX requests from following redirects when previewing a theme
160
- * by issuing a 200 response instead of a 30x.
161
- */
162
- static function redirect_status( $status ) {
163
- return 200;
164
  }
165
 
166
- static function woocommerce_unforce_ssl_checkout( $bool ){
167
  return FALSE;
168
  }
169
 
170
- static function customize_preview_init() {
171
- global $wp_customize;
172
- $wp_customize = new WP_Customize_Manager();
173
- do_action( 'customize_preview_init', $wp_customize );
174
- }
175
- }
176
-
177
- if ( !class_exists( 'WP_Customize_Manager' ) ) {
178
- final class WP_Customize_Manager {
179
- function is_preview() {
180
- return TRUE;
181
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  error_reporting( E_ALL );
6
  ini_set( 'display_errors', 1 );
7
 
8
+ /**
9
+ * Modified lightweight version of WP Customize Manager class.
10
+ * Provides methods required for preview to work without customizer options.
11
+ * This only loads when CTC preview is loaded.
12
+ */
13
+ if ( !class_exists( 'WP_Customize_Manager' ) ):
14
+ final class WP_Customize_Manager {
15
+
16
+ protected $theme;
17
+ protected $original_stylesheet;
18
+
19
+ public function __construct(){
20
+
21
+ add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
22
+ add_action( 'setup_theme', array( $this, 'setup_theme' ) );
23
+ add_action( 'wp_redirect_status', array( $this, 'wp_redirect_status', 1000 ) );
24
+
25
+ // Do not spawn cron (especially the alternate cron) while running the Customizer.
 
 
 
26
  remove_action( 'init', 'wp_cron' );
27
 
28
  // Do not run update checks when rendering the controls.
30
  remove_action( 'admin_init', '_maybe_update_plugins' );
31
  remove_action( 'admin_init', '_maybe_update_themes' );
32
 
33
+ }
34
+
35
+ public function setup_theme() {
36
+ send_origin_headers();
37
+ // are we previewing?
38
+ if ( ! isset( $_GET[ 'stylesheet' ] ) || !wp_verify_nonce( $_GET['preview_ctc'] ) || !current_user_can( 'switch_themes' ) )
39
+ return;
40
+
41
+ $this->original_stylesheet = get_stylesheet();
42
+ $this->theme = wp_get_theme( $_GET[ 'stylesheet' ] );
43
+ if ( ! $this->is_theme_active() ):
44
+ add_filter( 'template', array( $this, 'get_template' ) );
45
+ add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
46
+ /*
47
+ add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
48
+
49
+ add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
50
+ add_filter( 'pre_option_template', array( $this, 'get_template' ) );
51
+
52
+ // Handle custom theme roots.
53
+ add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
54
+ add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
55
+ */
56
+ // swap out theme mods with preview theme mods
57
+ add_filter( 'pre_option_theme_mods_' . $this->original_stylesheet, array( $this, 'preview_mods' ) );
58
  endif;
59
+
 
 
 
 
 
 
 
 
 
 
60
  // impossibly high priority to test for stylesheets loaded after wp_head()
61
+ add_action( 'wp_print_styles', array( $this, 'test_css' ), 999999 );
62
  // pass the wp_styles queue back to use for stylesheet handle verification
63
+ add_action( 'wp_footer', array( $this, 'parse_stylesheet' ) );
64
+ // hide admin bar in preview
65
+ if ( isset( $_GET[ 'preview_iframe' ] ) )
66
+ show_admin_bar( false );
67
  }
68
 
69
  /**
70
  * Retrieves child theme mods for preview
71
  */
72
+ public function preview_mods() {
73
+ if ( $this->is_theme_active() ) return false;
74
+ return get_option( 'theme_mods_' . $this->get_stylesheet() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
+ public function parse_stylesheet() {
78
  echo '<script>/*<![CDATA[' . LF;
79
  global $wp_styles, $wp_filter;
80
  $queue = implode( "\n", $wp_styles->queue );
134
  echo 'END CTC IRREGULAR' . LF;
135
  echo '*/]]></script>' . LF;
136
  }
137
+
138
+ // enqueue dummy stylesheet with extremely high priority to test wp_head()
139
+ public function test_css() {
140
+ wp_enqueue_style( 'ctc-test', get_stylesheet_directory_uri() . '/ctc-test.css' );
 
 
141
  }
142
 
143
+ public function woocommerce_unforce_ssl_checkout( $bool ){
144
  return FALSE;
145
  }
146
 
147
+ public function wp_die(){
148
+ die();
149
+ }
150
+
151
+ public function doing_ajax(){
152
+ return FALSE;
153
+ }
154
+
155
+ public function theme() {
156
+ if ( ! $this->theme ) {
157
+ $this->theme = wp_get_theme();
158
  }
159
+ return $this->theme;
160
+ }
161
+
162
+ public function is_preview() {
163
+ return TRUE;
164
+ }
165
+
166
+ public function is_theme_active() {
167
+ return $this->get_stylesheet() == $this->original_stylesheet;
168
+ }
169
+
170
+ public function get_template() {
171
+ return $this->theme()->get_template();
172
  }
173
+
174
+ public function get_stylesheet() {
175
+ return $this->theme()->get_stylesheet();
176
+ }
177
+
178
+ public function get_template_root() {
179
+ return get_raw_theme_root( $this->get_template(), true );
180
+ }
181
+
182
+ public function get_stylesheet_root() {
183
+ return get_raw_theme_root( $this->get_stylesheet(), true );
184
+ }
185
+
186
+ public function current_theme( $current_theme ) {
187
+ return $this->theme()->display( 'Name' );
188
+ }
189
+
190
+ public function wp_redirect_status( $status ) {
191
+ return 200;
192
+ }
193
+
194
+ public function wp_loaded() {
195
+ //do_action( 'customize_register', $this );
196
+ $this->customize_preview_init();
197
+ }
198
+
199
+ public function customize_preview_init() {
200
+ do_action( 'customize_preview_init', $this );
201
+ }
202
+ }
203
+
204
+ global $wp_customize;
205
+ $wp_customize = new WP_Customize_Manager();
206
+
207
+ endif;
includes/class-ctc-ui.php CHANGED
@@ -5,7 +5,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
5
  Class: Child_Theme_Configurator_UI
6
  Plugin URI: http://www.childthemeconfigurator.com/
7
  Description: Handles the plugin User Interface
8
- Version: 2.0.4
9
  Author: Lilaea Media
10
  Author URI: http://www.lilaeamedia.com/
11
  Text Domain: chld_thm_cfg
5
  Class: Child_Theme_Configurator_UI
6
  Plugin URI: http://www.childthemeconfigurator.com/
7
  Description: Handles the plugin User Interface
8
+ Version: 2.0.5
9
  Author: Lilaea Media
10
  Author URI: http://www.lilaeamedia.com/
11
  Text Domain: chld_thm_cfg
includes/class-ctc.php CHANGED
@@ -94,7 +94,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
94
  define( 'LILAEAMEDIA_URL', "http://www.lilaeamedia.com" );
95
  defined( 'CHLD_THM_CFG_DOCS_URL' ) or
96
  define( 'CHLD_THM_CFG_DOCS_URL', "http://www.childthemeconfigurator.com" );
97
- define( 'CHLD_THM_CFG_VERSION', '2.0.4' );
98
  define( 'CHLD_THM_CFG_PREV_VERSION', '1.7.9.1' );
99
  define( 'CHLD_THM_CFG_MIN_WP_VERSION', '3.7' );
100
  defined( 'CHLD_THM_CFG_BPSEL' ) or
94
  define( 'LILAEAMEDIA_URL', "http://www.lilaeamedia.com" );
95
  defined( 'CHLD_THM_CFG_DOCS_URL' ) or
96
  define( 'CHLD_THM_CFG_DOCS_URL', "http://www.childthemeconfigurator.com" );
97
+ define( 'CHLD_THM_CFG_VERSION', '2.0.5' );
98
  define( 'CHLD_THM_CFG_PREV_VERSION', '1.7.9.1' );
99
  define( 'CHLD_THM_CFG_MIN_WP_VERSION', '3.7' );
100
  defined( 'CHLD_THM_CFG_BPSEL' ) or
js/chldthmcfg.js CHANGED
@@ -2,7 +2,7 @@
2
  * Script: chldthmcfg.js
3
  * Plugin URI: http://www.childthemeconfigurator.com/
4
  * Description: Handles jQuery, AJAX and other UI
5
- * Version: 2.0.4
6
  * Author: Lilaea Media
7
  * Author URI: http://www.lilaeamedia.com/
8
  * License: GPLv2
2
  * Script: chldthmcfg.js
3
  * Plugin URI: http://www.childthemeconfigurator.com/
4
  * Description: Handles jQuery, AJAX and other UI
5
+ * Version: 2.0.5
6
  * Author: Lilaea Media
7
  * Author URI: http://www.lilaeamedia.com/
8
  * License: GPLv2
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: child, theme, child theme, child themes, custom styles, customize styles, customize theme, css, responsive, css editor, child theme editor, child theme generator, child theme creator, style, stylesheet, customizer, childtheme, childthemes
5
  Requires at least: 3.9
6
  Tested up to: 4.5.2
7
- Stable tag: 2.0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -287,8 +287,11 @@ https://www.youtube.com/watch?v=iBiiAgsK4G4
287
  7. Files tab
288
 
289
  == Changelog ==
 
 
 
290
  = 2.0.4 =
291
- * Updated preview class to send origin headers and run customize_preview_init action along with some other actions.
292
 
293
  = 2.0.3 =
294
  * Added logic conditions in preview class to help prevent Analyzer from failing in some cases
4
  Tags: child, theme, child theme, child themes, custom styles, customize styles, customize theme, css, responsive, css editor, child theme editor, child theme generator, child theme creator, style, stylesheet, customizer, childtheme, childthemes
5
  Requires at least: 3.9
6
  Tested up to: 4.5.2
7
+ Stable tag: 2.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
287
  7. Files tab
288
 
289
  == Changelog ==
290
+ = 2.0.5 =
291
+ * Updated child theme preview class to use is_theme_active and other methods to eliminate conflicts with Jetpack and any other plugin that references the customize manager.
292
+
293
  = 2.0.4 =
294
+ * Updated child theme preview class to send origin headers and run customize_preview_init action along with some other actions.
295
 
296
  = 2.0.3 =
297
  * Added logic conditions in preview class to help prevent Analyzer from failing in some cases