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( 'edit_theme_options' ) )
16 wp_die( __( 'Cheatin’ uh?' ) );
18 wp_reset_vars( array( 'url', 'return' ) );
19 $url = urldecode( $url );
20 $url = wp_validate_redirect( $url, home_url( '/' ) );
22 $return = wp_validate_redirect( urldecode( $return ) );
26 global $wp_scripts, $wp_customize;
28 $registered = $wp_scripts->registered;
29 $wp_scripts = new WP_Scripts;
30 $wp_scripts->registered = $registered;
32 add_action( 'customize_controls_print_scripts', 'print_head_scripts', 20 );
33 add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts' );
34 add_action( 'customize_controls_print_styles', 'print_admin_styles', 20 );
37 * Fires when Customizer controls are initialized, before scripts are enqueued.
41 do_action( 'customize_controls_init' );
43 wp_enqueue_script( 'customize-controls' );
44 wp_enqueue_style( 'customize-controls' );
46 wp_enqueue_script( 'accordion' );
49 * Enqueue Customizer control scripts.
53 do_action( 'customize_controls_enqueue_scripts' );
56 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
59 _wp_admin_html_begin();
61 $body_class = 'wp-core-ui wp-customizer js';
63 if ( wp_is_mobile() ) :
64 $body_class .= ' mobile';
66 ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2"><?php
69 $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
72 $body_class .= ' ios';
75 $body_class .= ' rtl';
76 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
78 $admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
79 ?><title><?php echo $admin_title; ?></title>
81 <script type="text/javascript">
82 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
87 * Fires when Customizer control styles are printed.
91 do_action( 'customize_controls_print_styles' );
94 * Fires when Customizer control scripts are printed.
98 do_action( 'customize_controls_print_scripts' );
101 <body class="<?php echo esc_attr( $body_class ); ?>">
102 <div class="wp-full-overlay expanded">
103 <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
105 <div id="customize-header-actions" class="wp-full-overlay-header">
107 $save_text = $wp_customize->is_theme_active() ? __( 'Save & Publish' ) : __( 'Save & Activate' );
108 submit_button( $save_text, 'primary save', 'save', false );
110 <span class="spinner"></span>
111 <a class="back button" href="<?php echo esc_url( $return ? $return : admin_url( 'themes.php' ) ); ?>">
112 <?php _e( 'Cancel' ); ?>
117 $screenshot = $wp_customize->theme()->get_screenshot();
118 $cannot_expand = ! ( $screenshot || $wp_customize->theme()->get('Description') );
121 <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 -->
122 <div class="wp-full-overlay-sidebar-content accordion-container" tabindex="-1">
123 <div id="customize-info" class="accordion-section <?php if ( $cannot_expand ) echo ' cannot-expand'; ?>">
124 <div class="accordion-section-title" aria-label="<?php esc_attr_e( 'Theme Customizer Options' ); ?>" tabindex="0">
125 <span class="preview-notice"><?php
126 /* translators: %s is the theme name in the Customize/Live Preview pane */
127 echo sprintf( __( 'You are previewing %s' ), '<strong class="theme-name">' . $wp_customize->theme()->display('Name') . '</strong>' );
130 <?php if ( ! $cannot_expand ) : ?>
131 <div class="accordion-section-content">
132 <?php if ( $screenshot ) : ?>
133 <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
136 <?php if ( $wp_customize->theme()->get('Description') ): ?>
137 <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
143 <div id="customize-theme-controls"><ul>
145 foreach ( $wp_customize->sections() as $section )
146 $section->maybe_render();
152 <div id="customize-footer-actions" class="wp-full-overlay-footer">
153 <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
154 <span class="collapse-sidebar-arrow"></span>
155 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
159 <div id="customize-preview" class="wp-full-overlay-main"></div>
163 * Print Customizer control scripts in the footer.
167 do_action( 'customize_controls_print_footer_scripts' );
169 // If the frontend and the admin are served from the same domain, load the
170 // preview over ssl if the customizer is being loaded over ssl. This avoids
171 // insecure content warnings. This is not attempted if the admin and frontend
172 // are on different domains to avoid the case where the frontend doesn't have
173 // ssl certs. Domain mapping plugins can allow other urls in these conditions
174 // using the customize_allowed_urls filter.
176 $allowed_urls = array( home_url('/') );
177 $admin_origin = parse_url( admin_url() );
178 $home_origin = parse_url( home_url() );
179 $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
181 if ( is_ssl() && ! $cross_domain )
182 $allowed_urls[] = home_url( '/', 'https' );
185 * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
189 * @param array $allowed_urls An array of allowed URLs.
191 $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
193 $fallback_url = add_query_arg( array(
195 'template' => $wp_customize->get_template(),
196 'stylesheet' => $wp_customize->get_stylesheet(),
197 'preview_iframe' => true,
198 'TB_iframe' => 'true'
199 ), home_url( '/' ) );
201 $login_url = add_query_arg( array(
202 'interim-login' => 1,
203 'customize-login' => 1
206 // Prepare customizer settings to pass to Javascript.
209 'stylesheet' => $wp_customize->get_stylesheet(),
210 'active' => $wp_customize->is_theme_active(),
213 'preview' => esc_url_raw( $url ? $url : home_url( '/' ) ),
214 'parent' => esc_url_raw( admin_url() ),
215 'activated' => esc_url_raw( admin_url( 'themes.php?activated=true&previewed' ) ),
216 'ajax' => esc_url_raw( admin_url( 'admin-ajax.php', 'relative' ) ),
217 'allowed' => array_map( 'esc_url_raw', $allowed_urls ),
218 'isCrossDomain' => $cross_domain,
219 'fallback' => esc_url_raw( $fallback_url ),
220 'home' => esc_url_raw( home_url( '/' ) ),
221 'login' => esc_url_raw( $login_url ),
224 'mobile' => wp_is_mobile(),
227 'settings' => array(),
228 'controls' => array(),
230 'save' => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
231 'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
235 // Prepare Customize Setting objects to pass to Javascript.
236 foreach ( $wp_customize->settings() as $id => $setting ) {
237 $settings['settings'][ $id ] = array(
238 'value' => $setting->js_value(),
239 'transport' => $setting->transport,
243 // Prepare Customize Control objects to pass to Javascript.
244 foreach ( $wp_customize->controls() as $id => $control ) {
246 $settings['controls'][ $id ] = $control->json;
250 <script type="text/javascript">
251 var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;