PageRenderTime 27ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/customize.php

http://github.com/wordpress/wordpress
PHP | 270 lines | 189 code | 33 blank | 48 comment | 16 complexity | 18da4481c4a4420630ff9e1c98579a56 MD5 | raw file
Possible License(s): 0BSD
  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 __DIR__ . '/admin.php';
  12. if ( ! current_user_can( 'customize' ) ) {
  13. wp_die(
  14. '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  15. '<p>' . __( 'Sorry, you are not allowed to customize this site.' ) . '</p>',
  16. 403
  17. );
  18. }
  19. /**
  20. * @global WP_Scripts $wp_scripts
  21. * @global WP_Customize_Manager $wp_customize
  22. */
  23. global $wp_scripts, $wp_customize;
  24. if ( $wp_customize->changeset_post_id() ) {
  25. $changeset_post = get_post( $wp_customize->changeset_post_id() );
  26. if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $changeset_post->ID ) ) {
  27. wp_die(
  28. '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  29. '<p>' . __( 'Sorry, you are not allowed to edit this changeset.' ) . '</p>',
  30. 403
  31. );
  32. }
  33. $missed_schedule = (
  34. 'future' === $changeset_post->post_status &&
  35. get_post_time( 'G', true, $changeset_post ) < time()
  36. );
  37. if ( $missed_schedule ) {
  38. /*
  39. * Note that an Ajax request spawns here instead of just calling `wp_publish_post( $changeset_post->ID )`.
  40. *
  41. * Because WP_Customize_Manager is not instantiated for customize.php with the `settings_previewed=false`
  42. * argument, settings cannot be reliably saved. Some logic short-circuits if the current value is the
  43. * same as the value being saved. This is particularly true for options via `update_option()`.
  44. *
  45. * By opening an Ajax request, this is avoided and the changeset is published. See #39221.
  46. */
  47. $nonces = $wp_customize->get_nonces();
  48. $request_args = array(
  49. 'nonce' => $nonces['save'],
  50. 'customize_changeset_uuid' => $wp_customize->changeset_uuid(),
  51. 'wp_customize' => 'on',
  52. 'customize_changeset_status' => 'publish',
  53. );
  54. ob_start();
  55. ?>
  56. <?php wp_print_scripts( array( 'wp-util' ) ); ?>
  57. <script>
  58. wp.ajax.post( 'customize_save', <?php echo wp_json_encode( $request_args ); ?> );
  59. </script>
  60. <?php
  61. $script = ob_get_clean();
  62. wp_die(
  63. '<h1>' . __( 'Your scheduled changes just published' ) . '</h1>' .
  64. '<p><a href="' . esc_url( remove_query_arg( 'changeset_uuid' ) ) . '">' . __( 'Customize New Changes' ) . '</a></p>' . $script,
  65. 200
  66. );
  67. }
  68. if ( in_array( get_post_status( $changeset_post->ID ), array( 'publish', 'trash' ), true ) ) {
  69. wp_die(
  70. '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
  71. '<p>' . __( 'This changeset cannot be further modified.' ) . '</p>' .
  72. '<p><a href="' . esc_url( remove_query_arg( 'changeset_uuid' ) ) . '">' . __( 'Customize New Changes' ) . '</a></p>',
  73. 403
  74. );
  75. }
  76. }
  77. wp_reset_vars( array( 'url', 'return', 'autofocus' ) );
  78. if ( ! empty( $url ) ) {
  79. $wp_customize->set_preview_url( wp_unslash( $url ) );
  80. }
  81. if ( ! empty( $return ) ) {
  82. $wp_customize->set_return_url( wp_unslash( $return ) );
  83. }
  84. if ( ! empty( $autofocus ) && is_array( $autofocus ) ) {
  85. $wp_customize->set_autofocus( wp_unslash( $autofocus ) );
  86. }
  87. $registered = $wp_scripts->registered;
  88. $wp_scripts = new WP_Scripts;
  89. $wp_scripts->registered = $registered;
  90. add_action( 'customize_controls_print_scripts', 'print_head_scripts', 20 );
  91. add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts' );
  92. add_action( 'customize_controls_print_styles', 'print_admin_styles', 20 );
  93. /**
  94. * Fires when Customizer controls are initialized, before scripts are enqueued.
  95. *
  96. * @since 3.4.0
  97. */
  98. do_action( 'customize_controls_init' );
  99. wp_enqueue_script( 'heartbeat' );
  100. wp_enqueue_script( 'customize-controls' );
  101. wp_enqueue_style( 'customize-controls' );
  102. /**
  103. * Enqueue Customizer control scripts.
  104. *
  105. * @since 3.4.0
  106. */
  107. do_action( 'customize_controls_enqueue_scripts' );
  108. // Let's roll.
  109. header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
  110. wp_user_settings();
  111. _wp_admin_html_begin();
  112. $body_class = 'wp-core-ui wp-customizer js';
  113. if ( wp_is_mobile() ) :
  114. $body_class .= ' mobile';
  115. ?>
  116. <meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=1.2" />
  117. <?php
  118. endif;
  119. if ( $wp_customize->is_ios() ) {
  120. $body_class .= ' ios';
  121. }
  122. if ( is_rtl() ) {
  123. $body_class .= ' rtl';
  124. }
  125. $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
  126. $admin_title = sprintf( $wp_customize->get_document_title_template(), __( 'Loading&hellip;' ) );
  127. ?>
  128. <title><?php echo esc_html( $admin_title ); ?></title>
  129. <script type="text/javascript">
  130. var ajaxurl = <?php echo wp_json_encode( admin_url( 'admin-ajax.php', 'relative' ) ); ?>,
  131. pagenow = 'customize';
  132. </script>
  133. <?php
  134. /**
  135. * Fires when Customizer control styles are printed.
  136. *
  137. * @since 3.4.0
  138. */
  139. do_action( 'customize_controls_print_styles' );
  140. /**
  141. * Fires when Customizer control scripts are printed.
  142. *
  143. * @since 3.4.0
  144. */
  145. do_action( 'customize_controls_print_scripts' );
  146. ?>
  147. </head>
  148. <body class="<?php echo esc_attr( $body_class ); ?>">
  149. <div class="wp-full-overlay expanded">
  150. <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
  151. <div id="customize-header-actions" class="wp-full-overlay-header">
  152. <?php $save_text = $wp_customize->is_theme_active() ? __( 'Publish' ) : __( 'Activate &amp; Publish' ); ?>
  153. <div id="customize-save-button-wrapper" class="customize-save-button-wrapper" >
  154. <?php submit_button( $save_text, 'primary save', 'save', false ); ?>
  155. <button id="publish-settings" class="publish-settings button-primary button dashicons dashicons-admin-generic" aria-label="<?php esc_attr_e( 'Publish Settings' ); ?>" aria-expanded="false" disabled></button>
  156. </div>
  157. <span class="spinner"></span>
  158. <button type="button" class="customize-controls-preview-toggle">
  159. <span class="controls"><?php _e( 'Customize' ); ?></span>
  160. <span class="preview"><?php _e( 'Preview' ); ?></span>
  161. </button>
  162. <a class="customize-controls-close" href="<?php echo esc_url( $wp_customize->get_return_url() ); ?>">
  163. <span class="screen-reader-text"><?php _e( 'Close the Customizer and go back to the previous page' ); ?></span>
  164. </a>
  165. </div>
  166. <div id="customize-sidebar-outer-content">
  167. <div id="customize-outer-theme-controls">
  168. <ul class="customize-outer-pane-parent"><?php // Outer panel and sections are not implemented, but its here as a placeholder to avoid any side-effect in api.Section. ?></ul>
  169. </div>
  170. </div>
  171. <div id="widgets-right" class="wp-clearfix"><!-- 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 -->
  172. <div id="customize-notifications-area" class="customize-control-notifications-container">
  173. <ul></ul>
  174. </div>
  175. <div class="wp-full-overlay-sidebar-content" tabindex="-1">
  176. <div id="customize-info" class="accordion-section customize-info">
  177. <div class="accordion-section-title">
  178. <span class="preview-notice">
  179. <?php
  180. /* translators: %s: The site/panel title in the Customizer. */
  181. echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title site-title">' . get_bloginfo( 'name', 'display' ) . '</strong>' );
  182. ?>
  183. </span>
  184. <button type="button" class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button>
  185. </div>
  186. <div class="customize-panel-description">
  187. <?php
  188. _e( 'The Customizer allows you to preview changes to your site before publishing them. You can navigate to different pages on your site within the preview. Edit shortcuts are shown for some editable elements.' );
  189. ?>
  190. </div>
  191. </div>
  192. <div id="customize-theme-controls">
  193. <ul class="customize-pane-parent"><?php // Panels and sections are managed here via JavaScript ?></ul>
  194. </div>
  195. </div>
  196. </div>
  197. <div id="customize-footer-actions" class="wp-full-overlay-footer">
  198. <button type="button" class="collapse-sidebar button" aria-expanded="true" aria-label="<?php echo esc_attr( _x( 'Hide Controls', 'label for hide controls button without length constraints' ) ); ?>">
  199. <span class="collapse-sidebar-arrow"></span>
  200. <span class="collapse-sidebar-label"><?php _ex( 'Hide Controls', 'short (~12 characters) label for hide controls button' ); ?></span>
  201. </button>
  202. <?php $previewable_devices = $wp_customize->get_previewable_devices(); ?>
  203. <?php if ( ! empty( $previewable_devices ) ) : ?>
  204. <div class="devices-wrapper">
  205. <div class="devices">
  206. <?php foreach ( (array) $previewable_devices as $device => $settings ) : ?>
  207. <?php
  208. if ( empty( $settings['label'] ) ) {
  209. continue;
  210. }
  211. $active = ! empty( $settings['default'] );
  212. $class = 'preview-' . $device;
  213. if ( $active ) {
  214. $class .= ' active';
  215. }
  216. ?>
  217. <button type="button" class="<?php echo esc_attr( $class ); ?>" aria-pressed="<?php echo esc_attr( $active ); ?>" data-device="<?php echo esc_attr( $device ); ?>">
  218. <span class="screen-reader-text"><?php echo esc_html( $settings['label'] ); ?></span>
  219. </button>
  220. <?php endforeach; ?>
  221. </div>
  222. </div>
  223. <?php endif; ?>
  224. </div>
  225. </form>
  226. <div id="customize-preview" class="wp-full-overlay-main"></div>
  227. <?php
  228. /**
  229. * Prints templates, control scripts, and settings in the footer.
  230. *
  231. * @since 3.4.0
  232. */
  233. do_action( 'customize_controls_print_footer_scripts' );
  234. ?>
  235. </div>
  236. </body>
  237. </html>