[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/twentyseventeen/inc/ -> customizer.php (source)

   1  <?php
   2  /**
   3   * Twenty Seventeen: Customizer
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Seventeen
   7   * @since Twenty Seventeen 1.0
   8   */
   9  
  10  /**
  11   * Adds postMessage support for site title and description for the Theme Customizer.
  12   *
  13   * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  14   */
  15  function twentyseventeen_customize_register( $wp_customize ) {
  16      $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
  17      $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
  18      $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  19  
  20      $wp_customize->selective_refresh->add_partial(
  21          'blogname',
  22          array(
  23              'selector'        => '.site-title a',
  24              'render_callback' => 'twentyseventeen_customize_partial_blogname',
  25          )
  26      );
  27      $wp_customize->selective_refresh->add_partial(
  28          'blogdescription',
  29          array(
  30              'selector'        => '.site-description',
  31              'render_callback' => 'twentyseventeen_customize_partial_blogdescription',
  32          )
  33      );
  34  
  35      /**
  36       * Custom colors.
  37       */
  38      $wp_customize->add_setting(
  39          'colorscheme',
  40          array(
  41              'default'           => 'light',
  42              'transport'         => 'postMessage',
  43              'sanitize_callback' => 'twentyseventeen_sanitize_colorscheme',
  44          )
  45      );
  46  
  47      $wp_customize->add_setting(
  48          'colorscheme_hue',
  49          array(
  50              'default'           => 250,
  51              'transport'         => 'postMessage',
  52              'sanitize_callback' => 'absint', // The hue is stored as a positive integer.
  53          )
  54      );
  55  
  56      $wp_customize->add_control(
  57          'colorscheme',
  58          array(
  59              'type'     => 'radio',
  60              'label'    => __( 'Color Scheme', 'twentyseventeen' ),
  61              'choices'  => array(
  62                  'light'  => __( 'Light', 'twentyseventeen' ),
  63                  'dark'   => __( 'Dark', 'twentyseventeen' ),
  64                  'custom' => __( 'Custom', 'twentyseventeen' ),
  65              ),
  66              'section'  => 'colors',
  67              'priority' => 5,
  68          )
  69      );
  70  
  71      $wp_customize->add_control(
  72          new WP_Customize_Color_Control(
  73              $wp_customize,
  74              'colorscheme_hue',
  75              array(
  76                  'label'    => __( 'Hue', 'twentyseventeen' ),
  77                  'mode'     => 'hue',
  78                  'section'  => 'colors',
  79                  'priority' => 6,
  80              )
  81          )
  82      );
  83  
  84      /**
  85       * Theme options.
  86       */
  87      $wp_customize->add_section(
  88          'theme_options',
  89          array(
  90              'title'    => __( 'Theme Options', 'twentyseventeen' ),
  91              'priority' => 130, // Before Additional CSS.
  92          )
  93      );
  94  
  95      $wp_customize->add_setting(
  96          'page_layout',
  97          array(
  98              'default'           => 'two-column',
  99              'sanitize_callback' => 'twentyseventeen_sanitize_page_layout',
 100              'transport'         => 'postMessage',
 101          )
 102      );
 103  
 104      $wp_customize->add_control(
 105          'page_layout',
 106          array(
 107              'label'           => __( 'Page Layout', 'twentyseventeen' ),
 108              'section'         => 'theme_options',
 109              'type'            => 'radio',
 110              'description'     => __( 'When the two-column layout is assigned, the page title is in one column and content is in the other.', 'twentyseventeen' ),
 111              'choices'         => array(
 112                  'one-column' => __( 'One Column', 'twentyseventeen' ),
 113                  'two-column' => __( 'Two Column', 'twentyseventeen' ),
 114              ),
 115              'active_callback' => 'twentyseventeen_is_view_with_layout_option',
 116          )
 117      );
 118  
 119      /**
 120       * Filters the number of front page sections in Twenty Seventeen.
 121       *
 122       * @since Twenty Seventeen 1.0
 123       *
 124       * @param int $num_sections Number of front page sections.
 125       */
 126      $num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
 127  
 128      // Create a setting and control for each of the sections available in the theme.
 129      for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) {
 130          $wp_customize->add_setting(
 131              'panel_' . $i,
 132              array(
 133                  'default'           => false,
 134                  'sanitize_callback' => 'absint',
 135                  'transport'         => 'postMessage',
 136              )
 137          );
 138  
 139          $wp_customize->add_control(
 140              'panel_' . $i,
 141              array(
 142                  /* translators: %d: The front page section number. */
 143                  'label'           => sprintf( __( 'Front Page Section %d Content', 'twentyseventeen' ), $i ),
 144                  'description'     => ( 1 !== $i ? '' : __( 'Select pages to feature in each area from the dropdowns. Add an image to a section by setting a featured image in the page editor. Empty sections will not be displayed.', 'twentyseventeen' ) ),
 145                  'section'         => 'theme_options',
 146                  'type'            => 'dropdown-pages',
 147                  'allow_addition'  => true,
 148                  'active_callback' => 'twentyseventeen_is_frontpage',
 149              )
 150          );
 151  
 152          $wp_customize->selective_refresh->add_partial(
 153              'panel_' . $i,
 154              array(
 155                  'selector'            => '#panel' . $i,
 156                  'render_callback'     => 'twentyseventeen_front_page_section',
 157                  'container_inclusive' => true,
 158              )
 159          );
 160      }
 161  }
 162  add_action( 'customize_register', 'twentyseventeen_customize_register' );
 163  
 164  /**
 165   * Sanitizes the page layout options.
 166   *
 167   * @param string $input Page layout.
 168   */
 169  function twentyseventeen_sanitize_page_layout( $input ) {
 170      $valid = array(
 171          'one-column' => __( 'One Column', 'twentyseventeen' ),
 172          'two-column' => __( 'Two Column', 'twentyseventeen' ),
 173      );
 174  
 175      if ( array_key_exists( $input, $valid ) ) {
 176          return $input;
 177      }
 178  
 179      return '';
 180  }
 181  
 182  /**
 183   * Sanitizes the colorscheme.
 184   *
 185   * @param string $input Color scheme.
 186   */
 187  function twentyseventeen_sanitize_colorscheme( $input ) {
 188      $valid = array( 'light', 'dark', 'custom' );
 189  
 190      if ( in_array( $input, $valid, true ) ) {
 191          return $input;
 192      }
 193  
 194      return 'light';
 195  }
 196  
 197  /**
 198   * Renders the site title for the selective refresh partial.
 199   *
 200   * @since Twenty Seventeen 1.0
 201   *
 202   * @see twentyseventeen_customize_register()
 203   *
 204   * @return void
 205   */
 206  function twentyseventeen_customize_partial_blogname() {
 207      bloginfo( 'name' );
 208  }
 209  
 210  /**
 211   * Renders the site tagline for the selective refresh partial.
 212   *
 213   * @since Twenty Seventeen 1.0
 214   *
 215   * @see twentyseventeen_customize_register()
 216   *
 217   * @return void
 218   */
 219  function twentyseventeen_customize_partial_blogdescription() {
 220      bloginfo( 'description' );
 221  }
 222  
 223  /**
 224   * Returns whether we're previewing the front page and it's a static page.
 225   *
 226   * This function is an alias for twentyseventeen_is_frontpage().
 227   *
 228   * @since Twenty Seventeen 1.0
 229   * @since Twenty Seventeen 3.3 Converted function to an alias.
 230   *
 231   * @return bool Whether the current page is the front page and static.
 232   */
 233  function twentyseventeen_is_static_front_page() {
 234      return twentyseventeen_is_frontpage();
 235  }
 236  
 237  /**
 238   * Returns whether we're on a view that supports a one or two column layout.
 239   */
 240  function twentyseventeen_is_view_with_layout_option() {
 241      // This option is available on all pages. It's also available on archives when there isn't a sidebar.
 242      return ( is_page() || ( is_archive() && ! is_active_sidebar( 'sidebar-1' ) ) );
 243  }
 244  
 245  /**
 246   * Binds JS handlers to instantly live-preview changes.
 247   */
 248  function twentyseventeen_customize_preview_js() {
 249      wp_enqueue_script( 'twentyseventeen-customize-preview', get_theme_file_uri( '/assets/js/customize-preview.js' ), array( 'customize-preview' ), '20161002', array( 'in_footer' => true ) );
 250  }
 251  add_action( 'customize_preview_init', 'twentyseventeen_customize_preview_js' );
 252  
 253  /**
 254   * Loads dynamic logic for the customizer controls area.
 255   */
 256  function twentyseventeen_panels_js() {
 257      wp_enqueue_script( 'twentyseventeen-customize-controls', get_theme_file_uri( '/assets/js/customize-controls.js' ), array(), '20161020', array( 'in_footer' => true ) );
 258  }
 259  add_action( 'customize_controls_enqueue_scripts', 'twentyseventeen_panels_js' );


Generated : Wed Aug 13 08:20:01 2025 Cross-referenced by PHPXref