customizer.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * photos Theme Customizer
  4. *
  5. * @package photos
  6. */
  7. /**
  8. * Add postMessage support for site title and description for the Theme Customizer.
  9. *
  10. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  11. */
  12. function photos_customize_register( $wp_customize ) {
  13. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  14. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  15. $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  16. if ( isset( $wp_customize->selective_refresh ) ) {
  17. $wp_customize->selective_refresh->add_partial( 'blogname', array(
  18. 'selector' => '.site-title a',
  19. 'render_callback' => 'photos_customize_partial_blogname',
  20. ) );
  21. $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
  22. 'selector' => '.site-description',
  23. 'render_callback' => 'photos_customize_partial_blogdescription',
  24. ) );
  25. }
  26. }
  27. add_action( 'customize_register', 'photos_customize_register' );
  28. /**
  29. * Render the site title for the selective refresh partial.
  30. *
  31. * @return void
  32. */
  33. function photos_customize_partial_blogname() {
  34. bloginfo( 'name' );
  35. }
  36. /**
  37. * Render the site tagline for the selective refresh partial.
  38. *
  39. * @return void
  40. */
  41. function photos_customize_partial_blogdescription() {
  42. bloginfo( 'description' );
  43. }
  44. /**
  45. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  46. */
  47. function photos_customize_preview_js() {
  48. wp_enqueue_script( 'photos-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20151215', true );
  49. }
  50. add_action( 'customize_preview_init', 'photos_customize_preview_js' );