[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> class-wp-customize-section.php (source)

   1  <?php
   2  /**
   3   * WordPress Customize Section classes
   4   *
   5   * @package WordPress
   6   * @subpackage Customize
   7   * @since 3.4.0
   8   */
   9  
  10  /**
  11   * Customize Section class.
  12   *
  13   * A UI container for controls, managed by the WP_Customize_Manager class.
  14   *
  15   * @since 3.4.0
  16   *
  17   * @see WP_Customize_Manager
  18   */
  19  class WP_Customize_Section {
  20  
  21      /**
  22       * Incremented with each new class instantiation, then stored in $instance_number.
  23       *
  24       * Used when sorting two instances whose priorities are equal.
  25       *
  26       * @since 4.1.0
  27       * @var int
  28       */
  29      protected static $instance_count = 0;
  30  
  31      /**
  32       * Order in which this instance was created in relation to other instances.
  33       *
  34       * @since 4.1.0
  35       * @var int
  36       */
  37      public $instance_number;
  38  
  39      /**
  40       * WP_Customize_Manager instance.
  41       *
  42       * @since 3.4.0
  43       * @var WP_Customize_Manager
  44       */
  45      public $manager;
  46  
  47      /**
  48       * Unique identifier.
  49       *
  50       * @since 3.4.0
  51       * @var string
  52       */
  53      public $id;
  54  
  55      /**
  56       * Priority of the section which informs load order of sections.
  57       *
  58       * @since 3.4.0
  59       * @var integer
  60       */
  61      public $priority = 160;
  62  
  63      /**
  64       * Panel in which to show the section, making it a sub-section.
  65       *
  66       * @since 4.0.0
  67       * @var string
  68       */
  69      public $panel = '';
  70  
  71      /**
  72       * Capability required for the section.
  73       *
  74       * @since 3.4.0
  75       * @var string
  76       */
  77      public $capability = 'edit_theme_options';
  78  
  79      /**
  80       * Theme feature support for the section.
  81       *
  82       * @since 3.4.0
  83       * @var string|array
  84       */
  85      public $theme_supports = '';
  86  
  87      /**
  88       * Title of the section to show in UI.
  89       *
  90       * @since 3.4.0
  91       * @var string
  92       */
  93      public $title = '';
  94  
  95      /**
  96       * Description to show in the UI.
  97       *
  98       * @since 3.4.0
  99       * @var string
 100       */
 101      public $description = '';
 102  
 103      /**
 104       * Customizer controls for this section.
 105       *
 106       * @since 3.4.0
 107       * @var array
 108       */
 109      public $controls;
 110  
 111      /**
 112       * Type of this section.
 113       *
 114       * @since 4.1.0
 115       * @var string
 116       */
 117      public $type = 'default';
 118  
 119      /**
 120       * Active callback.
 121       *
 122       * @since 4.1.0
 123       *
 124       * @see WP_Customize_Section::active()
 125       *
 126       * @var callable Callback is called with one argument, the instance of
 127       *               WP_Customize_Section, and returns bool to indicate whether
 128       *               the section is active (such as it relates to the URL currently
 129       *               being previewed).
 130       */
 131      public $active_callback = '';
 132  
 133      /**
 134       * Show the description or hide it behind the help icon.
 135       *
 136       * @since 4.7.0
 137       *
 138       * @var bool Indicates whether the Section's description should be
 139       *           hidden behind a help icon ("?") in the Section header,
 140       *           similar to how help icons are displayed on Panels.
 141       */
 142      public $description_hidden = false;
 143  
 144      /**
 145       * Constructor.
 146       *
 147       * Any supplied $args override class property defaults.
 148       *
 149       * @since 3.4.0
 150       *
 151       * @param WP_Customize_Manager $manager Customizer bootstrap instance.
 152       * @param string               $id      An specific ID of the section.
 153       * @param array                $args    Section arguments.
 154       */
 155  	public function __construct( $manager, $id, $args = array() ) {
 156          $keys = array_keys( get_object_vars( $this ) );
 157          foreach ( $keys as $key ) {
 158              if ( isset( $args[ $key ] ) ) {
 159                  $this->$key = $args[ $key ];
 160              }
 161          }
 162  
 163          $this->manager = $manager;
 164          $this->id      = $id;
 165          if ( empty( $this->active_callback ) ) {
 166              $this->active_callback = array( $this, 'active_callback' );
 167          }
 168          self::$instance_count += 1;
 169          $this->instance_number = self::$instance_count;
 170  
 171          $this->controls = array(); // Users cannot customize the $controls array.
 172      }
 173  
 174      /**
 175       * Check whether section is active to current Customizer preview.
 176       *
 177       * @since 4.1.0
 178       *
 179       * @return bool Whether the section is active to the current preview.
 180       */
 181  	final public function active() {
 182          $section = $this;
 183          $active  = call_user_func( $this->active_callback, $this );
 184  
 185          /**
 186           * Filters response of WP_Customize_Section::active().
 187           *
 188           * @since 4.1.0
 189           *
 190           * @param bool                 $active  Whether the Customizer section is active.
 191           * @param WP_Customize_Section $section WP_Customize_Section instance.
 192           */
 193          $active = apply_filters( 'customize_section_active', $active, $section );
 194  
 195          return $active;
 196      }
 197  
 198      /**
 199       * Default callback used when invoking WP_Customize_Section::active().
 200       *
 201       * Subclasses can override this with their specific logic, or they may provide
 202       * an 'active_callback' argument to the constructor.
 203       *
 204       * @since 4.1.0
 205       *
 206       * @return true Always true.
 207       */
 208  	public function active_callback() {
 209          return true;
 210      }
 211  
 212      /**
 213       * Gather the parameters passed to client JavaScript via JSON.
 214       *
 215       * @since 4.1.0
 216       *
 217       * @return array The array to be exported to the client as JSON.
 218       */
 219  	public function json() {
 220          $array                   = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'panel', 'type', 'description_hidden' ) );
 221          $array['title']          = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
 222          $array['content']        = $this->get_content();
 223          $array['active']         = $this->active();
 224          $array['instanceNumber'] = $this->instance_number;
 225  
 226          if ( $this->panel ) {
 227              /* translators: &#9656; is the unicode right-pointing triangle. %s: Section title in the Customizer. */
 228              $array['customizeAction'] = sprintf( __( 'Customizing &#9656; %s' ), esc_html( $this->manager->get_panel( $this->panel )->title ) );
 229          } else {
 230              $array['customizeAction'] = __( 'Customizing' );
 231          }
 232  
 233          return $array;
 234      }
 235  
 236      /**
 237       * Checks required user capabilities and whether the theme has the
 238       * feature support required by the section.
 239       *
 240       * @since 3.4.0
 241       *
 242       * @return bool False if theme doesn't support the section or user doesn't have the capability.
 243       */
 244  	final public function check_capabilities() {
 245          if ( $this->capability && ! current_user_can( $this->capability ) ) {
 246              return false;
 247          }
 248  
 249          if ( $this->theme_supports && ! current_theme_supports( ... (array) $this->theme_supports ) ) {
 250              return false;
 251          }
 252  
 253          return true;
 254      }
 255  
 256      /**
 257       * Get the section's content for insertion into the Customizer pane.
 258       *
 259       * @since 4.1.0
 260       *
 261       * @return string Contents of the section.
 262       */
 263  	final public function get_content() {
 264          ob_start();
 265          $this->maybe_render();
 266          return trim( ob_get_clean() );
 267      }
 268  
 269      /**
 270       * Check capabilities and render the section.
 271       *
 272       * @since 3.4.0
 273       */
 274  	final public function maybe_render() {
 275          if ( ! $this->check_capabilities() ) {
 276              return;
 277          }
 278  
 279          /**
 280           * Fires before rendering a Customizer section.
 281           *
 282           * @since 3.4.0
 283           *
 284           * @param WP_Customize_Section $this WP_Customize_Section instance.
 285           */
 286          do_action( 'customize_render_section', $this );
 287          /**
 288           * Fires before rendering a specific Customizer section.
 289           *
 290           * The dynamic portion of the hook name, `$this->id`, refers to the ID
 291           * of the specific Customizer section to be rendered.
 292           *
 293           * @since 3.4.0
 294           */
 295          do_action( "customize_render_section_{$this->id}" );
 296  
 297          $this->render();
 298      }
 299  
 300      /**
 301       * Render the section UI in a subclass.
 302       *
 303       * Sections are now rendered in JS by default, see WP_Customize_Section::print_template().
 304       *
 305       * @since 3.4.0
 306       */
 307  	protected function render() {}
 308  
 309      /**
 310       * Render the section's JS template.
 311       *
 312       * This function is only run for section types that have been registered with
 313       * WP_Customize_Manager::register_section_type().
 314       *
 315       * @since 4.3.0
 316       *
 317       * @see WP_Customize_Manager::render_template()
 318       */
 319  	public function print_template() {
 320          ?>
 321          <script type="text/html" id="tmpl-customize-section-<?php echo $this->type; ?>">
 322              <?php $this->render_template(); ?>
 323          </script>
 324          <?php
 325      }
 326  
 327      /**
 328       * An Underscore (JS) template for rendering this section.
 329       *
 330       * Class variables for this section class are available in the `data` JS object;
 331       * export custom variables by overriding WP_Customize_Section::json().
 332       *
 333       * @since 4.3.0
 334       *
 335       * @see WP_Customize_Section::print_template()
 336       */
 337  	protected function render_template() {
 338          ?>
 339          <li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }}">
 340              <h3 class="accordion-section-title" tabindex="0">
 341                  {{ data.title }}
 342                  <span class="screen-reader-text"><?php _e( 'Press return or enter to open this section' ); ?></span>
 343              </h3>
 344              <ul class="accordion-section-content">
 345                  <li class="customize-section-description-container section-meta <# if ( data.description_hidden ) { #>customize-info<# } #>">
 346                      <div class="customize-section-title">
 347                          <button class="customize-section-back" tabindex="-1">
 348                              <span class="screen-reader-text"><?php _e( 'Back' ); ?></span>
 349                          </button>
 350                          <h3>
 351                              <span class="customize-action">
 352                                  {{{ data.customizeAction }}}
 353                              </span>
 354                              {{ data.title }}
 355                          </h3>
 356                          <# if ( data.description && data.description_hidden ) { #>
 357                              <button type="button" class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button>
 358                              <div class="description customize-section-description">
 359                                  {{{ data.description }}}
 360                              </div>
 361                          <# } #>
 362  
 363                          <div class="customize-control-notifications-container"></div>
 364                      </div>
 365  
 366                      <# if ( data.description && ! data.description_hidden ) { #>
 367                          <div class="description customize-section-description">
 368                              {{{ data.description }}}
 369                          </div>
 370                      <# } #>
 371                  </li>
 372              </ul>
 373          </li>
 374          <?php
 375      }
 376  }
 377  
 378  /** WP_Customize_Themes_Section class */
 379  require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-themes-section.php' );
 380  
 381  /** WP_Customize_Sidebar_Section class */
 382  require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php' );
 383  
 384  /** WP_Customize_Nav_Menu_Section class */
 385  require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' );
 386  
 387  /**
 388   * WP_Customize_New_Menu_Section class
 389   *
 390   * As this file is deprecated, it will trigger a deprecation notice if instantiated. In a subsequent
 391   * release, the require_once() here will be removed and _deprecated_file() will be called if file is
 392   * required at all.
 393   *
 394   * @deprecated 4.9.0 This file is no longer used due to new menu creation UX.
 395   */
 396  require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-section.php' );


Generated: Thu Sep 19 01:00:03 2019 Cross-referenced by PHPXref 0.7.1