[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> customize.php (source)

   1  <?php
   2  /**
   3   * Theme Customize Screen.
   4   *
   5   * @package WordPress
   6   * @subpackage Customize
   7   * @since 3.4.0
   8   */
   9  
  10  define( 'IFRAME_REQUEST', true );
  11  
  12  /** Load WordPress Administration Bootstrap */
  13  require_once  __DIR__ . '/admin.php';
  14  
  15  if ( ! current_user_can( 'customize' ) ) {
  16      wp_die(
  17          '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  18          '<p>' . __( 'Sorry, you are not allowed to customize this site.' ) . '</p>',
  19          403
  20      );
  21  }
  22  
  23  /**
  24   * @global WP_Scripts           $wp_scripts
  25   * @global WP_Customize_Manager $wp_customize
  26   */
  27  global $wp_scripts, $wp_customize;
  28  
  29  if ( $wp_customize->changeset_post_id() ) {
  30      $changeset_post = get_post( $wp_customize->changeset_post_id() );
  31  
  32      if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $changeset_post->ID ) ) {
  33          wp_die(
  34              '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  35              '<p>' . __( 'Sorry, you are not allowed to edit this changeset.' ) . '</p>',
  36              403
  37          );
  38      }
  39  
  40      $missed_schedule = (
  41          'future' === $changeset_post->post_status &&
  42          get_post_time( 'G', true, $changeset_post ) < time()
  43      );
  44      if ( $missed_schedule ) {
  45          /*
  46           * Note that an Ajax request spawns here instead of just calling `wp_publish_post( $changeset_post->ID )`.
  47           *
  48           * Because WP_Customize_Manager is not instantiated for customize.php with the `settings_previewed=false`
  49           * argument, settings cannot be reliably saved. Some logic short-circuits if the current value is the
  50           * same as the value being saved. This is particularly true for options via `update_option()`.
  51           *
  52           * By opening an Ajax request, this is avoided and the changeset is published. See #39221.
  53           */
  54          $nonces       = $wp_customize->get_nonces();
  55          $request_args = array(
  56              'nonce'                      => $nonces['save'],
  57              'customize_changeset_uuid'   => $wp_customize->changeset_uuid(),
  58              'wp_customize'               => 'on',
  59              'customize_changeset_status' => 'publish',
  60          );
  61          ob_start();
  62          ?>
  63          <?php wp_print_scripts( array( 'wp-util' ) ); ?>
  64          <script>
  65              wp.ajax.post( 'customize_save', <?php echo wp_json_encode( $request_args, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> );
  66          </script>
  67          <?php
  68          $script = ob_get_clean();
  69  
  70          wp_die(
  71              '<h1>' . __( 'Your scheduled changes just published' ) . '</h1>' .
  72              '<p><a href="' . esc_url( remove_query_arg( 'changeset_uuid' ) ) . '">' . __( 'Customize New Changes' ) . '</a></p>' . $script,
  73              200
  74          );
  75      }
  76  
  77      if ( in_array( get_post_status( $changeset_post->ID ), array( 'publish', 'trash' ), true ) ) {
  78          wp_die(
  79              '<h1>' . __( 'An error occurred while saving your changeset.' ) . '</h1>' .
  80              '<p>' . __( 'Please try again or start a new changeset. This changeset cannot be further modified.' ) . '</p>' .
  81              '<p><a href="' . esc_url( remove_query_arg( 'changeset_uuid' ) ) . '">' . __( 'Customize New Changes' ) . '</a></p>',
  82              403
  83          );
  84      }
  85  }
  86  
  87  $url       = ! empty( $_REQUEST['url'] ) ? esc_url_raw( wp_unslash( $_REQUEST['url'] ) ) : '';
  88  $return    = ! empty( $_REQUEST['return'] ) ? esc_url_raw( wp_unslash( $_REQUEST['return'] ) ) : '';
  89  $autofocus = ! empty( $_REQUEST['autofocus'] ) && is_array( $_REQUEST['autofocus'] )
  90      ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['autofocus'] ) )
  91      : array();
  92  
  93  if ( ! empty( $url ) ) {
  94      $wp_customize->set_preview_url( $url );
  95  }
  96  if ( ! empty( $return ) ) {
  97      $wp_customize->set_return_url( $return );
  98  }
  99  if ( ! empty( $autofocus ) ) {
 100      $wp_customize->set_autofocus( $autofocus );
 101  }
 102  
 103  // Let's roll.
 104  header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
 105  
 106  wp_user_settings();
 107  _wp_admin_html_begin();
 108  
 109  $registered             = $wp_scripts->registered;
 110  $wp_scripts             = new WP_Scripts();
 111  $wp_scripts->registered = $registered;
 112  
 113  add_action( 'customize_controls_print_scripts', 'print_head_scripts', 20 );
 114  add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts' );
 115  add_action( 'customize_controls_print_styles', 'print_admin_styles', 20 );
 116  
 117  /**
 118   * Fires when Customizer controls are initialized, before scripts are enqueued.
 119   *
 120   * @since 3.4.0
 121   */
 122  do_action( 'customize_controls_init' );
 123  
 124  wp_enqueue_script( 'heartbeat' );
 125  wp_enqueue_script( 'customize-controls' );
 126  wp_enqueue_style( 'customize-controls' );
 127  
 128  /**
 129   * Fires when enqueuing Customizer control scripts.
 130   *
 131   * @since 3.4.0
 132   */
 133  do_action( 'customize_controls_enqueue_scripts' );
 134  
 135  $body_class = 'wp-core-ui wp-customizer js';
 136  
 137  if ( wp_is_mobile() ) :
 138      $body_class .= ' mobile';
 139      add_filter( 'admin_viewport_meta', '_customizer_mobile_viewport_meta' );
 140  endif;
 141  
 142  if ( $wp_customize->is_ios() ) {
 143      $body_class .= ' ios';
 144  }
 145  
 146  if ( is_rtl() ) {
 147      $body_class .= ' rtl';
 148  }
 149  $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
 150  $admin_color = get_user_option( 'admin_color' );
 151  $body_class .= ' admin-color-' . sanitize_html_class( is_string( $admin_color ) ? $admin_color : '', 'modern' );
 152  
 153  if ( wp_use_widgets_block_editor() ) {
 154      $body_class .= ' wp-embed-responsive';
 155  }
 156  
 157  $admin_title = sprintf( $wp_customize->get_document_title_template(), __( 'Loading&hellip;' ) );
 158  
 159  ?>
 160  <title><?php echo esc_html( $admin_title ); ?></title>
 161  
 162  <script>
 163  var ajaxurl = <?php echo wp_json_encode( admin_url( 'admin-ajax.php', 'relative' ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>,
 164      pagenow = 'customize';
 165  </script>
 166  
 167  <?php
 168  /**
 169   * Fires when Customizer control styles are printed.
 170   *
 171   * @since 3.4.0
 172   */
 173  do_action( 'customize_controls_print_styles' );
 174  
 175  /**
 176   * Fires when Customizer control scripts are printed.
 177   *
 178   * @since 3.4.0
 179   */
 180  do_action( 'customize_controls_print_scripts' );
 181  
 182  /**
 183   * Fires in head section of Customizer controls.
 184   *
 185   * @since 5.5.0
 186   */
 187  do_action( 'customize_controls_head' );
 188  
 189  /** This filter is documented in wp-admin/admin-header.php */
 190  $additional_body_class = apply_filters( 'admin_body_class', '' );
 191  if ( is_string( $additional_body_class ) && '' !== $additional_body_class ) {
 192      $body_class .= ' ' . $additional_body_class;
 193  }
 194  ?>
 195  </head>
 196  <body class="<?php echo esc_attr( $body_class ); ?>">
 197  <div class="wp-full-overlay expanded">
 198      <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
 199          <div id="customize-header-actions" class="wp-full-overlay-header">
 200              <?php
 201              $compatible_wp  = is_wp_version_compatible( $wp_customize->theme()->get( 'RequiresWP' ) );
 202              $compatible_php = is_php_version_compatible( $wp_customize->theme()->get( 'RequiresPHP' ) );
 203              ?>
 204              <?php if ( $compatible_wp && $compatible_php ) : ?>
 205                  <?php $save_text = $wp_customize->is_theme_active() ? __( 'Publish' ) : __( 'Activate &amp; Publish' ); ?>
 206                  <div id="customize-save-button-wrapper" class="customize-save-button-wrapper" >
 207                      <?php submit_button( $save_text, 'primary compact save', 'save', false ); ?>
 208                      <button id="publish-settings" class="publish-settings button-primary button-compact button dashicons dashicons-admin-generic" aria-label="<?php esc_attr_e( 'Publish Settings' ); ?>" aria-expanded="false" disabled></button>
 209                  </div>
 210              <?php else : ?>
 211                  <?php $save_text = _x( 'Cannot Activate', 'theme' ); ?>
 212                  <div id="customize-save-button-wrapper" class="customize-save-button-wrapper disabled" >
 213                      <button class="button button-primary button-compact disabled" aria-label="<?php esc_attr_e( 'Publish Settings' ); ?>" aria-expanded="false" disabled><?php echo $save_text; ?></button>
 214                  </div>
 215              <?php endif; ?>
 216              <span class="spinner"></span>
 217              <button type="button" class="customize-controls-preview-toggle">
 218                  <span class="controls"><?php _e( 'Customize' ); ?></span>
 219                  <span class="preview"><?php echo esc_html_x( 'Preview', 'noun' ); ?></span>
 220              </button>
 221              <a class="customize-controls-close" href="<?php echo esc_url( $wp_customize->get_return_url() ); ?>">
 222                  <span class="screen-reader-text">
 223                      <?php
 224                      /* translators: Hidden accessibility text. */
 225                      _e( 'Close the Customizer and go back to the previous page' );
 226                      ?>
 227                  </span>
 228              </a>
 229          </div>
 230  
 231          <div id="customize-sidebar-outer-content">
 232              <div id="customize-outer-theme-controls">
 233                  <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>
 234              </div>
 235          </div>
 236  
 237          <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 -->
 238              <div id="customize-notifications-area" class="customize-control-notifications-container">
 239                  <ul></ul>
 240              </div>
 241              <div class="wp-full-overlay-sidebar-content" tabindex="-1">
 242                  <div id="customize-info" class="accordion-section customize-info" data-block-theme="<?php echo (int) wp_is_block_theme(); ?>">
 243                      <div class="accordion-section-title">
 244                          <h2 class="preview-notice">
 245                          <?php
 246                              /* translators: %s: The site/panel title in the Customizer. */
 247                              printf( __( 'You are customizing %s' ), '<strong class="panel-title site-title">' . get_bloginfo( 'name', 'display' ) . '</strong>' );
 248                          ?>
 249                          </h2>
 250                          <button type="button" class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false"><span class="screen-reader-text">
 251                              <?php
 252                              /* translators: Hidden accessibility text. */
 253                              _e( 'Help' );
 254                              ?>
 255                          </span></button>
 256                      </div>
 257                      <div class="customize-panel-description">
 258                          <p>
 259                              <?php
 260                              _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. The Customizer is intended for use with non-block themes.' );
 261                              ?>
 262                          </p>
 263                          <p>
 264                              <?php
 265                              _e( '<a href="https://wordpress.org/documentation/article/customizer/">Documentation on Customizer</a>' );
 266                              ?>
 267                          </p>
 268                      </div>
 269                  </div>
 270  
 271                  <div id="customize-theme-controls">
 272                      <ul class="customize-pane-parent"><?php // Panels and sections are managed here via JavaScript ?></ul>
 273                  </div>
 274              </div>
 275          </div>
 276  
 277          <div id="customize-footer-actions" class="wp-full-overlay-footer">
 278              <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' ); ?>">
 279                  <span class="collapse-sidebar-arrow" aria-hidden="true"></span>
 280                  <span class="collapse-sidebar-label"><?php _ex( 'Hide Controls', 'short (~12 characters) label for hide controls button' ); ?></span>
 281              </button>
 282              <?php $previewable_devices = $wp_customize->get_previewable_devices(); ?>
 283              <?php if ( ! empty( $previewable_devices ) ) : ?>
 284              <div class="devices-wrapper" role="group" aria-label="<?php echo esc_attr_x( 'Responsive Views', 'label for responsive previews group' ); ?>">
 285                  <div class="devices">
 286                      <?php foreach ( (array) $previewable_devices as $device => $settings ) : ?>
 287                          <?php
 288                          if ( empty( $settings['label'] ) ) {
 289                              continue;
 290                          }
 291                          $active = ! empty( $settings['default'] );
 292                          $class  = 'preview-' . $device;
 293                          if ( $active ) {
 294                              $class .= ' active';
 295                          }
 296                          ?>
 297                          <button type="button" class="<?php echo esc_attr( $class ); ?>" aria-pressed="<?php echo $active ? 'true' : 'false'; ?>" data-device="<?php echo esc_attr( $device ); ?>">
 298                              <span class="devices__preview-label"><?php echo esc_html( $settings['label'] ); ?></span>
 299                          </button>
 300                      <?php endforeach; ?>
 301                  </div>
 302              </div>
 303              <?php endif; ?>
 304          </div>
 305      </form>
 306      <div id="customize-preview" class="wp-full-overlay-main"></div>
 307      <?php
 308  
 309      /**
 310       * Prints templates, control scripts, and settings in the footer.
 311       *
 312       * @since 3.4.0
 313       */
 314      do_action( 'customize_controls_print_footer_scripts' );
 315      ?>
 316  </div>
 317  </body>
 318  </html>


Generated : Mon Sep 21 08:20:32 2026 Cross-referenced by PHPXref