2013-07-28 18:55:10 -04:00
< ? php
/**
2013-10-11 18:02:11 -04:00
* Twenty Fourteen Theme Customizer support
2013-07-28 18:55:10 -04:00
*
* @ package WordPress
* @ subpackage Twenty_Fourteen
2013-10-11 18:02:11 -04:00
* @ since Twenty Fourteen 1.0
2013-07-28 18:55:10 -04:00
*/
/**
2013-10-15 14:01:09 -04:00
* Implement Theme Customizer additions and adjustments .
2013-07-28 18:55:10 -04:00
*
2013-10-11 18:02:11 -04:00
* @ since Twenty Fourteen 1.0
*
2013-07-28 18:55:10 -04:00
* @ param WP_Customize_Manager $wp_customize Theme Customizer object .
*/
function twentyfourteen_customize_register ( $wp_customize ) {
2013-10-15 14:01:09 -04:00
// Add postMessage support for site title and description.
2013-12-03 13:27:10 -05:00
$wp_customize -> get_setting ( 'blogname' ) -> transport = 'postMessage' ;
$wp_customize -> get_setting ( 'blogdescription' ) -> transport = 'postMessage' ;
$wp_customize -> get_setting ( 'header_textcolor' ) -> transport = 'postMessage' ;
// Rename the label to "Display Site Title & Tagline" in order to make this option extra clear.
$wp_customize -> add_control ( 'display_header_text' , array (
'settings' => 'header_textcolor' ,
'label' => __ ( 'Display Site Title & Tagline' , 'twentyfourteen' ),
'section' => 'title_tagline' ,
'type' => 'checkbox' ,
) );
// Rename the label to "Site Title Color" because this only effects the site title in this theme.
$wp_customize -> add_control ( new WP_Customize_Color_Control ( $wp_customize , 'header_textcolor' , array (
'label' => __ ( 'Site Title Color' , 'twentyfourteen' ),
'section' => 'colors' ,
) ) );
2013-10-15 19:24:10 -04:00
2013-11-07 15:37:08 -05:00
// Add custom description to Colors and Background sections.
2013-11-13 23:57:10 -05:00
$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 15:28:11 -05:00
2013-11-07 15:25:09 -05:00
// Add the featured content section in case it's not already there.
2013-10-30 10:39:10 -04:00
$wp_customize -> add_section ( 'featured_content' , array (
2013-11-07 20:09:10 -05:00
'title' => __ ( 'Featured Content' , 'twentyfourteen' ),
2013-11-24 11:57:10 -05:00
'description' => sprintf ( __ ( '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' ), admin_url ( '/edit.php?tag=featured' ), admin_url ( '/edit.php?show_sticky=1' ) ),
2013-11-07 20:09:10 -05:00
'priority' => 130 ,
2013-10-30 10:39:10 -04:00
) );
// Add the featured content layout setting and control.
$wp_customize -> add_setting ( 'featured_content_layout' , array (
2013-12-04 16:33:11 -05:00
'default' => 'grid' ,
'sanitize_callback' => 'twentyfourteen_sanitize_layout' ,
2013-10-30 10:39:10 -04:00
) );
$wp_customize -> add_control ( 'featured_content_layout' , array (
'label' => __ ( 'Layout' , 'twentyfourteen' ),
'section' => 'featured_content' ,
'type' => 'select' ,
'choices' => array (
2013-11-07 15:25:09 -05:00
'grid' => __ ( 'Grid' , 'twentyfourteen' ),
2013-10-30 10:39:10 -04:00
'slider' => __ ( 'Slider' , 'twentyfourteen' ),
),
) );
2013-07-28 18:55:10 -04:00
}
add_action ( 'customize_register' , 'twentyfourteen_customize_register' );
2013-12-04 16:33:11 -05: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 ) {
if ( ! in_array ( $layout , array ( 'grid' , 'slider' ) ) )
$layout = 'grid' ;
return $layout ;
}
2013-07-28 18:55:10 -04:00
/**
2013-10-11 18:02:11 -04:00
* Bind JS handlers to make Theme Customizer preview reload changes asynchronously .
*
* @ since Twenty Fourteen 1.0
2013-07-28 18:55:10 -04:00
*/
function twentyfourteen_customize_preview_js () {
2013-12-03 13:27:10 -05:00
wp_enqueue_script ( 'twentyfourteen_customizer' , get_template_directory_uri () . '/js/customizer.js' , array ( 'customize-preview' ), '20131130' , true );
2013-07-28 18:55:10 -04:00
}
2013-08-14 23:13:29 -04:00
add_action ( 'customize_preview_init' , 'twentyfourteen_customize_preview_js' );
2013-09-12 18:06:09 -04:00
2013-11-13 23:53:09 -05:00
/**
2013-12-03 12:06:11 -05:00
* Add contextual help to the Themes and Post edit screens .
2013-11-13 23:53:09 -05:00
*
* @ since Twenty Fourteen 1.0
*
* @ return void
*/
function twentyfourteen_contextual_help () {
2013-12-03 12:01:10 -05:00
if ( 'admin_head-edit.php' === current_filter () && 'post' !== $GLOBALS [ 'typenow' ] ) {
return ;
}
2013-11-13 23:53:09 -05:00
get_current_screen () -> add_help_tab ( array (
'id' => 'twentyfourteen' ,
'title' => __ ( 'Twenty Fourteen' , 'twentyfourteen' ),
'content' =>
'<ul>' .
2013-12-04 14:53:18 -05:00
'<li>' . sprintf ( __ ( 'The home page features your choice of up to 6 posts prominently displayed in a grid or slider, controlled by the <a href="%1$s">featured</a> tag; 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' ), admin_url ( '/edit.php?tag=featured' ), admin_url ( 'customize.php' ), admin_url ( '/edit.php?show_sticky=1' ) ) . '</li>' .
2013-11-14 21:43:10 -05: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' ), 'http://codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail' ) . '</li>' .
2013-12-04 14:53:18 -05:00
'<li>' . sprintf ( __ ( 'For an in-depth tutorial, and more tips and tricks, visit the <a href="%s">Twenty Fourteen documentation</a>.' , 'twentyfourteen' ), 'http://codex.wordpress.org/Twenty_Fourteen' ) . '</li>' .
2013-11-13 23:53:09 -05:00
'</ul>' ,
) );
}
add_action ( 'admin_head-themes.php' , 'twentyfourteen_contextual_help' );
add_action ( 'admin_head-edit.php' , 'twentyfourteen_contextual_help' );