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


Generated : Fri Apr 26 08:20:02 2024 Cross-referenced by PHPXref