| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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. Instantiates 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 * Registers 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 foreach ( array( 'blogname', 'blogdescription' ) as $setting_id ) { 39 $setting = $wp_customize->get_setting( $setting_id ); 40 if ( $setting ) { 41 $setting->transport = 'postMessage'; 42 } 43 } 44 45 // Add partial for blogname. 46 $wp_customize->selective_refresh->add_partial( 47 'blogname', 48 array( 49 'selector' => '.site-title', 50 'render_callback' => array( $this, 'partial_blogname' ), 51 ) 52 ); 53 54 // Add partial for blogdescription. 55 $wp_customize->selective_refresh->add_partial( 56 'blogdescription', 57 array( 58 'selector' => '.site-description', 59 'render_callback' => array( $this, 'partial_blogdescription' ), 60 ) 61 ); 62 63 // Add "display_title_and_tagline" setting for displaying the site-title & tagline. 64 $wp_customize->add_setting( 65 'display_title_and_tagline', 66 array( 67 'capability' => 'edit_theme_options', 68 'default' => true, 69 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ), 70 ) 71 ); 72 73 // Add control for the "display_title_and_tagline" setting. 74 $wp_customize->add_control( 75 'display_title_and_tagline', 76 array( 77 'type' => 'checkbox', 78 'section' => 'title_tagline', 79 'label' => esc_html__( 'Display Site Title & Tagline', 'twentytwentyone' ), 80 ) 81 ); 82 83 /** 84 * Add excerpt or full text selector to customizer 85 */ 86 $wp_customize->add_section( 87 'excerpt_settings', 88 array( 89 'title' => esc_html__( 'Excerpt Settings', 'twentytwentyone' ), 90 'priority' => 120, 91 ) 92 ); 93 94 $wp_customize->add_setting( 95 'display_excerpt_or_full_post', 96 array( 97 'capability' => 'edit_theme_options', 98 'default' => 'excerpt', 99 'sanitize_callback' => static function ( $value ) { 100 return 'excerpt' === $value || 'full' === $value ? $value : 'excerpt'; 101 }, 102 ) 103 ); 104 105 $wp_customize->add_control( 106 'display_excerpt_or_full_post', 107 array( 108 'type' => 'radio', 109 'section' => 'excerpt_settings', 110 'label' => esc_html__( 'On Archive Pages, posts show:', 'twentytwentyone' ), 111 'choices' => array( 112 'excerpt' => esc_html__( 'Summary', 'twentytwentyone' ), 113 'full' => esc_html__( 'Full text', 'twentytwentyone' ), 114 ), 115 ) 116 ); 117 118 // Background color. 119 // Include the custom control class. 120 require_once get_theme_file_path( 'classes/class-twenty-twenty-one-customize-color-control.php' ); 121 122 // Register the custom control. 123 $wp_customize->register_control_type( 'Twenty_Twenty_One_Customize_Color_Control' ); 124 125 // Get the palette from theme-supports. 126 $palette = get_theme_support( 'editor-color-palette' ); 127 128 // Build the colors array from theme-support. 129 $colors = array(); 130 if ( isset( $palette[0] ) && is_array( $palette[0] ) ) { 131 foreach ( $palette[0] as $palette_color ) { 132 $colors[] = $palette_color['color']; 133 } 134 } 135 136 // Add the control. Overrides the default background-color control. 137 $wp_customize->add_control( 138 new Twenty_Twenty_One_Customize_Color_Control( 139 $wp_customize, 140 'background_color', 141 array( 142 'label' => esc_html_x( 'Background color', 'Customizer control', 'twentytwentyone' ), 143 'section' => 'colors', 144 'palette' => $colors, 145 ) 146 ) 147 ); 148 } 149 150 /** 151 * Sanitizes a boolean for checkbox. 152 * 153 * @since Twenty Twenty-One 1.0 154 * 155 * @param bool $checked Whether or not a box is checked. 156 * @return bool 157 */ 158 public static function sanitize_checkbox( $checked = null ) { 159 return (bool) isset( $checked ) && true === $checked; 160 } 161 162 /** 163 * Renders the site title for the selective refresh partial. 164 * 165 * @since Twenty Twenty-One 1.0 166 * 167 * @return void 168 */ 169 public function partial_blogname() { 170 bloginfo( 'name' ); 171 } 172 173 /** 174 * Renders the site tagline for the selective refresh partial. 175 * 176 * @since Twenty Twenty-One 1.0 177 * 178 * @return void 179 */ 180 public function partial_blogdescription() { 181 bloginfo( 'description' ); 182 } 183 } 184 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon Jun 15 08:20:09 2026 | Cross-referenced by PHPXref |