WordPress 4.1.3
[autoinstalls/wordpress.git] / wp-admin / customize.php
1 <?php
2 /**
3  * Theme Customize Screen.
4  *
5  * @package WordPress
6  * @subpackage Customize
7  * @since 3.4.0
8  */
9
10 define( 'IFRAME_REQUEST', true );
11
12 /** Load WordPress Administration Bootstrap */
13 require_once( dirname( __FILE__ ) . '/admin.php' );
14
15 if ( ! current_user_can( 'customize' ) ) {
16         wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
17 }
18
19 wp_reset_vars( array( 'url', 'return' ) );
20 $url = wp_unslash( $url );
21 $url = wp_validate_redirect( $url, home_url( '/' ) );
22 if ( $return ) {
23         $return = wp_unslash( $return );
24         $return = wp_validate_redirect( $return );
25 }
26 if ( ! $return ) {
27         if ( $url ) {
28                 $return = $url;
29         } elseif ( current_user_can( 'edit_theme_options' ) || current_user_can( 'switch_themes' ) ) {
30                 $return = admin_url( 'themes.php' );
31         } else {
32                 $return = admin_url();
33         }
34 }
35
36 global $wp_scripts, $wp_customize;
37
38 $registered = $wp_scripts->registered;
39 $wp_scripts = new WP_Scripts;
40 $wp_scripts->registered = $registered;
41
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 );
45
46 /**
47  * Fires when Customizer controls are initialized, before scripts are enqueued.
48  *
49  * @since 3.4.0
50  */
51 do_action( 'customize_controls_init' );
52
53 wp_enqueue_script( 'customize-controls' );
54 wp_enqueue_style( 'customize-controls' );
55
56 /**
57  * Enqueue Customizer control scripts.
58  *
59  * @since 3.4.0
60  */
61 do_action( 'customize_controls_enqueue_scripts' );
62
63 // Let's roll.
64 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
65
66 wp_user_settings();
67 _wp_admin_html_begin();
68
69 $body_class = 'wp-core-ui wp-customizer js';
70
71 if ( wp_is_mobile() ) :
72         $body_class .= ' mobile';
73
74         ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2" /><?php
75 endif;
76
77 $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
78
79 if ( $is_ios ) {
80         $body_class .= ' ios';
81 }
82
83 if ( is_rtl() ) {
84         $body_class .= ' rtl';
85 }
86 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
87
88 if ( $wp_customize->is_theme_active() ) {
89         $document_title_tmpl = _x( 'Customize: %s', 'Placeholder is the document title from the preview' );
90 } else {
91         $document_title_tmpl = _x( 'Live Preview: %s', 'Placeholder is the document title from the preview' );
92 }
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&hellip;' ) );
95
96 ?><title><?php echo $admin_title; ?></title>
97
98 <script type="text/javascript">
99 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
100 </script>
101
102 <?php
103 /**
104  * Fires when Customizer control styles are printed.
105  *
106  * @since 3.4.0
107  */
108 do_action( 'customize_controls_print_styles' );
109
110 /**
111  * Fires when Customizer control scripts are printed.
112  *
113  * @since 3.4.0
114  */
115 do_action( 'customize_controls_print_scripts' );
116 ?>
117 </head>
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="screen-reader-messages" aria-live="polite" aria-relevant="all" aria-role="status" aria-atomic="true" class="screen-reader-text"></div>
122
123                 <div id="customize-header-actions" class="wp-full-overlay-header">
124                         <?php
125                                 $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
126                                 submit_button( $save_text, 'primary save', 'save', false );
127                         ?>
128                         <span class="spinner"></span>
129                         <a class="customize-controls-close" href="<?php echo esc_url( $return ); ?>">
130                                 <span class="screen-reader-text"><?php _e( 'Cancel' ); ?></span>
131                         </a>
132                         <span class="control-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e( 'Back' ); ?></span></span>
133                 </div>
134
135                 <?php
136                         $screenshot = $wp_customize->theme()->get_screenshot();
137                         $cannot_expand = ! ( $wp_customize->is_theme_active() || $screenshot || $wp_customize->theme()->get('Description') );
138                 ?>
139
140                 <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 -->
141                 <div class="wp-full-overlay-sidebar-content" tabindex="-1">
142                         <div id="customize-info" class="accordion-section <?php if ( $cannot_expand ) echo ' cannot-expand'; ?>">
143                                 <div class="accordion-section-title" aria-label="<?php esc_attr_e( 'Customizer Options' ); ?>" tabindex="0">
144                                         <span class="preview-notice"><?php
145                                                 if ( ! $wp_customize->is_theme_active() ) {
146                                                         /* translators: %s is the theme name in the Customize/Live Preview pane */
147                                                         echo sprintf( __( 'You are previewing %s' ), '<strong class="theme-name">' . $wp_customize->theme()->display('Name') . '</strong>' );
148                                                 } else {
149                                                         /* translators: %s is the site/panel title in the Customize pane */
150                                                         echo sprintf( __( 'You are customizing %s' ), '<strong class="theme-name site-title">' . get_bloginfo( 'name' ) . '</strong>' );
151                                                 }
152                                         ?></span>
153                                 </div>
154                                 <?php if ( ! $cannot_expand ) : ?>
155                                 <div class="accordion-section-content">
156                                         <?php if ( ! $wp_customize->is_theme_active() ) :
157                                                 if ( $screenshot ) : ?>
158                                                         <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
159                                                 <?php endif; ?>
160
161                                                 <?php if ( $wp_customize->theme()->get('Description') ): ?>
162                                                         <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
163                                                 <?php endif;
164                                         else:
165                                                 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.' );
166                                         endif; ?>
167                                 </div>
168                                 <?php endif; ?>
169                         </div>
170
171                         <div id="customize-theme-controls">
172                                 <ul><?php // Panels and sections are managed here via JavaScript ?></ul>
173                         </div>
174                 </div>
175                 </div>
176
177                 <div id="customize-footer-actions" class="wp-full-overlay-footer">
178                         <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
179                                 <span class="collapse-sidebar-arrow"></span>
180                                 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
181                         </a>
182                 </div>
183         </form>
184         <div id="customize-preview" class="wp-full-overlay-main"></div>
185         <?php
186
187         // Render control templates.
188         $wp_customize->render_control_templates();
189
190         /**
191          * Print Customizer control scripts in the footer.
192          *
193          * @since 3.4.0
194          */
195         do_action( 'customize_controls_print_footer_scripts' );
196
197         /*
198          * If the frontend and the admin are served from the same domain, load the
199          * preview over ssl if the Customizer is being loaded over ssl. This avoids
200          * insecure content warnings. This is not attempted if the admin and frontend
201          * are on different domains to avoid the case where the frontend doesn't have
202          * ssl certs. Domain mapping plugins can allow other urls in these conditions
203          * using the customize_allowed_urls filter.
204          */
205
206         $allowed_urls = array( home_url('/') );
207         $admin_origin = parse_url( admin_url() );
208         $home_origin  = parse_url( home_url() );
209         $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
210
211         if ( is_ssl() && ! $cross_domain )
212                 $allowed_urls[] = home_url( '/', 'https' );
213
214         /**
215          * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
216          *
217          * @since 3.4.0
218          *
219          * @param array $allowed_urls An array of allowed URLs.
220          */
221         $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
222
223         $fallback_url = add_query_arg( array(
224                 'preview'        => 1,
225                 'template'       => $wp_customize->get_template(),
226                 'stylesheet'     => $wp_customize->get_stylesheet(),
227                 'preview_iframe' => true,
228                 'TB_iframe'      => 'true'
229         ), home_url( '/' ) );
230
231         $login_url = add_query_arg( array(
232                 'interim-login' => 1,
233                 'customize-login' => 1
234         ), wp_login_url() );
235
236         // Prepare Customizer settings to pass to JavaScript.
237         $settings = array(
238                 'theme'    => array(
239                         'stylesheet' => $wp_customize->get_stylesheet(),
240                         'active'     => $wp_customize->is_theme_active(),
241                 ),
242                 'url'      => array(
243                         'preview'       => esc_url_raw( $url ? $url : home_url( '/' ) ),
244                         'parent'        => esc_url_raw( admin_url() ),
245                         'activated'     => esc_url_raw( admin_url( 'themes.php?activated=true&previewed' ) ),
246                         'ajax'          => esc_url_raw( admin_url( 'admin-ajax.php', 'relative' ) ),
247                         'allowed'       => array_map( 'esc_url_raw', $allowed_urls ),
248                         'isCrossDomain' => $cross_domain,
249                         'fallback'      => esc_url_raw( $fallback_url ),
250                         'home'          => esc_url_raw( home_url( '/' ) ),
251                         'login'         => esc_url_raw( $login_url ),
252                 ),
253                 'browser'  => array(
254                         'mobile' => wp_is_mobile(),
255                         'ios'    => $is_ios,
256                 ),
257                 'settings' => array(),
258                 'controls' => array(),
259                 'panels'   => array(),
260                 'sections' => array(),
261                 'nonce'    => array(
262                         'save'    => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
263                         'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
264                 ),
265                 'autofocus' => array(),
266                 'documentTitleTmpl' => $document_title_tmpl,
267         );
268
269         // Prepare Customize Setting objects to pass to JavaScript.
270         foreach ( $wp_customize->settings() as $id => $setting ) {
271                 $settings['settings'][ $id ] = array(
272                         'value'     => $setting->js_value(),
273                         'transport' => $setting->transport,
274                 );
275         }
276
277         // Prepare Customize Control objects to pass to JavaScript.
278         foreach ( $wp_customize->controls() as $id => $control ) {
279                 $settings['controls'][ $id ] = $control->json();
280         }
281
282         // Prepare Customize Section objects to pass to JavaScript.
283         foreach ( $wp_customize->sections() as $id => $section ) {
284                 $settings['sections'][ $id ] = $section->json();
285         }
286
287         // Prepare Customize Panel objects to pass to JavaScript.
288         foreach ( $wp_customize->panels() as $id => $panel ) {
289                 $settings['panels'][ $id ] = $panel->json();
290                 foreach ( $panel->sections as $section_id => $section ) {
291                         $settings['sections'][ $section_id ] = $section->json();
292                 }
293         }
294
295         // Pass to frontend the Customizer construct being deeplinked
296         if ( isset( $_GET['autofocus'] ) ) {
297                 $autofocus = wp_unslash( $_GET['autofocus'] );
298                 if ( is_array( $autofocus ) ) {
299                         foreach ( $autofocus as $type => $id ) {
300                                 if ( isset( $settings[ $type . 's' ][ $id ] ) ) {
301                                         $settings['autofocus'][ $type ] = $id;
302                                 }
303                         }
304                 }
305         }
306
307         ?>
308         <script type="text/javascript">
309                 var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>;
310         </script>
311 </div>
312 </body>
313 </html>