2013-07-29 00:55:10 +02:00
< ? php
/**
2014-10-15 19:21:19 +02:00
* Twenty Fourteen Customizer support
2013-07-29 00:55:10 +02:00
*
* @ package WordPress
* @ subpackage Twenty_Fourteen
2013-10-12 00:02:11 +02:00
* @ since Twenty Fourteen 1.0
2013-07-29 00:55:10 +02:00
*/
/**
2014-10-15 19:21:19 +02:00
* Implement Customizer additions and adjustments .
2013-07-29 00:55:10 +02:00
*
2013-10-12 00:02:11 +02:00
* @ since Twenty Fourteen 1.0
*
2014-10-15 19:21:19 +02:00
* @ param WP_Customize_Manager $wp_customize Customizer object .
2013-07-29 00:55:10 +02:00
*/
function twentyfourteen_customize_register ( $wp_customize ) {
2013-10-15 20:01:09 +02:00
// Add postMessage support for site title and description.
2017-12-01 00:11:00 +01:00
$wp_customize -> get_setting ( 'blogname' ) -> transport = 'postMessage' ;
$wp_customize -> get_setting ( 'blogdescription' ) -> transport = 'postMessage' ;
$wp_customize -> get_setting ( 'header_textcolor' ) -> transport = 'postMessage' ;
2013-12-03 19:27:10 +01:00
2016-03-01 23:18:26 +01:00
if ( isset ( $wp_customize -> selective_refresh ) ) {
2017-12-01 00:11:00 +01:00
$wp_customize -> selective_refresh -> add_partial (
2018-08-17 03:51:36 +02:00
'blogname' ,
array (
2017-12-01 00:11:00 +01:00
'selector' => '.site-title a' ,
'container_inclusive' => false ,
'render_callback' => 'twentyfourteen_customize_partial_blogname' ,
)
);
$wp_customize -> selective_refresh -> add_partial (
2018-08-17 03:51:36 +02:00
'blogdescription' ,
array (
2017-12-01 00:11:00 +01:00
'selector' => '.site-description' ,
'container_inclusive' => false ,
'render_callback' => 'twentyfourteen_customize_partial_blogdescription' ,
)
);
2016-03-01 23:18:26 +01:00
}
2013-12-04 23:52:10 +01:00
// Rename the label to "Site Title Color" because this only affects the site title in this theme.
2013-12-04 23:09:11 +01:00
$wp_customize -> get_control ( 'header_textcolor' ) -> label = __ ( 'Site Title Color' , 'twentyfourteen' );
2013-10-16 01:24:10 +02:00
2013-12-04 23:09:11 +01:00
// Rename the label to "Display Site Title & Tagline" in order to make this option extra clear.
$wp_customize -> get_control ( 'display_header_text' ) -> label = __ ( 'Display Site Title & Tagline' , 'twentyfourteen' );
2013-11-07 21:28:11 +01:00
2014-10-03 10:43:15 +02:00
// Add custom description to Colors and Background controls or sections.
if ( property_exists ( $wp_customize -> get_control ( 'background_color' ), 'description' ) ) {
$wp_customize -> get_control ( 'background_color' ) -> description = __ ( 'May only be visible on wide screens.' , 'twentyfourteen' );
$wp_customize -> get_control ( 'background_image' ) -> description = __ ( 'May only be visible on wide screens.' , 'twentyfourteen' );
} else {
$wp_customize -> get_section ( 'colors' ) -> description = __ ( 'Background may only be visible on wide screens.' , 'twentyfourteen' );
$wp_customize -> get_section ( 'background_image' ) -> description = __ ( 'Background may only be visible on wide screens.' , 'twentyfourteen' );
}
2013-11-07 21:25:09 +01:00
// Add the featured content section in case it's not already there.
2017-12-01 00:11:00 +01:00
$wp_customize -> add_section (
2018-08-17 03:51:36 +02:00
'featured_content' ,
array (
2017-12-01 00:11:00 +01:00
'title' => __ ( 'Featured Content' , 'twentyfourteen' ),
'description' => sprintf (
2019-09-03 02:41:05 +02:00
/* translators: 1: Featured tag editor URL, 2: Post editor URL. */
2017-12-01 00:11:00 +01:00
__ ( 'Use a <a href="%1$s">tag</a> to feature your posts. If no posts match the tag, <a href="%2$s">sticky posts</a> will be displayed instead.' , 'twentyfourteen' ),
esc_url ( add_query_arg ( 'tag' , _x ( 'featured' , 'featured content default tag slug' , 'twentyfourteen' ), admin_url ( 'edit.php' ) ) ),
admin_url ( 'edit.php?show_sticky=1' )
),
'priority' => 130 ,
'active_callback' => 'is_front_page' ,
)
);
2013-10-30 15:39:10 +01:00
// Add the featured content layout setting and control.
2017-12-01 00:11:00 +01:00
$wp_customize -> add_setting (
2018-08-17 03:51:36 +02:00
'featured_content_layout' ,
array (
2017-12-01 00:11:00 +01:00
'default' => 'grid' ,
'sanitize_callback' => 'twentyfourteen_sanitize_layout' ,
)
);
2013-10-30 15:39:10 +01:00
2017-12-01 00:11:00 +01:00
$wp_customize -> add_control (
2018-08-17 03:51:36 +02:00
'featured_content_layout' ,
array (
2017-12-01 00:11:00 +01:00
'label' => __ ( 'Layout' , 'twentyfourteen' ),
'section' => 'featured_content' ,
'type' => 'select' ,
'choices' => array (
'grid' => __ ( 'Grid' , 'twentyfourteen' ),
'slider' => __ ( 'Slider' , 'twentyfourteen' ),
),
)
);
2013-07-29 00:55:10 +02:00
}
add_action ( 'customize_register' , 'twentyfourteen_customize_register' );
2016-03-01 23:18:26 +01:00
/**
* Render the site title for the selective refresh partial .
*
* @ since Twenty Fourteen 1.7
2020-06-16 23:07:14 +02:00
*
2016-03-01 23:18:26 +01:00
* @ see twentyfourteen_customize_register ()
*
* @ return void
*/
function twentyfourteen_customize_partial_blogname () {
bloginfo ( 'name' );
}
/**
* Render the site tagline for the selective refresh partial .
*
* @ since Twenty Fourteen 1.7
2020-06-16 23:07:14 +02:00
*
2016-03-01 23:18:26 +01:00
* @ see twentyfourteen_customize_register ()
*
* @ return void
*/
function twentyfourteen_customize_partial_blogdescription () {
bloginfo ( 'description' );
}
2013-12-04 22:33:11 +01:00
/**
* Sanitize the Featured Content layout value .
*
* @ since Twenty Fourteen 1.0
*
* @ param string $layout Layout type .
* @ return string Filtered layout type ( grid | slider ) .
*/
function twentyfourteen_sanitize_layout ( $layout ) {
2020-04-05 05:02:11 +02:00
if ( ! in_array ( $layout , array ( 'grid' , 'slider' ), true ) ) {
2013-12-04 22:33:11 +01:00
$layout = 'grid' ;
2013-12-04 23:09:11 +01:00
}
2013-12-04 22:33:11 +01:00
return $layout ;
}
2013-07-29 00:55:10 +02:00
/**
2014-10-15 19:21:19 +02:00
* Bind JS handlers to make Customizer preview reload changes asynchronously .
2013-10-12 00:02:11 +02:00
*
* @ since Twenty Fourteen 1.0
2013-07-29 00:55:10 +02:00
*/
function twentyfourteen_customize_preview_js () {
2019-08-08 03:29:58 +02:00
wp_enqueue_script ( 'twentyfourteen_customizer' , get_template_directory_uri () . '/js/customizer.js' , array ( 'customize-preview' ), '20141015' , true );
2013-07-29 00:55:10 +02:00
}
2013-08-15 05:13:29 +02:00
add_action ( 'customize_preview_init' , 'twentyfourteen_customize_preview_js' );
2013-09-13 00:06:09 +02:00
2013-11-14 05:53:09 +01:00
/**
2013-12-03 18:06:11 +01:00
* Add contextual help to the Themes and Post edit screens .
2013-11-14 05:53:09 +01:00
*
* @ since Twenty Fourteen 1.0
*/
function twentyfourteen_contextual_help () {
2013-12-03 18:01:10 +01:00
if ( 'admin_head-edit.php' === current_filter () && 'post' !== $GLOBALS [ 'typenow' ] ) {
return ;
}
2017-12-01 00:11:00 +01:00
get_current_screen () -> add_help_tab (
array (
'id' => 'twentyfourteen' ,
'title' => __ ( 'Twenty Fourteen' , 'twentyfourteen' ),
'content' =>
'<ul>' .
2019-09-03 02:41:05 +02:00
/* translators: 1: Featured tag editor URL, 2: Post editor URL, 3: Customizer URL, 4: Post editor URL. */
2017-12-01 00:11:00 +01:00
'<li>' . sprintf ( __ ( 'The home page features your choice of up to 6 posts prominently displayed in a grid or slider, controlled by a <a href="%1$s">tag</a>; you can change the tag and layout in <a href="%2$s">Appearance → Customize</a>. If no posts match the tag, <a href="%3$s">sticky posts</a> will be displayed instead.' , 'twentyfourteen' ), esc_url ( add_query_arg ( 'tag' , _x ( 'featured' , 'featured content default tag slug' , 'twentyfourteen' ), admin_url ( 'edit.php' ) ) ), admin_url ( 'customize.php' ), admin_url ( 'edit.php?show_sticky=1' ) ) . '</li>' .
2019-09-03 02:41:05 +02:00
/* translators: %s: Featured images documentation URL. */
2017-12-01 00:11:00 +01:00
'<li>' . sprintf ( __ ( 'Enhance your site design by using <a href="%s">Featured Images</a> for posts you’d like to stand out (also known as post thumbnails). This allows you to associate an image with your post without inserting it. Twenty Fourteen uses featured images for posts and pages—above the title—and in the Featured Content area on the home page.' , 'twentyfourteen' ), 'https://codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail' ) . '</li>' .
2019-09-03 02:41:05 +02:00
/* translators: %s: Twenty Fourteen documentation URL. */
2017-12-01 00:11:00 +01:00
'<li>' . sprintf ( __ ( 'For an in-depth tutorial, and more tips and tricks, visit the <a href="%s">Twenty Fourteen documentation</a>.' , 'twentyfourteen' ), 'https://codex.wordpress.org/Twenty_Fourteen' ) . '</li>' .
'</ul>' ,
)
);
2013-11-14 05:53:09 +01:00
}
add_action ( 'admin_head-themes.php' , 'twentyfourteen_contextual_help' );
2017-12-01 00:11:00 +01:00
add_action ( 'admin_head-edit.php' , 'twentyfourteen_contextual_help' );