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