]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/customize.php
WordPress 4.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 /**
37  * @global WP_Scripts           $wp_scripts
38  * @global WP_Customize_Manager $wp_customize
39  */
40 global $wp_scripts, $wp_customize;
41
42 $registered = $wp_scripts->registered;
43 $wp_scripts = new WP_Scripts;
44 $wp_scripts->registered = $registered;
45
46 add_action( 'customize_controls_print_scripts',        'print_head_scripts', 20 );
47 add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts'     );
48 add_action( 'customize_controls_print_styles',         'print_admin_styles', 20 );
49
50 /**
51  * Fires when Customizer controls are initialized, before scripts are enqueued.
52  *
53  * @since 3.4.0
54  */
55 do_action( 'customize_controls_init' );
56
57 wp_enqueue_script( 'customize-controls' );
58 wp_enqueue_style( 'customize-controls' );
59
60 /**
61  * Enqueue Customizer control scripts.
62  *
63  * @since 3.4.0
64  */
65 do_action( 'customize_controls_enqueue_scripts' );
66
67 // Let's roll.
68 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
69
70 wp_user_settings();
71 _wp_admin_html_begin();
72
73 $body_class = 'wp-core-ui wp-customizer js';
74
75 if ( wp_is_mobile() ) :
76         $body_class .= ' mobile';
77
78         ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=1.2" /><?php
79 endif;
80
81 $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
82
83 if ( $is_ios ) {
84         $body_class .= ' ios';
85 }
86
87 if ( is_rtl() ) {
88         $body_class .= ' rtl';
89 }
90 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
91
92 if ( $wp_customize->is_theme_active() ) {
93         $document_title_tmpl = _x( 'Customize: %s', 'Placeholder is the document title from the preview' );
94 } else {
95         $document_title_tmpl = _x( 'Live Preview: %s', 'Placeholder is the document title from the preview' );
96 }
97 $document_title_tmpl = html_entity_decode( $document_title_tmpl, ENT_QUOTES, 'UTF-8' ); // because exported to JS and assigned to document.title
98 $admin_title = sprintf( $document_title_tmpl, __( 'Loading&hellip;' ) );
99
100 ?><title><?php echo $admin_title; ?></title>
101
102 <script type="text/javascript">
103 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
104 </script>
105
106 <?php
107 /**
108  * Fires when Customizer control styles are printed.
109  *
110  * @since 3.4.0
111  */
112 do_action( 'customize_controls_print_styles' );
113
114 /**
115  * Fires when Customizer control scripts are printed.
116  *
117  * @since 3.4.0
118  */
119 do_action( 'customize_controls_print_scripts' );
120 ?>
121 </head>
122 <body class="<?php echo esc_attr( $body_class ); ?>">
123 <div class="wp-full-overlay expanded">
124         <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
125                 <div id="customize-header-actions" class="wp-full-overlay-header">
126                         <?php
127                         $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
128                         submit_button( $save_text, 'primary save', 'save', false );
129                         ?>
130                         <span class="spinner"></span>
131                         <a class="customize-controls-preview-toggle" href="#">
132                                 <span class="controls"><?php _e( 'Customize' ); ?></span>
133                                 <span class="preview"><?php _e( 'Preview' ); ?></span>
134                         </a>
135                         <a class="customize-controls-close" href="<?php echo esc_url( $return ); ?>">
136                                 <span class="screen-reader-text"><?php _e( 'Cancel' ); ?></span>
137                         </a>
138                 </div>
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 customize-info">
143                                 <div class="accordion-section-title" aria-label="<?php esc_attr_e( 'Customizer Options' ); ?>">
144                                         <span class="preview-notice"><?php
145                                                 echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title site-title">' . get_bloginfo( 'name' ) . '</strong>' );
146                                         ?></span>
147                                         <button class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button>
148                                 </div>
149                                 <div class="customize-panel-description"><?php
150                                         _e( '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.' );
151                                 ?></div>
152                         </div>
153
154                         <div id="customize-theme-controls">
155                                 <ul><?php // Panels and sections are managed here via JavaScript ?></ul>
156                         </div>
157                 </div>
158                 </div>
159
160                 <div id="customize-footer-actions" class="wp-full-overlay-footer">
161                         <button type="button" class="collapse-sidebar button-secondary" aria-expanded="true" aria-label="<?php esc_attr_e( 'Collapse Sidebar' ); ?>">
162                                 <span class="collapse-sidebar-arrow"></span>
163                                 <span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span>
164                         </button>
165                 </div>
166         </form>
167         <div id="customize-preview" class="wp-full-overlay-main"></div>
168         <?php
169
170         // Render Panel, Section, and Control templates.
171         $wp_customize->render_panel_templates();
172         $wp_customize->render_section_templates();
173         $wp_customize->render_control_templates();
174
175         /**
176          * Print Customizer control scripts in the footer.
177          *
178          * @since 3.4.0
179          */
180         do_action( 'customize_controls_print_footer_scripts' );
181
182         /*
183          * If the frontend and the admin are served from the same domain, load the
184          * preview over ssl if the Customizer is being loaded over ssl. This avoids
185          * insecure content warnings. This is not attempted if the admin and frontend
186          * are on different domains to avoid the case where the frontend doesn't have
187          * ssl certs. Domain mapping plugins can allow other urls in these conditions
188          * using the customize_allowed_urls filter.
189          */
190
191         $allowed_urls = array( home_url('/') );
192         $admin_origin = parse_url( admin_url() );
193         $home_origin  = parse_url( home_url() );
194         $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
195
196         if ( is_ssl() && ! $cross_domain )
197                 $allowed_urls[] = home_url( '/', 'https' );
198
199         /**
200          * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
201          *
202          * @since 3.4.0
203          *
204          * @param array $allowed_urls An array of allowed URLs.
205          */
206         $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
207
208         $login_url = add_query_arg( array(
209                 'interim-login' => 1,
210                 'customize-login' => 1
211         ), wp_login_url() );
212
213         // Prepare Customizer settings to pass to JavaScript.
214         $settings = array(
215                 'theme'    => array(
216                         'stylesheet' => $wp_customize->get_stylesheet(),
217                         'active'     => $wp_customize->is_theme_active(),
218                 ),
219                 'url'      => array(
220                         'preview'       => esc_url_raw( $url ? $url : home_url( '/' ) ),
221                         'parent'        => esc_url_raw( admin_url() ),
222                         'activated'     => esc_url_raw( home_url( '/' ) ),
223                         'ajax'          => esc_url_raw( admin_url( 'admin-ajax.php', 'relative' ) ),
224                         'allowed'       => array_map( 'esc_url_raw', $allowed_urls ),
225                         'isCrossDomain' => $cross_domain,
226                         'home'          => esc_url_raw( home_url( '/' ) ),
227                         'login'         => esc_url_raw( $login_url ),
228                 ),
229                 'browser'  => array(
230                         'mobile' => wp_is_mobile(),
231                         'ios'    => $is_ios,
232                 ),
233                 'settings' => array(),
234                 'controls' => array(),
235                 'panels'   => array(),
236                 'sections' => array(),
237                 'nonce'    => array(
238                         'save'    => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
239                         'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
240                 ),
241                 'autofocus' => array(),
242                 'documentTitleTmpl' => $document_title_tmpl,
243         );
244
245         // Prepare Customize Setting objects to pass to JavaScript.
246         foreach ( $wp_customize->settings() as $id => $setting ) {
247                 if ( $setting->check_capabilities() ) {
248                         $settings['settings'][ $id ] = array(
249                                 'value'     => $setting->js_value(),
250                                 'transport' => $setting->transport,
251                                 'dirty'     => $setting->dirty,
252                         );
253                 }
254         }
255
256         // Prepare Customize Control objects to pass to JavaScript.
257         foreach ( $wp_customize->controls() as $id => $control ) {
258                 if ( $control->check_capabilities() ) {
259                         $settings['controls'][ $id ] = $control->json();
260                 }
261         }
262
263         // Prepare Customize Section objects to pass to JavaScript.
264         foreach ( $wp_customize->sections() as $id => $section ) {
265                 if ( $section->check_capabilities() ) {
266                         $settings['sections'][ $id ] = $section->json();
267                 }
268         }
269
270         // Prepare Customize Panel objects to pass to JavaScript.
271         foreach ( $wp_customize->panels() as $panel_id => $panel ) {
272                 if ( $panel->check_capabilities() ) {
273                         $settings['panels'][ $panel_id ] = $panel->json();
274                         foreach ( $panel->sections as $section_id => $section ) {
275                                 if ( $section->check_capabilities() ) {
276                                         $settings['sections'][ $section_id ] = $section->json();
277                                 }
278                         }
279                 }
280         }
281
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;
289                                 }
290                         }
291                 }
292         }
293
294         ?>
295         <script type="text/javascript">
296                 var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>;
297         </script>
298 </div>
299 </body>
300 </html>