]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/customize.php
WordPress 3.9.2
[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( 'edit_theme_options' ) )
16         wp_die( __( 'Cheatin&#8217; uh?' ) );
17
18 wp_reset_vars( array( 'url', 'return' ) );
19 $url = urldecode( $url );
20 $url = wp_validate_redirect( $url, home_url( '/' ) );
21 if ( $return )
22         $return = wp_validate_redirect( urldecode( $return ) );
23 if ( ! $return )
24         $return = $url;
25
26 global $wp_scripts, $wp_customize;
27
28 $registered = $wp_scripts->registered;
29 $wp_scripts = new WP_Scripts;
30 $wp_scripts->registered = $registered;
31
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 );
35
36 /**
37  * Fires when Customizer controls are initialized, before scripts are enqueued.
38  *
39  * @since 3.4.0
40  */
41 do_action( 'customize_controls_init' );
42
43 wp_enqueue_script( 'customize-controls' );
44 wp_enqueue_style( 'customize-controls' );
45
46 wp_enqueue_script( 'accordion' );
47
48 /**
49  * Enqueue Customizer control scripts.
50  *
51  * @since 3.4.0
52  */
53 do_action( 'customize_controls_enqueue_scripts' );
54
55 // Let's roll.
56 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
57
58 wp_user_settings();
59 _wp_admin_html_begin();
60
61 $body_class = 'wp-core-ui wp-customizer js';
62
63 if ( wp_is_mobile() ) :
64         $body_class .= ' mobile';
65
66         ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2"><?php
67 endif;
68
69 $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
70
71 if ( $is_ios )
72         $body_class .= ' ios';
73
74 if ( is_rtl() )
75         $body_class .=  ' rtl';
76 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
77
78 $admin_title = sprintf( __( '%1$s &#8212; WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
79 ?><title><?php echo $admin_title; ?></title>
80
81 <script type="text/javascript">
82 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
83 </script>
84
85 <?php
86 /**
87  * Fires when Customizer control styles are printed.
88  *
89  * @since 3.4.0
90  */
91 do_action( 'customize_controls_print_styles' );
92
93 /**
94  * Fires when Customizer control scripts are printed.
95  *
96  * @since 3.4.0
97  */
98 do_action( 'customize_controls_print_scripts' );
99 ?>
100 </head>
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">
104
105                 <div id="customize-header-actions" class="wp-full-overlay-header">
106                         <?php
107                                 $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
108                                 submit_button( $save_text, 'primary save', 'save', false );
109                         ?>
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' ); ?>
113                         </a>
114                 </div>
115
116                 <?php
117                         $screenshot = $wp_customize->theme()->get_screenshot();
118                         $cannot_expand = ! ( $screenshot || $wp_customize->theme()->get('Description') );
119                 ?>
120
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>' );
128                                         ?></span>
129                                 </div>
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 ); ?>" />
134                                         <?php endif; ?>
135
136                                         <?php if ( $wp_customize->theme()->get('Description') ): ?>
137                                                 <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
138                                         <?php endif; ?>
139                                 </div>
140                                 <?php endif; ?>
141                         </div>
142
143                         <div id="customize-theme-controls"><ul>
144                                 <?php
145                                 foreach ( $wp_customize->sections() as $section )
146                                         $section->maybe_render();
147                                 ?>
148                         </ul></div>
149                 </div>
150                 </div>
151
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>
156                         </a>
157                 </div>
158         </form>
159         <div id="customize-preview" class="wp-full-overlay-main"></div>
160         <?php
161
162         /**
163          * Print Customizer control scripts in the footer.
164          *
165          * @since 3.4.0
166          */
167         do_action( 'customize_controls_print_footer_scripts' );
168
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.
175
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' ] ) );
180
181         if ( is_ssl() && ! $cross_domain )
182                 $allowed_urls[] = home_url( '/', 'https' );
183
184         /**
185          * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
186          *
187          * @since 3.4.0
188          *
189          * @param array $allowed_urls An array of allowed URLs.
190          */
191         $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
192
193         $fallback_url = add_query_arg( array(
194                 'preview'        => 1,
195                 'template'       => $wp_customize->get_template(),
196                 'stylesheet'     => $wp_customize->get_stylesheet(),
197                 'preview_iframe' => true,
198                 'TB_iframe'      => 'true'
199         ), home_url( '/' ) );
200
201         $login_url = add_query_arg( array(
202                 'interim-login' => 1,
203                 'customize-login' => 1
204         ), wp_login_url() );
205
206         // Prepare customizer settings to pass to Javascript.
207         $settings = array(
208                 'theme'    => array(
209                         'stylesheet' => $wp_customize->get_stylesheet(),
210                         'active'     => $wp_customize->is_theme_active(),
211                 ),
212                 'url'      => array(
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 ),
222                 ),
223                 'browser'  => array(
224                         'mobile' => wp_is_mobile(),
225                         'ios'    => $is_ios,
226                 ),
227                 'settings' => array(),
228                 'controls' => array(),
229                 'nonce'    => array(
230                         'save'    => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
231                         'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
232                 ),
233         );
234
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,
240                 );
241         }
242
243         // Prepare Customize Control objects to pass to Javascript.
244         foreach ( $wp_customize->controls() as $id => $control ) {
245                 $control->to_json();
246                 $settings['controls'][ $id ] = $control->json;
247         }
248
249         ?>
250         <script type="text/javascript">
251                 var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;
252         </script>
253 </div>
254 </body>
255 </html>