]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-content/themes/twentyfourteen/inc/customizer.php
WordPress 4.6.3
[autoinstalls/wordpress.git] / wp-content / themes / twentyfourteen / inc / customizer.php
1 <?php
2 /**
3  * Twenty Fourteen Customizer support
4  *
5  * @package WordPress
6  * @subpackage Twenty_Fourteen
7  * @since Twenty Fourteen 1.0
8  */
9
10 /**
11  * Implement Customizer additions and adjustments.
12  *
13  * @since Twenty Fourteen 1.0
14  *
15  * @param WP_Customize_Manager $wp_customize Customizer object.
16  */
17 function twentyfourteen_customize_register( $wp_customize ) {
18         // Add postMessage support for site title and description.
19         $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
20         $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
21         $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
22
23         if ( isset( $wp_customize->selective_refresh ) ) {
24                 $wp_customize->selective_refresh->add_partial( 'blogname', array(
25                         'selector' => '.site-title a',
26                         'container_inclusive' => false,
27                         'render_callback' => 'twentyfourteen_customize_partial_blogname',
28                 ) );
29                 $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
30                         'selector' => '.site-description',
31                         'container_inclusive' => false,
32                         'render_callback' => 'twentyfourteen_customize_partial_blogdescription',
33                 ) );
34         }
35
36         // Rename the label to "Site Title Color" because this only affects the site title in this theme.
37         $wp_customize->get_control( 'header_textcolor' )->label = __( 'Site Title Color', 'twentyfourteen' );
38
39         // Rename the label to "Display Site Title & Tagline" in order to make this option extra clear.
40         $wp_customize->get_control( 'display_header_text' )->label = __( 'Display Site Title &amp; Tagline', 'twentyfourteen' );
41
42         // Add custom description to Colors and Background controls or sections.
43         if ( property_exists( $wp_customize->get_control( 'background_color' ), 'description' ) ) {
44                 $wp_customize->get_control( 'background_color' )->description = __( 'May only be visible on wide screens.', 'twentyfourteen' );
45                 $wp_customize->get_control( 'background_image' )->description = __( 'May only be visible on wide screens.', 'twentyfourteen' );
46         } else {
47                 $wp_customize->get_section( 'colors' )->description           = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
48                 $wp_customize->get_section( 'background_image' )->description = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
49         }
50
51         // Add the featured content section in case it's not already there.
52         $wp_customize->add_section( 'featured_content', array(
53                 'title'           => __( 'Featured Content', 'twentyfourteen' ),
54                 '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' ),
55                         esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), admin_url( 'edit.php' ) ) ),
56                         admin_url( 'edit.php?show_sticky=1' )
57                 ),
58                 'priority'        => 130,
59                 'active_callback' => 'is_front_page',
60         ) );
61
62         // Add the featured content layout setting and control.
63         $wp_customize->add_setting( 'featured_content_layout', array(
64                 'default'           => 'grid',
65                 'sanitize_callback' => 'twentyfourteen_sanitize_layout',
66         ) );
67
68         $wp_customize->add_control( 'featured_content_layout', array(
69                 'label'   => __( 'Layout', 'twentyfourteen' ),
70                 'section' => 'featured_content',
71                 'type'    => 'select',
72                 'choices' => array(
73                         'grid'   => __( 'Grid',   'twentyfourteen' ),
74                         'slider' => __( 'Slider', 'twentyfourteen' ),
75                 ),
76         ) );
77 }
78 add_action( 'customize_register', 'twentyfourteen_customize_register' );
79
80 /**
81  * Render the site title for the selective refresh partial.
82  *
83  * @since Twenty Fourteen 1.7
84  * @see twentyfourteen_customize_register()
85  *
86  * @return void
87  */
88 function twentyfourteen_customize_partial_blogname() {
89         bloginfo( 'name' );
90 }
91
92 /**
93  * Render the site tagline for the selective refresh partial.
94  *
95  * @since Twenty Fourteen 1.7
96  * @see twentyfourteen_customize_register()
97  *
98  * @return void
99  */
100 function twentyfourteen_customize_partial_blogdescription() {
101         bloginfo( 'description' );
102 }
103
104 /**
105  * Sanitize the Featured Content layout value.
106  *
107  * @since Twenty Fourteen 1.0
108  *
109  * @param string $layout Layout type.
110  * @return string Filtered layout type (grid|slider).
111  */
112 function twentyfourteen_sanitize_layout( $layout ) {
113         if ( ! in_array( $layout, array( 'grid', 'slider' ) ) ) {
114                 $layout = 'grid';
115         }
116
117         return $layout;
118 }
119
120 /**
121  * Bind JS handlers to make Customizer preview reload changes asynchronously.
122  *
123  * @since Twenty Fourteen 1.0
124  */
125 function twentyfourteen_customize_preview_js() {
126         wp_enqueue_script( 'twentyfourteen_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20131205', true );
127 }
128 add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
129
130 /**
131  * Add contextual help to the Themes and Post edit screens.
132  *
133  * @since Twenty Fourteen 1.0
134  */
135 function twentyfourteen_contextual_help() {
136         if ( 'admin_head-edit.php' === current_filter() && 'post' !== $GLOBALS['typenow'] ) {
137                 return;
138         }
139
140         get_current_screen()->add_help_tab( array(
141                 'id'      => 'twentyfourteen',
142                 'title'   => __( 'Twenty Fourteen', 'twentyfourteen' ),
143                 'content' =>
144                         '<ul>' .
145                                 '<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 &rarr; 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>' .
146                                 '<li>' . sprintf( __( 'Enhance your site design by using <a href="%s">Featured Images</a> for posts you&rsquo;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&mdash;above the title&mdash;and in the Featured Content area on the home page.', 'twentyfourteen' ), 'https://codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail' ) . '</li>' .
147                                 '<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>' .
148                         '</ul>',
149         ) );
150 }
151 add_action( 'admin_head-themes.php', 'twentyfourteen_contextual_help' );
152 add_action( 'admin_head-edit.php',   'twentyfourteen_contextual_help' );