update
This commit is contained in:
+63
-12
@@ -6,13 +6,13 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add postMessage support for site title and description for the Theme Customizer.
|
||||
* Add postMessage support and custom options for the Theme Customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
function cyywordpress_customize_register( $wp_customize ) {
|
||||
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
|
||||
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
|
||||
function cyywordpress_customize_register( WP_Customize_Manager $wp_customize ): void {
|
||||
$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 ) ) {
|
||||
@@ -31,31 +31,82 @@ function cyywordpress_customize_register( $wp_customize ) {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Section: Front Page Banner
|
||||
// -----------------------------------------------------------------------
|
||||
$wp_customize->add_section(
|
||||
'cyywordpress_frontpage',
|
||||
array(
|
||||
'title' => esc_html__( '首页横幅', 'cyywordpress' ),
|
||||
'priority' => 130,
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting(
|
||||
'cyywordpress_welcome_text',
|
||||
array(
|
||||
// 存原始字符串,输出时再转义。
|
||||
'default' => __( '欢迎来到这!Hello everyone.', 'cyywordpress' ),
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'transport' => 'postMessage',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'cyywordpress_welcome_text',
|
||||
array(
|
||||
'label' => esc_html__( '欢迎横幅文字', 'cyywordpress' ),
|
||||
'section' => 'cyywordpress_frontpage',
|
||||
'type' => 'text',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting(
|
||||
'cyywordpress_show_welcome_banner',
|
||||
array(
|
||||
'default' => true,
|
||||
'sanitize_callback' => 'rest_sanitize_boolean',
|
||||
'transport' => 'refresh',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'cyywordpress_show_welcome_banner',
|
||||
array(
|
||||
'label' => esc_html__( '显示欢迎横幅', 'cyywordpress' ),
|
||||
'section' => 'cyywordpress_frontpage',
|
||||
'type' => 'checkbox',
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'customize_register', 'cyywordpress_customize_register' );
|
||||
|
||||
/**
|
||||
* Render the site title for the selective refresh partial.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cyywordpress_customize_partial_blogname() {
|
||||
function cyywordpress_customize_partial_blogname(): void {
|
||||
bloginfo( 'name' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the site tagline for the selective refresh partial.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cyywordpress_customize_partial_blogdescription() {
|
||||
function cyywordpress_customize_partial_blogdescription(): void {
|
||||
bloginfo( 'description' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
|
||||
*/
|
||||
function cyywordpress_customize_preview_js() {
|
||||
wp_enqueue_script( 'cyywordpress-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), _S_VERSION, true );
|
||||
function cyywordpress_customize_preview_js(): void {
|
||||
wp_enqueue_script(
|
||||
'cyywordpress-customizer',
|
||||
get_template_directory_uri() . '/js/customizer.js',
|
||||
array( 'customize-preview' ),
|
||||
_S_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
add_action( 'customize_preview_init', 'cyywordpress_customize_preview_js' );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user