WordPress 4.0
[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?' ) );
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 wp_enqueue_script( 'accordion' );
57
58 /**
59  * Enqueue Customizer control scripts.
60  *
61  * @since 3.4.0
62  */
63 do_action( 'customize_controls_enqueue_scripts' );
64
65 // Let's roll.
66 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
67
68 wp_user_settings();
69 _wp_admin_html_begin();
70
71 $body_class = 'wp-core-ui wp-customizer js';
72
73 if ( wp_is_mobile() ) :
74         $body_class .= ' mobile';
75
76         ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2" /><?php
77 endif;
78
79 $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
80
81 if ( $is_ios )
82         $body_class .= ' ios';
83
84 if ( is_rtl() )
85         $body_class .=  ' rtl';
86 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
87
88 $admin_title = sprintf( __( '%1$s &#8212; WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
89 ?><title><?php echo $admin_title; ?></title>
90
91 <script type="text/javascript">
92 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
93 </script>
94
95 <?php
96 /**
97  * Fires when Customizer control styles are printed.
98  *
99  * @since 3.4.0
100  */
101 do_action( 'customize_controls_print_styles' );
102
103 /**
104  * Fires when Customizer control scripts are printed.
105  *
106  * @since 3.4.0
107  */
108 do_action( 'customize_controls_print_scripts' );
109 ?>
110 </head>
111 <body class="<?php echo esc_attr( $body_class ); ?>">
112 <div class="wp-full-overlay expanded">
113         <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
114
115                 <div id="customize-header-actions" class="wp-full-overlay-header">
116                         <?php
117                                 $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
118                                 submit_button( $save_text, 'primary save', 'save', false );
119                         ?>
120                         <span class="spinner"></span>
121                         <a class="customize-controls-close" href="<?php echo esc_url( $return ); ?>">
122                                 <span class="screen-reader-text"><?php _e( 'Cancel' ); ?></span>
123                         </a>
124                         <span class="control-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e( 'Back' ); ?></span></span>
125                 </div>
126
127                 <?php
128                         $screenshot = $wp_customize->theme()->get_screenshot();
129                         $cannot_expand = ! ( $wp_customize->is_theme_active() || $screenshot || $wp_customize->theme()->get('Description') );
130                 ?>
131
132                 <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 -->
133                 <div class="wp-full-overlay-sidebar-content accordion-container" tabindex="-1">
134                         <div id="customize-info" class="accordion-section <?php if ( $cannot_expand ) echo ' cannot-expand'; ?>">
135                                 <div class="accordion-section-title" aria-label="<?php esc_attr_e( 'Theme Customizer Options' ); ?>" tabindex="0">
136                                         <span class="preview-notice"><?php
137                                                 if ( ! $wp_customize->is_theme_active() ) {
138                                                         /* translators: %s is the theme name in the Customize/Live Preview pane */
139                                                         echo sprintf( __( 'You are previewing %s' ), '<strong class="theme-name">' . $wp_customize->theme()->display('Name') . '</strong>' );
140                                                 } else {
141                                                         /* translators: %s is the site/panel title in the Customize pane */
142                                                         echo sprintf( __( 'You are customizing %s' ), '<strong class="theme-name site-title">' . get_bloginfo( 'name' ) . '</strong>' );
143                                                 }
144                                         ?></span>
145                                 </div>
146                                 <?php if ( ! $cannot_expand ) : ?>
147                                 <div class="accordion-section-content">
148                                         <?php if ( ! $wp_customize->is_theme_active() ) :
149                                                 if ( $screenshot ) : ?>
150                                                         <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
151                                                 <?php endif; ?>
152
153                                                 <?php if ( $wp_customize->theme()->get('Description') ): ?>
154                                                         <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
155                                                 <?php endif;
156                                         else:
157                                                 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.' );
158                                         endif; ?>
159                                 </div>
160                                 <?php endif; ?>
161                         </div>
162
163                         <div id="customize-theme-controls"><ul>
164                                 <?php
165                                 foreach ( $wp_customize->containers() as $container ) {
166                                         $container->maybe_render();
167                                 }
168                                 ?>
169                         </ul></div>
170                 </div>
171                 </div>
172
173                 <div id="customize-footer-actions" class="wp-full-overlay-footer">
174                         <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
175                                 <span class="collapse-sidebar-arrow"></span>
176                                 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
177                         </a>
178                 </div>
179         </form>
180         <div id="customize-preview" class="wp-full-overlay-main"></div>
181         <?php
182
183         /**
184          * Print Customizer control scripts in the footer.
185          *
186          * @since 3.4.0
187          */
188         do_action( 'customize_controls_print_footer_scripts' );
189
190         /*
191          * If the frontend and the admin are served from the same domain, load the
192          * preview over ssl if the customizer is being loaded over ssl. This avoids
193          * insecure content warnings. This is not attempted if the admin and frontend
194          * are on different domains to avoid the case where the frontend doesn't have
195          * ssl certs. Domain mapping plugins can allow other urls in these conditions
196          * using the customize_allowed_urls filter.
197          */
198
199         $allowed_urls = array( home_url('/') );
200         $admin_origin = parse_url( admin_url() );
201         $home_origin  = parse_url( home_url() );
202         $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
203
204         if ( is_ssl() && ! $cross_domain )
205                 $allowed_urls[] = home_url( '/', 'https' );
206
207         /**
208          * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
209          *
210          * @since 3.4.0
211          *
212          * @param array $allowed_urls An array of allowed URLs.
213          */
214         $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
215
216         $fallback_url = add_query_arg( array(
217                 'preview'        => 1,
218                 'template'       => $wp_customize->get_template(),
219                 'stylesheet'     => $wp_customize->get_stylesheet(),
220                 'preview_iframe' => true,
221                 'TB_iframe'      => 'true'
222         ), home_url( '/' ) );
223
224         $login_url = add_query_arg( array(
225                 'interim-login' => 1,
226                 'customize-login' => 1
227         ), wp_login_url() );
228
229         // Prepare customizer settings to pass to Javascript.
230         $settings = array(
231                 'theme'    => array(
232                         'stylesheet' => $wp_customize->get_stylesheet(),
233                         'active'     => $wp_customize->is_theme_active(),
234                 ),
235                 'url'      => array(
236                         'preview'       => esc_url_raw( $url ? $url : home_url( '/' ) ),
237                         'parent'        => esc_url_raw( admin_url() ),
238                         'activated'     => esc_url_raw( admin_url( 'themes.php?activated=true&previewed' ) ),
239                         'ajax'          => esc_url_raw( admin_url( 'admin-ajax.php', 'relative' ) ),
240                         'allowed'       => array_map( 'esc_url_raw', $allowed_urls ),
241                         'isCrossDomain' => $cross_domain,
242                         'fallback'      => esc_url_raw( $fallback_url ),
243                         'home'          => esc_url_raw( home_url( '/' ) ),
244                         'login'         => esc_url_raw( $login_url ),
245                 ),
246                 'browser'  => array(
247                         'mobile' => wp_is_mobile(),
248                         'ios'    => $is_ios,
249                 ),
250                 'settings' => array(),
251                 'controls' => array(),
252                 'nonce'    => array(
253                         'save'    => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
254                         'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
255                 ),
256         );
257
258         // Prepare Customize Setting objects to pass to Javascript.
259         foreach ( $wp_customize->settings() as $id => $setting ) {
260                 $settings['settings'][ $id ] = array(
261                         'value'     => $setting->js_value(),
262                         'transport' => $setting->transport,
263                 );
264         }
265
266         // Prepare Customize Control objects to pass to Javascript.
267         foreach ( $wp_customize->controls() as $id => $control ) {
268                 $control->to_json();
269                 $settings['controls'][ $id ] = $control->json;
270         }
271
272         ?>
273         <script type="text/javascript">
274                 var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;
275         </script>
276 </div>
277 </body>
278 </html>