customizer.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Sketch Theme Customizer
  4. *
  5. * @package Sketch
  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 sketch_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_setting( 'sketch_portfolio_thumbnail', array(
  17. 'default' => 'landscape',
  18. 'sanitize_callback' => 'sketch_sanitize_ratio',
  19. ) );
  20. $wp_customize->add_control( 'sketch_portfolio_thumbnail', array(
  21. 'label' => __( 'Portfolio Thumbnail Aspect Ratio', 'sketch' ),
  22. 'section' => 'jetpack_portfolio',
  23. 'type' => 'select',
  24. 'choices' => array(
  25. 'landscape' => __( 'Landscape (4:3)', 'sketch' ),
  26. 'portrait' => __( 'Portrait (3:4)', 'sketch' ),
  27. 'square' => __( 'Square (1:1)', 'sketch' ),
  28. ),
  29. ) );
  30. $wp_customize->add_setting( 'sketch_hide_portfolio_page_content', array(
  31. 'default' => '',
  32. 'sanitize_callback' => 'sketch_sanitize_checkbox',
  33. ) );
  34. $wp_customize->add_control( 'sketch_hide_portfolio_page_content', array(
  35. 'label' => __( 'Hide title and content on Portfolio Page Template', 'sketch' ),
  36. 'section' => 'jetpack_portfolio',
  37. 'type' => 'checkbox',
  38. ) );
  39. }
  40. add_action( 'customize_register', 'sketch_customize_register' );
  41. /**
  42. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  43. */
  44. function sketch_customize_preview_js() {
  45. wp_enqueue_script( 'sketch_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
  46. }
  47. add_action( 'customize_preview_init', 'sketch_customize_preview_js' );
  48. /**
  49. * Sanitize the checkbox.
  50. *
  51. * @param boolean $input.
  52. * @return boolean true if portfolio page template displays title and content.
  53. */
  54. function sketch_sanitize_checkbox( $input ) {
  55. if ( 1 == $input ) {
  56. return true;
  57. } else {
  58. return false;
  59. }
  60. }
  61. /**
  62. * Sanitize the Portfolio Thumbnail Aspect Ratio value.
  63. *
  64. * @param string $ratio Aspect ratio.
  65. * @return string Filtered ratio (landscape|portrait|square).
  66. */
  67. function sketch_sanitize_ratio( $ratio ) {
  68. if ( ! in_array( $ratio, array( 'landscape', 'portrait', 'square' ) ) ) {
  69. $ratio = 'landscape';
  70. }
  71. return $ratio;
  72. }