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

/APP/wp-admin/customize.php

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