customize.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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( 'customize' ) ) {
  13. wp_die(
  14. '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</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. if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) ) {
  26. wp_die(
  27. '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
  28. '<p>' . __( 'Sorry, you are not allowed to edit this changeset.' ) . '</p>',
  29. 403
  30. );
  31. }
  32. if ( in_array( get_post_status( $wp_customize->changeset_post_id() ), array( 'publish', 'trash' ), true ) ) {
  33. wp_die(
  34. '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
  35. '<p>' . __( 'This changeset has already been published and cannot be further modified.' ) . '</p>' .
  36. '<p><a href="' . esc_url( remove_query_arg( 'changeset_uuid' ) ) . '">' . __( 'Customize New Changes' ) . '</a></p>',
  37. 403
  38. );
  39. }
  40. }
  41. wp_reset_vars( array( 'url', 'return', 'autofocus' ) );
  42. if ( ! empty( $url ) ) {
  43. $wp_customize->set_preview_url( wp_unslash( $url ) );
  44. }
  45. if ( ! empty( $return ) ) {
  46. $wp_customize->set_return_url( wp_unslash( $return ) );
  47. }
  48. if ( ! empty( $autofocus ) && is_array( $autofocus ) ) {
  49. $wp_customize->set_autofocus( wp_unslash( $autofocus ) );
  50. }
  51. $registered = $wp_scripts->registered;
  52. $wp_scripts = new WP_Scripts;
  53. $wp_scripts->registered = $registered;
  54. add_action( 'customize_controls_print_scripts', 'print_head_scripts', 20 );
  55. add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts' );
  56. add_action( 'customize_controls_print_styles', 'print_admin_styles', 20 );
  57. /**
  58. * Fires when Customizer controls are initialized, before scripts are enqueued.
  59. *
  60. * @since 3.4.0
  61. */
  62. do_action( 'customize_controls_init' );
  63. wp_enqueue_script( 'customize-controls' );
  64. wp_enqueue_style( 'customize-controls' );
  65. /**
  66. * Enqueue Customizer control scripts.
  67. *
  68. * @since 3.4.0
  69. */
  70. do_action( 'customize_controls_enqueue_scripts' );
  71. // Let's roll.
  72. @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
  73. wp_user_settings();
  74. _wp_admin_html_begin();
  75. $body_class = 'wp-core-ui wp-customizer js';
  76. if ( wp_is_mobile() ) :
  77. $body_class .= ' mobile';
  78. ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=1.2" /><?php
  79. endif;
  80. if ( $wp_customize->is_ios() ) {
  81. $body_class .= ' ios';
  82. }
  83. if ( is_rtl() ) {
  84. $body_class .= ' rtl';
  85. }
  86. $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
  87. $admin_title = sprintf( $wp_customize->get_document_title_template(), __( 'Loading&hellip;' ) );
  88. ?><title><?php echo $admin_title; ?></title>
  89. <script type="text/javascript">
  90. var ajaxurl = <?php echo wp_json_encode( admin_url( 'admin-ajax.php', 'relative' ) ); ?>;
  91. </script>
  92. <?php
  93. /**
  94. * Fires when Customizer control styles are printed.
  95. *
  96. * @since 3.4.0
  97. */
  98. do_action( 'customize_controls_print_styles' );
  99. /**
  100. * Fires when Customizer control scripts are printed.
  101. *
  102. * @since 3.4.0
  103. */
  104. do_action( 'customize_controls_print_scripts' );
  105. ?>
  106. </head>
  107. <body class="<?php echo esc_attr( $body_class ); ?>">
  108. <div class="wp-full-overlay expanded">
  109. <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
  110. <div id="customize-header-actions" class="wp-full-overlay-header">
  111. <?php
  112. $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
  113. $save_attrs = array();
  114. if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->publish_posts ) ) {
  115. $save_attrs['style'] = 'display: none';
  116. }
  117. submit_button( $save_text, 'primary save', 'save', false, $save_attrs );
  118. ?>
  119. <span class="spinner"></span>
  120. <button type="button" class="customize-controls-preview-toggle">
  121. <span class="controls"><?php _e( 'Customize' ); ?></span>
  122. <span class="preview"><?php _e( 'Preview' ); ?></span>
  123. </button>
  124. <a class="customize-controls-close" href="<?php echo esc_url( $wp_customize->get_return_url() ); ?>">
  125. <span class="screen-reader-text"><?php _e( 'Close the Customizer and go back to the previous page' ); ?></span>
  126. </a>
  127. </div>
  128. <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 -->
  129. <div class="wp-full-overlay-sidebar-content" tabindex="-1">
  130. <div id="customize-info" class="accordion-section customize-info">
  131. <div class="accordion-section-title">
  132. <span class="preview-notice"><?php
  133. echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title site-title">' . get_bloginfo( 'name' ) . '</strong>' );
  134. ?></span>
  135. <button type="button" class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button>
  136. </div>
  137. <div class="customize-panel-description"><?php
  138. _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.' );
  139. ?></div>
  140. </div>
  141. <div id="customize-theme-controls">
  142. <ul class="customize-pane-parent"><?php // Panels and sections are managed here via JavaScript ?></ul>
  143. </div>
  144. </div>
  145. </div>
  146. <div id="customize-footer-actions" class="wp-full-overlay-footer">
  147. <?php $previewable_devices = $wp_customize->get_previewable_devices(); ?>
  148. <?php if ( ! empty( $previewable_devices ) ) : ?>
  149. <div class="devices">
  150. <?php foreach ( (array) $previewable_devices as $device => $settings ) : ?>
  151. <?php
  152. if ( empty( $settings['label'] ) ) {
  153. continue;
  154. }
  155. $active = ! empty( $settings['default'] );
  156. $class = 'preview-' . $device;
  157. if ( $active ) {
  158. $class .= ' active';
  159. }
  160. ?>
  161. <button type="button" class="<?php echo esc_attr( $class ); ?>" aria-pressed="<?php echo esc_attr( $active ) ?>" data-device="<?php echo esc_attr( $device ); ?>">
  162. <span class="screen-reader-text"><?php echo esc_html( $settings['label'] ); ?></span>
  163. </button>
  164. <?php endforeach; ?>
  165. </div>
  166. <?php endif; ?>
  167. <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' ) ); ?>">
  168. <span class="collapse-sidebar-arrow"></span>
  169. <span class="collapse-sidebar-label"><?php _ex( 'Hide Controls', 'short (~12 characters) label for hide controls button' ); ?></span>
  170. </button>
  171. </div>
  172. </form>
  173. <div id="customize-preview" class="wp-full-overlay-main"></div>
  174. <?php
  175. /**
  176. * Prints templates, control scripts, and settings in the footer.
  177. *
  178. * @since 3.4.0
  179. */
  180. do_action( 'customize_controls_print_footer_scripts' );
  181. ?>
  182. </div>
  183. </body>
  184. </html>