[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/twentytwentyone/classes/ -> class-twenty-twenty-one-customize.php (source)

   1  <?php
   2  /**
   3   * Customizer settings for this theme.
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Twenty_One
   7   * @since 1.0.0
   8   */
   9  
  10  if ( ! class_exists( 'Twenty_Twenty_One_Customize' ) ) {
  11      /**
  12       * Customizer Settings.
  13       *
  14       * @since 1.0.0
  15       */
  16      class Twenty_Twenty_One_Customize {
  17  
  18          /**
  19           * Constructor. Instantiate the object.
  20           *
  21           * @access public
  22           *
  23           * @since 1.0.0
  24           */
  25  		public function __construct() {
  26              add_action( 'customize_register', array( $this, 'register' ) );
  27          }
  28  
  29          /**
  30           * Register customizer options.
  31           *
  32           * @access public
  33           *
  34           * @since 1.0.0
  35           *
  36           * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  37           *
  38           * @return void
  39           */
  40  		public function register( $wp_customize ) {
  41  
  42              // Change site-title & description to postMessage.
  43              $wp_customize->get_setting( 'blogname' )->transport        = 'postMessage'; // @phpstan-ignore-line. Assume that this setting exists.
  44              $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; // @phpstan-ignore-line. Assume that this setting exists.
  45  
  46              // Add partial for blogname.
  47              $wp_customize->selective_refresh->add_partial(
  48                  'blogname',
  49                  array(
  50                      'selector'        => '.site-title',
  51                      'render_callback' => array( $this, 'partial_blogname' ),
  52                  )
  53              );
  54  
  55              // Add partial for blogdescription.
  56              $wp_customize->selective_refresh->add_partial(
  57                  'blogdescription',
  58                  array(
  59                      'selector'        => '.site-description',
  60                      'render_callback' => array( $this, 'partial_blogdescription' ),
  61                  )
  62              );
  63  
  64              // Add "display_title_and_tagline" setting for displaying the site-title & tagline.
  65              $wp_customize->add_setting(
  66                  'display_title_and_tagline',
  67                  array(
  68                      'capability'        => 'edit_theme_options',
  69                      'default'           => true,
  70                      'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  71                  )
  72              );
  73  
  74              // Add control for the "display_title_and_tagline" setting.
  75              $wp_customize->add_control(
  76                  'display_title_and_tagline',
  77                  array(
  78                      'type'    => 'checkbox',
  79                      'section' => 'title_tagline',
  80                      'label'   => esc_html__( 'Display Site Title & Tagline', 'twentytwentyone' ),
  81                  )
  82              );
  83  
  84              /**
  85               * Add excerpt or full text selector to customizer
  86               */
  87              $wp_customize->add_section(
  88                  'excerpt_settings',
  89                  array(
  90                      'title'    => esc_html__( 'Excerpt Settings', 'twentytwentyone' ),
  91                      'priority' => 120,
  92                  )
  93              );
  94  
  95              $wp_customize->add_setting(
  96                  'display_excerpt_or_full_post',
  97                  array(
  98                      'capability'        => 'edit_theme_options',
  99                      'default'           => 'excerpt',
 100                      'sanitize_callback' => function( $value ) {
 101                          return 'excerpt' === $value || 'full' === $value ? $value : 'excerpt';
 102                      },
 103                  )
 104              );
 105  
 106              $wp_customize->add_control(
 107                  'display_excerpt_or_full_post',
 108                  array(
 109                      'type'    => 'radio',
 110                      'section' => 'excerpt_settings',
 111                      'label'   => esc_html__( 'On Archive Pages, posts show:', 'twentytwentyone' ),
 112                      'choices' => array(
 113                          'excerpt' => esc_html__( 'Summary', 'twentytwentyone' ),
 114                          'full'    => esc_html__( 'Full text', 'twentytwentyone' ),
 115                      ),
 116                  )
 117              );
 118  
 119              // Background color.
 120              // Include the custom control class.
 121              include_once get_theme_file_path( 'classes/class-twenty-twenty-one-customize-color-control.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
 122  
 123              // Register the custom control.
 124              $wp_customize->register_control_type( 'Twenty_Twenty_One_Customize_Color_Control' );
 125  
 126              // Get the palette from theme-supports.
 127              $palette = get_theme_support( 'editor-color-palette' );
 128  
 129              // Build the colors array from theme-support.
 130              $colors = array();
 131              if ( isset( $palette[0] ) && is_array( $palette[0] ) ) {
 132                  foreach ( $palette[0] as $palette_color ) {
 133                      $colors[] = $palette_color['color'];
 134                  }
 135              }
 136  
 137              // Add the control. Overrides the default background-color control.
 138              $wp_customize->add_control(
 139                  new Twenty_Twenty_One_Customize_Color_Control(
 140                      $wp_customize,
 141                      'background_color',
 142                      array(
 143                          'label'   => esc_html_x( 'Background color', 'Customizer control', 'twentytwentyone' ),
 144                          'section' => 'colors',
 145                          'palette' => $colors,
 146                      )
 147                  )
 148              );
 149          }
 150  
 151          /**
 152           * Sanitize boolean for checkbox.
 153           *
 154           * @access public
 155           *
 156           * @since 1.0.0
 157           *
 158           * @param bool $checked Whether or not a box is checked.
 159           *
 160           * @return bool
 161           */
 162  		public static function sanitize_checkbox( $checked = null ) {
 163              return (bool) isset( $checked ) && true === $checked;
 164          }
 165  
 166          /**
 167           * Render the site title for the selective refresh partial.
 168           *
 169           * @access public
 170           *
 171           * @since 1.0.0
 172           *
 173           * @return void
 174           */
 175  		public function partial_blogname() {
 176              bloginfo( 'name' );
 177          }
 178  
 179          /**
 180           * Render the site tagline for the selective refresh partial.
 181           *
 182           * @access public
 183           *
 184           * @since 1.0.0
 185           *
 186           * @return void
 187           */
 188  		public function partial_blogdescription() {
 189              bloginfo( 'description' );
 190          }
 191      }
 192  }


Generated : Wed Dec 2 08:20:02 2020 Cross-referenced by PHPXref