customizer.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Independent Publisher 2 Theme Customizer
  4. *
  5. * @package Independent_Publisher_2
  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 independent_publisher_2_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. $wp_customize->add_section( 'independent_publisher_2_theme_options', array(
  17. 'title' => esc_html__( 'Theme Options', 'independent-publisher-2' ),
  18. 'priority' => 130,
  19. ) );
  20. $wp_customize->add_setting( 'independent_publisher_2_gravatar_email', array(
  21. 'default' => get_option( 'admin_email' ),
  22. 'sanitize_callback' => 'independent_publisher_2_sanitize_email',
  23. ) );
  24. $wp_customize->add_control( 'independent_publisher_2_gravatar_email', array(
  25. 'label' => esc_html__( 'Header Gravatar', 'independent-publisher-2' ),
  26. 'description' => sprintf( esc_html_x( 'Enter the email address associated with your %1$s, or Globally Recognized Avatar, to be displayed in the header.', 'independent-publisher-2' ),'<a href="https://gravatar.com" target="_blank">Gravatar</a>', 'Gravatar URL' ),
  27. 'section' => 'independent_publisher_2_theme_options',
  28. 'type' => 'text',
  29. ) );
  30. $wp_customize->add_setting( 'independent_publisher_2_display_reading_time', array(
  31. 'default' => 1,
  32. 'sanitize_callback' => 'independent_publisher_2_sanitize_checkbox',
  33. ) );
  34. $wp_customize->add_control( 'independent_publisher_2_display_reading_time', array(
  35. 'label' => esc_html__( 'Display estimated reading time on posts', 'independent-publisher-2' ),
  36. 'section' => 'independent_publisher_2_theme_options',
  37. 'type' => 'checkbox',
  38. ) );
  39. }
  40. add_action( 'customize_register', 'independent_publisher_2_customize_register' );
  41. /**
  42. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  43. */
  44. function independent_publisher_2_customize_preview_js() {
  45. wp_enqueue_script( 'independent-publisher-2-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
  46. }
  47. add_action( 'customize_preview_init', 'independent_publisher_2_customize_preview_js' );
  48. /**
  49. * Sanitizes customizer email inputs.
  50. *
  51. * @return bool
  52. */
  53. function independent_publisher_2_sanitize_email( $value ) {
  54. if ( '' != $value && is_email( $value ) )
  55. $value = sanitize_email( $value );
  56. else
  57. $value = '';
  58. return $value;
  59. }
  60. /**
  61. * Sanitize the checkbox.
  62. *
  63. * @param int $input.
  64. * @return boolean|string
  65. */
  66. function independent_publisher_2_sanitize_checkbox( $input ) {
  67. return ( 1 == $input ) ? 1 : '';
  68. }