3 * Theme Customize Screen.
6 * @subpackage Customize
10 define( 'IFRAME_REQUEST', true );
12 /** Load WordPress Administration Bootstrap */
13 require_once( dirname( __FILE__ ) . '/admin.php' );
15 if ( ! current_user_can( 'customize' ) ) {
16 wp_die( __( 'Cheatin’ uh?' ), 403 );
19 wp_reset_vars( array( 'url', 'return' ) );
20 $url = wp_unslash( $url );
21 $url = wp_validate_redirect( $url, home_url( '/' ) );
23 $return = wp_unslash( $return );
24 $return = wp_validate_redirect( $return );
29 } elseif ( current_user_can( 'edit_theme_options' ) || current_user_can( 'switch_themes' ) ) {
30 $return = admin_url( 'themes.php' );
32 $return = admin_url();
36 global $wp_scripts, $wp_customize;
38 $registered = $wp_scripts->registered;
39 $wp_scripts = new WP_Scripts;
40 $wp_scripts->registered = $registered;
42 add_action( 'customize_controls_print_scripts', 'print_head_scripts', 20 );
43 add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts' );
44 add_action( 'customize_controls_print_styles', 'print_admin_styles', 20 );
47 * Fires when Customizer controls are initialized, before scripts are enqueued.
51 do_action( 'customize_controls_init' );
53 wp_enqueue_script( 'customize-controls' );
54 wp_enqueue_style( 'customize-controls' );
57 * Enqueue Customizer control scripts.
61 do_action( 'customize_controls_enqueue_scripts' );
64 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
67 _wp_admin_html_begin();
69 $body_class = 'wp-core-ui wp-customizer js';
71 if ( wp_is_mobile() ) :
72 $body_class .= ' mobile';
74 ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=1.2" /><?php
77 $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
80 $body_class .= ' ios';
84 $body_class .= ' rtl';
86 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
88 if ( $wp_customize->is_theme_active() ) {
89 $document_title_tmpl = _x( 'Customize: %s', 'Placeholder is the document title from the preview' );
91 $document_title_tmpl = _x( 'Live Preview: %s', 'Placeholder is the document title from the preview' );
93 $document_title_tmpl = html_entity_decode( $document_title_tmpl, ENT_QUOTES, 'UTF-8' ); // because exported to JS and assigned to document.title
94 $admin_title = sprintf( $document_title_tmpl, __( 'Loading…' ) );
96 ?><title><?php echo $admin_title; ?></title>
98 <script type="text/javascript">
99 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
104 * Fires when Customizer control styles are printed.
108 do_action( 'customize_controls_print_styles' );
111 * Fires when Customizer control scripts are printed.
115 do_action( 'customize_controls_print_scripts' );
118 <body class="<?php echo esc_attr( $body_class ); ?>">
119 <div class="wp-full-overlay expanded">
120 <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
121 <div id="customize-header-actions" class="wp-full-overlay-header">
122 <div class="primary-actions">
124 $save_text = $wp_customize->is_theme_active() ? __( 'Save & Publish' ) : __( 'Save & Activate' );
125 submit_button( $save_text, 'primary save', 'save', false );
127 <span class="spinner"></span>
128 <a class="customize-controls-preview-toggle" href="#">
129 <span class="controls"><?php _e( 'Customize' ); ?></span>
130 <span class="preview"><?php _e( 'Preview' ); ?></span>
132 <a class="customize-controls-close" href="<?php echo esc_url( $return ); ?>">
133 <span class="screen-reader-text"><?php _e( 'Cancel' ); ?></span>
135 <span class="control-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e( 'Back' ); ?></span></span>
137 <div class="secondary-actions">
138 <button type="button" class="customize-overlay-close">
139 <span class="screen-reader-text"><?php _e( 'Close overlay' ); ?></span>
144 <div id="widgets-right"><!-- For Widget Customizer, many widgets try to look for instances under div#widgets-right, so we have to add that ID to a container div in the Customizer for compat -->
145 <div class="wp-full-overlay-sidebar-content" tabindex="-1">
146 <div id="customize-info" class="accordion-section">
147 <div class="accordion-section-title" aria-label="<?php esc_attr_e( 'Customizer Options' ); ?>" tabindex="0">
148 <span class="preview-notice"><?php
149 echo sprintf( __( 'You are customizing %s' ), '<strong class="theme-name site-title">' . get_bloginfo( 'name' ) . '</strong>' );
152 <div class="accordion-section-content"><?php
153 echo __( 'The Customizer allows you to preview changes to your site before publishing them. You can also navigate to different pages on your site to preview them.' );
157 <div id="customize-theme-controls">
158 <ul><?php // Panels and sections are managed here via JavaScript ?></ul>
163 <div id="customize-footer-actions" class="wp-full-overlay-footer">
164 <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
165 <span class="collapse-sidebar-arrow"></span>
166 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
170 <div id="customize-preview" class="wp-full-overlay-main"></div>
173 // Render control templates.
174 $wp_customize->render_control_templates();
177 * Print Customizer control scripts in the footer.
181 do_action( 'customize_controls_print_footer_scripts' );
184 * If the frontend and the admin are served from the same domain, load the
185 * preview over ssl if the Customizer is being loaded over ssl. This avoids
186 * insecure content warnings. This is not attempted if the admin and frontend
187 * are on different domains to avoid the case where the frontend doesn't have
188 * ssl certs. Domain mapping plugins can allow other urls in these conditions
189 * using the customize_allowed_urls filter.
192 $allowed_urls = array( home_url('/') );
193 $admin_origin = parse_url( admin_url() );
194 $home_origin = parse_url( home_url() );
195 $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
197 if ( is_ssl() && ! $cross_domain )
198 $allowed_urls[] = home_url( '/', 'https' );
201 * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
205 * @param array $allowed_urls An array of allowed URLs.
207 $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
209 $fallback_url = add_query_arg( array(
211 'template' => $wp_customize->get_template(),
212 'stylesheet' => $wp_customize->get_stylesheet(),
213 'preview_iframe' => true,
214 'TB_iframe' => 'true'
215 ), home_url( '/' ) );
217 $login_url = add_query_arg( array(
218 'interim-login' => 1,
219 'customize-login' => 1
222 // Prepare Customizer settings to pass to JavaScript.
225 'stylesheet' => $wp_customize->get_stylesheet(),
226 'active' => $wp_customize->is_theme_active(),
229 'preview' => esc_url_raw( $url ? $url : home_url( '/' ) ),
230 'parent' => esc_url_raw( admin_url() ),
231 'activated' => esc_url_raw( home_url( '/' ) ),
232 'ajax' => esc_url_raw( admin_url( 'admin-ajax.php', 'relative' ) ),
233 'allowed' => array_map( 'esc_url_raw', $allowed_urls ),
234 'isCrossDomain' => $cross_domain,
235 'fallback' => esc_url_raw( $fallback_url ),
236 'home' => esc_url_raw( home_url( '/' ) ),
237 'login' => esc_url_raw( $login_url ),
240 'mobile' => wp_is_mobile(),
243 'settings' => array(),
244 'controls' => array(),
246 'sections' => array(),
248 'save' => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
249 'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
251 'autofocus' => array(),
252 'documentTitleTmpl' => $document_title_tmpl,
255 // Prepare Customize Setting objects to pass to JavaScript.
256 foreach ( $wp_customize->settings() as $id => $setting ) {
257 $settings['settings'][ $id ] = array(
258 'value' => $setting->js_value(),
259 'transport' => $setting->transport,
260 'dirty' => $setting->dirty,
264 // Prepare Customize Control objects to pass to JavaScript.
265 foreach ( $wp_customize->controls() as $id => $control ) {
266 $settings['controls'][ $id ] = $control->json();
269 // Prepare Customize Section objects to pass to JavaScript.
270 foreach ( $wp_customize->sections() as $id => $section ) {
271 $settings['sections'][ $id ] = $section->json();
274 // Prepare Customize Panel objects to pass to JavaScript.
275 foreach ( $wp_customize->panels() as $id => $panel ) {
276 $settings['panels'][ $id ] = $panel->json();
277 foreach ( $panel->sections as $section_id => $section ) {
278 $settings['sections'][ $section_id ] = $section->json();
282 // Pass to frontend the Customizer construct being deeplinked
283 if ( isset( $_GET['autofocus'] ) ) {
284 $autofocus = wp_unslash( $_GET['autofocus'] );
285 if ( is_array( $autofocus ) ) {
286 foreach ( $autofocus as $type => $id ) {
287 if ( isset( $settings[ $type . 's' ][ $id ] ) ) {
288 $settings['autofocus'][ $type ] = $id;
295 <script type="text/javascript">
296 var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>;