[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
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 * 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 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 'mode' => 'hue', 77 'section' => 'colors', 78 'priority' => 6, 79 ) 80 ) 81 ); 82 83 /** 84 * Theme options. 85 */ 86 $wp_customize->add_section( 87 'theme_options', 88 array( 89 'title' => __( 'Theme Options', 'twentyseventeen' ), 90 'priority' => 130, // Before Additional CSS. 91 ) 92 ); 93 94 $wp_customize->add_setting( 95 'page_layout', 96 array( 97 'default' => 'two-column', 98 'sanitize_callback' => 'twentyseventeen_sanitize_page_layout', 99 'transport' => 'postMessage', 100 ) 101 ); 102 103 $wp_customize->add_control( 104 'page_layout', 105 array( 106 'label' => __( 'Page Layout', 'twentyseventeen' ), 107 'section' => 'theme_options', 108 'type' => 'radio', 109 'description' => __( 'When the two-column layout is assigned, the page title is in one column and content is in the other.', 'twentyseventeen' ), 110 'choices' => array( 111 'one-column' => __( 'One Column', 'twentyseventeen' ), 112 'two-column' => __( 'Two Column', 'twentyseventeen' ), 113 ), 114 'active_callback' => 'twentyseventeen_is_view_with_layout_option', 115 ) 116 ); 117 118 /** 119 * Filters the number of front page sections in Twenty Seventeen. 120 * 121 * @since Twenty Seventeen 1.0 122 * 123 * @param int $num_sections Number of front page sections. 124 */ 125 $num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 ); 126 127 // Create a setting and control for each of the sections available in the theme. 128 for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) { 129 $wp_customize->add_setting( 130 'panel_' . $i, 131 array( 132 'default' => false, 133 'sanitize_callback' => 'absint', 134 'transport' => 'postMessage', 135 ) 136 ); 137 138 $wp_customize->add_control( 139 'panel_' . $i, 140 array( 141 /* translators: %d: The front page section number. */ 142 'label' => sprintf( __( 'Front Page Section %d Content', 'twentyseventeen' ), $i ), 143 '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' ) ), 144 'section' => 'theme_options', 145 'type' => 'dropdown-pages', 146 'allow_addition' => true, 147 'active_callback' => 'twentyseventeen_is_static_front_page', 148 ) 149 ); 150 151 $wp_customize->selective_refresh->add_partial( 152 'panel_' . $i, 153 array( 154 'selector' => '#panel' . $i, 155 'render_callback' => 'twentyseventeen_front_page_section', 156 'container_inclusive' => true, 157 ) 158 ); 159 } 160 } 161 add_action( 'customize_register', 'twentyseventeen_customize_register' ); 162 163 /** 164 * Sanitize the page layout options. 165 * 166 * @param string $input Page layout. 167 */ 168 function twentyseventeen_sanitize_page_layout( $input ) { 169 $valid = array( 170 'one-column' => __( 'One Column', 'twentyseventeen' ), 171 'two-column' => __( 'Two Column', 'twentyseventeen' ), 172 ); 173 174 if ( array_key_exists( $input, $valid ) ) { 175 return $input; 176 } 177 178 return ''; 179 } 180 181 /** 182 * Sanitize the colorscheme. 183 * 184 * @param string $input Color scheme. 185 */ 186 function twentyseventeen_sanitize_colorscheme( $input ) { 187 $valid = array( 'light', 'dark', 'custom' ); 188 189 if ( in_array( $input, $valid, true ) ) { 190 return $input; 191 } 192 193 return 'light'; 194 } 195 196 /** 197 * Render the site title for the selective refresh partial. 198 * 199 * @since Twenty Seventeen 1.0 200 * 201 * @see twentyseventeen_customize_register() 202 * 203 * @return void 204 */ 205 function twentyseventeen_customize_partial_blogname() { 206 bloginfo( 'name' ); 207 } 208 209 /** 210 * Render the site tagline for the selective refresh partial. 211 * 212 * @since Twenty Seventeen 1.0 213 * 214 * @see twentyseventeen_customize_register() 215 * 216 * @return void 217 */ 218 function twentyseventeen_customize_partial_blogdescription() { 219 bloginfo( 'description' ); 220 } 221 222 /** 223 * Return whether we're previewing the front page and it's a static page. 224 */ 225 function twentyseventeen_is_static_front_page() { 226 return ( is_front_page() && ! is_home() ); 227 } 228 229 /** 230 * Return whether we're on a view that supports a one or two column layout. 231 */ 232 function twentyseventeen_is_view_with_layout_option() { 233 // This option is available on all pages. It's also available on archives when there isn't a sidebar. 234 return ( is_page() || ( is_archive() && ! is_active_sidebar( 'sidebar-1' ) ) ); 235 } 236 237 /** 238 * Bind JS handlers to instantly live-preview changes. 239 */ 240 function twentyseventeen_customize_preview_js() { 241 wp_enqueue_script( 'twentyseventeen-customize-preview', get_theme_file_uri( '/assets/js/customize-preview.js' ), array( 'customize-preview' ), '20161002', true ); 242 } 243 add_action( 'customize_preview_init', 'twentyseventeen_customize_preview_js' ); 244 245 /** 246 * Load dynamic logic for the customizer controls area. 247 */ 248 function twentyseventeen_panels_js() { 249 wp_enqueue_script( 'twentyseventeen-customize-controls', get_theme_file_uri( '/assets/js/customize-controls.js' ), array(), '20161020', true ); 250 } 251 add_action( 'customize_controls_enqueue_scripts', 'twentyseventeen_panels_js' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:03 2024 | Cross-referenced by PHPXref 0.7.1 |