customizer.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Twenty Fourteen Theme Customizer support
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Fourteen
  7. * @since Twenty Fourteen 1.0
  8. */
  9. /**
  10. * Implement Theme Customizer additions and adjustments.
  11. *
  12. * @since Twenty Fourteen 1.0
  13. *
  14. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  15. */
  16. function twentyfourteen_customize_register( $wp_customize ) {
  17. // Add custom description to Colors and Background sections.
  18. $wp_customize->get_section( 'colors' )->description = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
  19. $wp_customize->get_section( 'background_image' )->description = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
  20. // Add postMessage support for site title and description.
  21. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  22. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  23. $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  24. // Rename the label to "Site Title Color" because this only affects the site title in this theme.
  25. $wp_customize->get_control( 'header_textcolor' )->label = __( 'Site Title Color', 'twentyfourteen' );
  26. // Rename the label to "Display Site Title & Tagline" in order to make this option extra clear.
  27. $wp_customize->get_control( 'display_header_text' )->label = __( 'Display Site Title &amp; Tagline', 'twentyfourteen' );
  28. // Add the featured content section in case it's not already there.
  29. $wp_customize->add_section( 'featured_content', array(
  30. 'title' => __( 'Featured Content', 'twentyfourteen' ),
  31. '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' ) ),
  32. 'priority' => 130,
  33. ) );
  34. // Add the featured content layout setting and control.
  35. $wp_customize->add_setting( 'featured_content_layout', array(
  36. 'default' => 'grid',
  37. 'sanitize_callback' => 'twentyfourteen_sanitize_layout',
  38. ) );
  39. $wp_customize->add_control( 'featured_content_layout', array(
  40. 'label' => __( 'Layout', 'twentyfourteen' ),
  41. 'section' => 'featured_content',
  42. 'type' => 'select',
  43. 'choices' => array(
  44. 'grid' => __( 'Grid', 'twentyfourteen' ),
  45. 'slider' => __( 'Slider', 'twentyfourteen' ),
  46. ),
  47. ) );
  48. }
  49. add_action( 'customize_register', 'twentyfourteen_customize_register' );
  50. /**
  51. * Sanitize the Featured Content layout value.
  52. *
  53. * @since Twenty Fourteen 1.0
  54. *
  55. * @param string $layout Layout type.
  56. * @return string Filtered layout type (grid|slider).
  57. */
  58. function twentyfourteen_sanitize_layout( $layout ) {
  59. if ( ! in_array( $layout, array( 'grid', 'slider' ) ) ) {
  60. $layout = 'grid';
  61. }
  62. return $layout;
  63. }
  64. /**
  65. * Bind JS handlers to make Theme Customizer preview reload changes asynchronously.
  66. *
  67. * @since Twenty Fourteen 1.0
  68. */
  69. function twentyfourteen_customize_preview_js() {
  70. wp_enqueue_script( 'twentyfourteen_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20131205', true );
  71. }
  72. add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
  73. /**
  74. * Add contextual help to the Themes and Post edit screens.
  75. *
  76. * @since Twenty Fourteen 1.0
  77. *
  78. * @return void
  79. */
  80. function twentyfourteen_contextual_help() {
  81. if ( 'admin_head-edit.php' === current_filter() && 'post' !== $GLOBALS['typenow'] ) {
  82. return;
  83. }
  84. get_current_screen()->add_help_tab( array(
  85. 'id' => 'twentyfourteen',
  86. 'title' => __( 'Twenty Fourteen', 'twentyfourteen' ),
  87. 'content' =>
  88. '<ul>' .
  89. '<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 &rarr; 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>' .
  90. '<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' ), 'http://codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail' ) . '</li>' .
  91. '<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>' .
  92. '</ul>',
  93. ) );
  94. }
  95. add_action( 'admin_head-themes.php', 'twentyfourteen_contextual_help' );
  96. add_action( 'admin_head-edit.php', 'twentyfourteen_contextual_help' );