PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/customize.php

https://bitbucket.org/opehei/wordpress-trunk
PHP | 203 lines | 154 code | 34 blank | 15 comment | 14 complexity | 74b5679ae5fe94821ed5c78f3192085f MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Customize Controls
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 3.4.0
  8. */
  9. define( 'IFRAME_REQUEST', true );
  10. require_once( './admin.php' );
  11. if ( ! current_user_can( 'edit_theme_options' ) )
  12. wp_die( __( 'Cheatin&#8217; uh?' ) );
  13. wp_reset_vars( array( 'url', 'return' ) );
  14. $url = urldecode( $url );
  15. $url = wp_validate_redirect( $url, home_url( '/' ) );
  16. if ( $return )
  17. $return = wp_validate_redirect( urldecode( $return ) );
  18. if ( ! $return )
  19. $return = $url;
  20. global $wp_scripts, $wp_customize;
  21. $registered = $wp_scripts->registered;
  22. $wp_scripts = new WP_Scripts;
  23. $wp_scripts->registered = $registered;
  24. add_action( 'customize_controls_print_scripts', 'print_head_scripts', 20 );
  25. add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts' );
  26. add_action( 'customize_controls_print_styles', 'print_admin_styles', 20 );
  27. do_action( 'customize_controls_init' );
  28. wp_enqueue_script( 'customize-controls' );
  29. wp_enqueue_style( 'customize-controls' );
  30. do_action( 'customize_controls_enqueue_scripts' );
  31. // Let's roll.
  32. @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
  33. wp_user_settings();
  34. _wp_admin_html_begin();
  35. $body_class = '';
  36. if ( wp_is_mobile() ) :
  37. $body_class .= ' mobile';
  38. ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2"><?php
  39. endif;
  40. $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
  41. if ( $is_ios )
  42. $body_class .= ' ios';
  43. $admin_title = sprintf( __( '%1$s &#8212; WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
  44. ?><title><?php echo $admin_title; ?></title><?php
  45. do_action( 'customize_controls_print_styles' );
  46. do_action( 'customize_controls_print_scripts' );
  47. ?>
  48. </head>
  49. <body class="<?php echo esc_attr( $body_class ); ?>">
  50. <div class="wp-full-overlay expanded">
  51. <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
  52. <div id="customize-header-actions" class="wp-full-overlay-header">
  53. <?php
  54. $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
  55. submit_button( $save_text, 'primary', 'save', false );
  56. ?>
  57. <span class="spinner"></span>
  58. <a class="back button" href="<?php echo esc_url( $return ? $return : admin_url( 'themes.php' ) ); ?>">
  59. <?php _e( 'Cancel' ); ?>
  60. </a>
  61. </div>
  62. <?php
  63. $screenshot = $wp_customize->theme()->get_screenshot();
  64. $cannot_expand = ! ( $screenshot || $wp_customize->theme()->get('Description') );
  65. ?>
  66. <div class="wp-full-overlay-sidebar-content">
  67. <div id="customize-info" class="customize-section<?php if ( $cannot_expand ) echo ' cannot-expand'; ?>">
  68. <div class="customize-section-title">
  69. <span class="preview-notice"><?php
  70. /* translators: %s is the theme name in the Customize/Live Preview pane */
  71. echo sprintf( __( 'You are previewing %s' ), '<strong class="theme-name">' . $wp_customize->theme()->display('Name') . '</strong>' );
  72. ?></span>
  73. </div>
  74. <?php if ( ! $cannot_expand ) : ?>
  75. <div class="customize-section-content">
  76. <?php if ( $screenshot ) : ?>
  77. <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
  78. <?php endif; ?>
  79. <?php if ( $wp_customize->theme()->get('Description') ): ?>
  80. <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
  81. <?php endif; ?>
  82. </div>
  83. <?php endif; ?>
  84. </div>
  85. <div id="customize-theme-controls"><ul>
  86. <?php
  87. foreach ( $wp_customize->sections() as $section )
  88. $section->maybe_render();
  89. ?>
  90. </ul></div>
  91. </div>
  92. <div id="customize-footer-actions" class="wp-full-overlay-footer">
  93. <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
  94. <span class="collapse-sidebar-arrow"></span>
  95. <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
  96. </a>
  97. </div>
  98. </form>
  99. <div id="customize-preview" class="wp-full-overlay-main"></div>
  100. <?php
  101. do_action( 'customize_controls_print_footer_scripts' );
  102. // If the frontend and the admin are served from the same domain, load the
  103. // preview over ssl if the customizer is being loaded over ssl. This avoids
  104. // insecure content warnings. This is not attempted if the admin and frontend
  105. // are on different domains to avoid the case where the frontend doesn't have
  106. // ssl certs. Domain mapping plugins can allow other urls in these conditions
  107. // using the customize_allowed_urls filter.
  108. $allowed_urls = array( home_url('/') );
  109. $admin_origin = parse_url( admin_url() );
  110. $home_origin = parse_url( home_url() );
  111. $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
  112. if ( is_ssl() && ! $cross_domain )
  113. $allowed_urls[] = home_url( '/', 'https' );
  114. $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
  115. $fallback_url = add_query_arg( array(
  116. 'preview' => 1,
  117. 'template' => $wp_customize->get_template(),
  118. 'stylesheet' => $wp_customize->get_stylesheet(),
  119. 'preview_iframe' => true,
  120. 'TB_iframe' => 'true'
  121. ), home_url( '/' ) );
  122. $login_url = add_query_arg( array(
  123. 'interim-login' => 1,
  124. 'customize-login' => 1
  125. ), wp_login_url() );
  126. $settings = array(
  127. 'theme' => array(
  128. 'stylesheet' => $wp_customize->get_stylesheet(),
  129. 'active' => $wp_customize->is_theme_active(),
  130. ),
  131. 'url' => array(
  132. 'preview' => esc_url( $url ? $url : home_url( '/' ) ),
  133. 'parent' => esc_url( admin_url() ),
  134. 'activated' => admin_url( 'themes.php?activated=true&previewed' ),
  135. 'ajax' => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ),
  136. 'allowed' => array_map( 'esc_url', $allowed_urls ),
  137. 'isCrossDomain' => $cross_domain,
  138. 'fallback' => $fallback_url,
  139. 'home' => esc_url( home_url( '/' ) ),
  140. 'login' => $login_url,
  141. ),
  142. 'browser' => array(
  143. 'mobile' => wp_is_mobile(),
  144. 'ios' => $is_ios,
  145. ),
  146. 'settings' => array(),
  147. 'controls' => array(),
  148. 'nonce' => array(
  149. 'save' => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
  150. 'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
  151. ),
  152. );
  153. foreach ( $wp_customize->settings() as $id => $setting ) {
  154. $settings['settings'][ $id ] = array(
  155. 'value' => $setting->js_value(),
  156. 'transport' => $setting->transport,
  157. );
  158. }
  159. foreach ( $wp_customize->controls() as $id => $control ) {
  160. $control->to_json();
  161. $settings['controls'][ $id ] = $control->json;
  162. }
  163. ?>
  164. <script type="text/javascript">
  165. var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;
  166. </script>
  167. </div>
  168. </body>
  169. </html>