mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-30 13:08:26 +01:00
5432b8e055
Merges [43808,43821,43842,43860,43892,43904,43909,43926-43929,43956,43961-43963] from the 5.0 branch to trunk. Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, jorbin, netweb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins, peterwilsoncc, dannycooper, iCaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, grapplerulrich, ocean90, joshfeck, frankew, AbdulWahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, nao, mayukojpn, enodekciw, ketuchetan, atanasangelovdev, poena, sharaz, artisticasad, mukesh27, burhandodhy, crunnells, aprakasa, themeroots, imonly_ik, tlxo, youthkee, brentswisher, smyoon315, mrahmadawais, desideveloper, Kau-Boy, mor10, mikeyarce, dingo_bastard, xkon, twoabove. Fixes #45424. Built from https://develop.svn.wordpress.org/trunk@44149 git-svn-id: http://core.svn.wordpress.org/trunk@43979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
159 lines
3.9 KiB
PHP
159 lines
3.9 KiB
PHP
<?php
|
|
/**
|
|
* Twenty Nineteen: Customizer
|
|
*
|
|
* @package WordPress
|
|
* @subpackage Twenty_Nineteen
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
/**
|
|
* Add postMessage support for site title and description for the Theme Customizer.
|
|
*
|
|
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
|
*/
|
|
function twentynineteen_customize_register( $wp_customize ) {
|
|
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
|
|
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
|
|
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
|
|
|
|
if ( isset( $wp_customize->selective_refresh ) ) {
|
|
$wp_customize->selective_refresh->add_partial(
|
|
'blogname',
|
|
array(
|
|
'selector' => '.site-title a',
|
|
'render_callback' => 'twentynineteen_customize_partial_blogname',
|
|
)
|
|
);
|
|
$wp_customize->selective_refresh->add_partial(
|
|
'blogdescription',
|
|
array(
|
|
'selector' => '.site-description',
|
|
'render_callback' => 'twentynineteen_customize_partial_blogdescription',
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Primary color.
|
|
*/
|
|
$wp_customize->add_setting(
|
|
'primary_color',
|
|
array(
|
|
'default' => 'default',
|
|
'transport' => 'postMessage',
|
|
'sanitize_callback' => 'twentynineteen_sanitize_color_option',
|
|
)
|
|
);
|
|
|
|
$wp_customize->add_control(
|
|
'primary_color',
|
|
array(
|
|
'type' => 'radio',
|
|
'label' => __( 'Primary Color', 'twentynineteen' ),
|
|
'choices' => array(
|
|
'default' => _x( 'Default', 'primary color', 'twentynineteen' ),
|
|
'custom' => _x( 'Custom', 'primary color', 'twentynineteen' ),
|
|
),
|
|
'section' => 'colors',
|
|
'priority' => 5,
|
|
)
|
|
);
|
|
|
|
// Add primary color hue setting and control.
|
|
$wp_customize->add_setting(
|
|
'primary_color_hue',
|
|
array(
|
|
'default' => 199,
|
|
'transport' => 'postMessage',
|
|
'sanitize_callback' => 'absint',
|
|
)
|
|
);
|
|
|
|
$wp_customize->add_control(
|
|
new WP_Customize_Color_Control(
|
|
$wp_customize,
|
|
'primary_color_hue',
|
|
array(
|
|
'description' => __( 'Apply a custom color for buttons, links, featured images, etc.', 'twentynineteen' ),
|
|
'section' => 'colors',
|
|
'mode' => 'hue',
|
|
)
|
|
)
|
|
);
|
|
|
|
// Add image filter setting and control.
|
|
$wp_customize->add_setting(
|
|
'image_filter',
|
|
array(
|
|
'default' => 1,
|
|
'sanitize_callback' => 'absint',
|
|
'transport' => 'postMessage',
|
|
)
|
|
);
|
|
|
|
$wp_customize->add_control(
|
|
'image_filter',
|
|
array(
|
|
'label' => __( 'Apply a filter to featured images using the primary color', 'twentynineteen' ),
|
|
'section' => 'colors',
|
|
'type' => 'checkbox',
|
|
)
|
|
);
|
|
}
|
|
add_action( 'customize_register', 'twentynineteen_customize_register' );
|
|
|
|
/**
|
|
* Render the site title for the selective refresh partial.
|
|
*
|
|
* @return void
|
|
*/
|
|
function twentynineteen_customize_partial_blogname() {
|
|
bloginfo( 'name' );
|
|
}
|
|
|
|
/**
|
|
* Render the site tagline for the selective refresh partial.
|
|
*
|
|
* @return void
|
|
*/
|
|
function twentynineteen_customize_partial_blogdescription() {
|
|
bloginfo( 'description' );
|
|
}
|
|
|
|
/**
|
|
* Bind JS handlers to instantly live-preview changes.
|
|
*/
|
|
function twentynineteen_customize_preview_js() {
|
|
wp_enqueue_script( 'twentynineteen-customize-preview', get_theme_file_uri( '/js/customize-preview.js' ), array( 'customize-preview' ), '20151215', true );
|
|
}
|
|
add_action( 'customize_preview_init', 'twentynineteen_customize_preview_js' );
|
|
|
|
/**
|
|
* Load dynamic logic for the customizer controls area.
|
|
*/
|
|
function twentynineteen_panels_js() {
|
|
wp_enqueue_script( 'twentynineteen-customize-controls', get_theme_file_uri( '/js/customize-controls.js' ), array(), '1.0', true );
|
|
}
|
|
add_action( 'customize_controls_enqueue_scripts', 'twentynineteen_panels_js' );
|
|
|
|
/**
|
|
* Sanitize custom color choice.
|
|
*
|
|
* @param string $choice Whether image filter is active.
|
|
*
|
|
* @return string
|
|
*/
|
|
function twentynineteen_sanitize_color_option( $choice ) {
|
|
$valid = array(
|
|
'default',
|
|
'custom',
|
|
);
|
|
|
|
if ( in_array( $choice, $valid, true ) ) {
|
|
return $choice;
|
|
}
|
|
|
|
return 'default';
|
|
}
|