[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentyfourteen/inc/ -> customizer.php (source)

   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(
  25              'blogname',
  26              array(
  27                  'selector'            => '.site-title a',
  28                  'container_inclusive' => false,
  29                  'render_callback'     => 'twentyfourteen_customize_partial_blogname',
  30              )
  31          );
  32          $wp_customize->selective_refresh->add_partial(
  33              'blogdescription',
  34              array(
  35                  'selector'            => '.site-description',
  36                  'container_inclusive' => false,
  37                  'render_callback'     => 'twentyfourteen_customize_partial_blogdescription',
  38              )
  39          );
  40      }
  41  
  42      // Rename the label to "Site Title Color" because this only affects the site title in this theme.
  43      $wp_customize->get_control( 'header_textcolor' )->label = __( 'Site Title Color', 'twentyfourteen' );
  44  
  45      // Rename the label to "Display Site Title & Tagline" in order to make this option extra clear.
  46      $wp_customize->get_control( 'display_header_text' )->label = __( 'Display Site Title &amp; Tagline', 'twentyfourteen' );
  47  
  48      // Add custom description to Colors and Background controls or sections.
  49      if ( property_exists( $wp_customize->get_control( 'background_color' ), 'description' ) ) {
  50          $wp_customize->get_control( 'background_color' )->description = __( 'May only be visible on wide screens.', 'twentyfourteen' );
  51          $wp_customize->get_control( 'background_image' )->description = __( 'May only be visible on wide screens.', 'twentyfourteen' );
  52      } else {
  53          $wp_customize->get_section( 'colors' )->description           = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
  54          $wp_customize->get_section( 'background_image' )->description = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
  55      }
  56  
  57      // Add the featured content section in case it's not already there.
  58      $wp_customize->add_section(
  59          'featured_content',
  60          array(
  61              'title'           => __( 'Featured Content', 'twentyfourteen' ),
  62              'description'     => sprintf(
  63                  /* translators: 1: Featured tag editor URL, 2: Post editor URL. */
  64                  __( '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' ),
  65                  esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), admin_url( 'edit.php' ) ) ),
  66                  admin_url( 'edit.php?show_sticky=1' )
  67              ),
  68              'priority'        => 130,
  69              'active_callback' => 'is_front_page',
  70          )
  71      );
  72  
  73      // Add the featured content layout setting and control.
  74      $wp_customize->add_setting(
  75          'featured_content_layout',
  76          array(
  77              'default'           => 'grid',
  78              'sanitize_callback' => 'twentyfourteen_sanitize_layout',
  79          )
  80      );
  81  
  82      $wp_customize->add_control(
  83          'featured_content_layout',
  84          array(
  85              'label'   => __( 'Layout', 'twentyfourteen' ),
  86              'section' => 'featured_content',
  87              'type'    => 'select',
  88              'choices' => array(
  89                  'grid'   => __( 'Grid', 'twentyfourteen' ),
  90                  'slider' => __( 'Slider', 'twentyfourteen' ),
  91              ),
  92          )
  93      );
  94  }
  95  add_action( 'customize_register', 'twentyfourteen_customize_register' );
  96  
  97  /**
  98   * Render the site title for the selective refresh partial.
  99   *
 100   * @since Twenty Fourteen 1.7
 101   * @see twentyfourteen_customize_register()
 102   *
 103   * @return void
 104   */
 105  function twentyfourteen_customize_partial_blogname() {
 106      bloginfo( 'name' );
 107  }
 108  
 109  /**
 110   * Render the site tagline for the selective refresh partial.
 111   *
 112   * @since Twenty Fourteen 1.7
 113   * @see twentyfourteen_customize_register()
 114   *
 115   * @return void
 116   */
 117  function twentyfourteen_customize_partial_blogdescription() {
 118      bloginfo( 'description' );
 119  }
 120  
 121  /**
 122   * Sanitize the Featured Content layout value.
 123   *
 124   * @since Twenty Fourteen 1.0
 125   *
 126   * @param string $layout Layout type.
 127   * @return string Filtered layout type (grid|slider).
 128   */
 129  function twentyfourteen_sanitize_layout( $layout ) {
 130      if ( ! in_array( $layout, array( 'grid', 'slider' ) ) ) {
 131          $layout = 'grid';
 132      }
 133  
 134      return $layout;
 135  }
 136  
 137  /**
 138   * Bind JS handlers to make Customizer preview reload changes asynchronously.
 139   *
 140   * @since Twenty Fourteen 1.0
 141   */
 142  function twentyfourteen_customize_preview_js() {
 143      wp_enqueue_script( 'twentyfourteen_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20141015', true );
 144  }
 145  add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
 146  
 147  /**
 148   * Add contextual help to the Themes and Post edit screens.
 149   *
 150   * @since Twenty Fourteen 1.0
 151   */
 152  function twentyfourteen_contextual_help() {
 153      if ( 'admin_head-edit.php' === current_filter() && 'post' !== $GLOBALS['typenow'] ) {
 154          return;
 155      }
 156  
 157      get_current_screen()->add_help_tab(
 158          array(
 159              'id'      => 'twentyfourteen',
 160              'title'   => __( 'Twenty Fourteen', 'twentyfourteen' ),
 161              'content' =>
 162                  '<ul>' .
 163                      /* translators: 1: Featured tag editor URL, 2: Post editor URL, 3: Customizer URL, 4: Post editor URL. */
 164                      '<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>' .
 165                      /* translators: %s: Featured images documentation URL. */
 166                      '<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>' .
 167                      /* translators: %s: Twenty Fourteen documentation URL. */
 168                      '<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>' .
 169                  '</ul>',
 170          )
 171      );
 172  }
 173  add_action( 'admin_head-themes.php', 'twentyfourteen_contextual_help' );
 174  add_action( 'admin_head-edit.php', 'twentyfourteen_contextual_help' );


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1