customizer.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Spun Theme Customizer
  4. *
  5. * @package Spun
  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 spun_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. // Create the Theme Options section
  17. $wp_customize->add_section( 'spun_theme_options', array(
  18. 'title' => __( 'Theme Options', 'spun' ),
  19. ) );
  20. $wp_customize->add_setting( 'spun_grayscale', array(
  21. 'default' => false,
  22. 'type' => 'theme_mod',
  23. 'capability' => 'edit_theme_options',
  24. 'transport' => 'postMessage',
  25. ) );
  26. $wp_customize->add_control( 'spun_grayscale', array(
  27. 'label' => __( 'Always show color circles', 'spun' ),
  28. 'section' => 'spun_theme_options',
  29. 'type' => 'checkbox',
  30. 'priority' => 1,
  31. ) );
  32. $wp_customize->add_setting( 'spun_titles', array(
  33. 'default' => false,
  34. 'type' => 'theme_mod',
  35. 'capability' => 'edit_theme_options',
  36. 'transport' => 'postMessage',
  37. ) );
  38. $wp_customize->add_control( 'spun_titles', array(
  39. 'label' => __( 'Always show post titles over circles', 'spun' ),
  40. 'section' => 'spun_theme_options',
  41. 'type' => 'checkbox',
  42. 'priority' => 2,
  43. ) );
  44. $wp_customize->add_setting( 'spun_opacity', array(
  45. 'default' => false,
  46. 'type' => 'theme_mod',
  47. 'capability' => 'edit_theme_options',
  48. 'transport' => 'postMessage',
  49. ) );
  50. $wp_customize->add_control( 'spun_opacity', array(
  51. 'label' => __( 'Fully opaque meta', 'spun' ),
  52. 'section' => 'spun_theme_options',
  53. 'type' => 'checkbox',
  54. 'priority' => 3,
  55. ) );
  56. }
  57. add_action( 'customize_register', 'spun_customize_register' );
  58. /**
  59. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  60. */
  61. function spun_customize_preview_js() {
  62. wp_enqueue_script( 'spun_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20131113', true );
  63. }
  64. add_action( 'customize_preview_init', 'spun_customize_preview_js' );