[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Twenty Nineteen: Customizer
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Nineteen
   7   * @since Twenty Nineteen 1.0
   8   */
   9  
  10  /**
  11   * Add 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 twentynineteen_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      if ( isset( $wp_customize->selective_refresh ) ) {
  21          $wp_customize->selective_refresh->add_partial(
  22              'blogname',
  23              array(
  24                  'selector'        => '.site-title a',
  25                  'render_callback' => 'twentynineteen_customize_partial_blogname',
  26              )
  27          );
  28          $wp_customize->selective_refresh->add_partial(
  29              'blogdescription',
  30              array(
  31                  'selector'        => '.site-description',
  32                  'render_callback' => 'twentynineteen_customize_partial_blogdescription',
  33              )
  34          );
  35      }
  36  
  37      /**
  38       * Primary color.
  39       */
  40      $wp_customize->add_setting(
  41          'primary_color',
  42          array(
  43              'default'           => 'default',
  44              'transport'         => 'postMessage',
  45              'sanitize_callback' => 'twentynineteen_sanitize_color_option',
  46          )
  47      );
  48  
  49      $wp_customize->add_control(
  50          'primary_color',
  51          array(
  52              'type'     => 'radio',
  53              'label'    => __( 'Primary Color', 'twentynineteen' ),
  54              'choices'  => array(
  55                  'default' => _x( 'Default', 'primary color', 'twentynineteen' ),
  56                  'custom'  => _x( 'Custom', 'primary color', 'twentynineteen' ),
  57              ),
  58              'section'  => 'colors',
  59              'priority' => 5,
  60          )
  61      );
  62  
  63      // Add primary color hue setting and control.
  64      $wp_customize->add_setting(
  65          'primary_color_hue',
  66          array(
  67              'default'           => 199,
  68              'transport'         => 'postMessage',
  69              'sanitize_callback' => 'absint',
  70          )
  71      );
  72  
  73      $wp_customize->add_control(
  74          new WP_Customize_Color_Control(
  75              $wp_customize,
  76              'primary_color_hue',
  77              array(
  78                  'label'       => __( 'Custom Color', 'twentynineteen' ),
  79                  'description' => __( 'Apply a custom color for buttons, links, featured images, etc.', 'twentynineteen' ),
  80                  'section'     => 'colors',
  81                  'mode'        => 'hue',
  82              )
  83          )
  84      );
  85  
  86      // Add image filter setting and control.
  87      $wp_customize->add_setting(
  88          'image_filter',
  89          array(
  90              'default'           => 1,
  91              'sanitize_callback' => 'absint',
  92              'transport'         => 'postMessage',
  93          )
  94      );
  95  
  96      $wp_customize->add_control(
  97          'image_filter',
  98          array(
  99              'label'   => __( 'Apply a filter to featured images using the primary color', 'twentynineteen' ),
 100              'section' => 'colors',
 101              'type'    => 'checkbox',
 102          )
 103      );
 104  }
 105  add_action( 'customize_register', 'twentynineteen_customize_register' );
 106  
 107  /**
 108   * Render the site title for the selective refresh partial.
 109   *
 110   * @return void
 111   */
 112  function twentynineteen_customize_partial_blogname() {
 113      bloginfo( 'name' );
 114  }
 115  
 116  /**
 117   * Render the site tagline for the selective refresh partial.
 118   *
 119   * @return void
 120   */
 121  function twentynineteen_customize_partial_blogdescription() {
 122      bloginfo( 'description' );
 123  }
 124  
 125  /**
 126   * Bind JS handlers to instantly live-preview changes.
 127   */
 128  function twentynineteen_customize_preview_js() {
 129      wp_enqueue_script( 'twentynineteen-customize-preview', get_theme_file_uri( '/js/customize-preview.js' ), array( 'customize-preview' ), '20181214', array( 'in_footer' => true ) );
 130  }
 131  add_action( 'customize_preview_init', 'twentynineteen_customize_preview_js' );
 132  
 133  /**
 134   * Load dynamic logic for the customizer controls area.
 135   */
 136  function twentynineteen_panels_js() {
 137      wp_enqueue_script( 'twentynineteen-customize-controls', get_theme_file_uri( '/js/customize-controls.js' ), array(), '20181214', array( 'in_footer' => true ) );
 138  }
 139  add_action( 'customize_controls_enqueue_scripts', 'twentynineteen_panels_js' );
 140  
 141  /**
 142   * Sanitize custom color choice.
 143   *
 144   * @param string $choice Whether image filter is active.
 145   * @return string
 146   */
 147  function twentynineteen_sanitize_color_option( $choice ) {
 148      $valid = array(
 149          'default',
 150          'custom',
 151      );
 152  
 153      if ( in_array( $choice, $valid, true ) ) {
 154          return $choice;
 155      }
 156  
 157      return 'default';
 158  }


Generated : Sat Jul 26 08:20:01 2025 Cross-referenced by PHPXref