[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
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 'description' => __( 'Apply a custom color for buttons, links, featured images, etc.', 'twentynineteen' ), 79 'section' => 'colors', 80 'mode' => 'hue', 81 ) 82 ) 83 ); 84 85 // Add image filter setting and control. 86 $wp_customize->add_setting( 87 'image_filter', 88 array( 89 'default' => 1, 90 'sanitize_callback' => 'absint', 91 'transport' => 'postMessage', 92 ) 93 ); 94 95 $wp_customize->add_control( 96 'image_filter', 97 array( 98 'label' => __( 'Apply a filter to featured images using the primary color', 'twentynineteen' ), 99 'section' => 'colors', 100 'type' => 'checkbox', 101 ) 102 ); 103 } 104 add_action( 'customize_register', 'twentynineteen_customize_register' ); 105 106 /** 107 * Render the site title for the selective refresh partial. 108 * 109 * @return void 110 */ 111 function twentynineteen_customize_partial_blogname() { 112 bloginfo( 'name' ); 113 } 114 115 /** 116 * Render the site tagline for the selective refresh partial. 117 * 118 * @return void 119 */ 120 function twentynineteen_customize_partial_blogdescription() { 121 bloginfo( 'description' ); 122 } 123 124 /** 125 * Bind JS handlers to instantly live-preview changes. 126 */ 127 function twentynineteen_customize_preview_js() { 128 wp_enqueue_script( 'twentynineteen-customize-preview', get_theme_file_uri( '/js/customize-preview.js' ), array( 'customize-preview' ), '20181214', true ); 129 } 130 add_action( 'customize_preview_init', 'twentynineteen_customize_preview_js' ); 131 132 /** 133 * Load dynamic logic for the customizer controls area. 134 */ 135 function twentynineteen_panels_js() { 136 wp_enqueue_script( 'twentynineteen-customize-controls', get_theme_file_uri( '/js/customize-controls.js' ), array(), '20181214', true ); 137 } 138 add_action( 'customize_controls_enqueue_scripts', 'twentynineteen_panels_js' ); 139 140 /** 141 * Sanitize custom color choice. 142 * 143 * @param string $choice Whether image filter is active. 144 * @return string 145 */ 146 function twentynineteen_sanitize_color_option( $choice ) { 147 $valid = array( 148 'default', 149 'custom', 150 ); 151 152 if ( in_array( $choice, $valid, true ) ) { 153 return $choice; 154 } 155 156 return 'default'; 157 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |