PageRenderTime 81ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/web/app/themes/understrap/inc/customizer.php

https://bitbucket.org/Ironika/debranding
PHP | 124 lines | 82 code | 11 blank | 31 comment | 3 complexity | 11d1067548ca2f91da1ba6e3a197ca8e MD5 | raw file
Possible License(s): JSON, BSD-2-Clause, Unlicense, MIT, Apache-2.0, CC-BY-4.0, 0BSD, BSD-3-Clause, CC-BY-SA-3.0
  1. <?php
  2. /**
  3. * Understrap Theme Customizer
  4. *
  5. * @package understrap
  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. if ( ! function_exists( 'understrap_customize_register' ) ) {
  13. /**
  14. * Register basic customizer support.
  15. *
  16. * @param object $wp_customize Customizer reference.
  17. */
  18. function understrap_customize_register( $wp_customize ) {
  19. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  20. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  21. $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  22. }
  23. }
  24. add_action( 'customize_register', 'understrap_customize_register' );
  25. if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
  26. /**
  27. * Register individual settings through customizer's API.
  28. *
  29. * @param WP_Customize_Manager $wp_customize Customizer reference.
  30. */
  31. function understrap_theme_customize_register( $wp_customize ) {
  32. // Theme layout settings.
  33. $wp_customize->add_section( 'understrap_theme_layout_options', array(
  34. 'title' => __( 'Theme Layout Settings', 'understrap' ),
  35. 'capability' => 'edit_theme_options',
  36. 'description' => __( 'Container width and sidebar defaults', 'understrap' ),
  37. 'priority' => 160,
  38. ) );
  39. //select sanitization function
  40. function understrap_theme_slug_sanitize_select( $input, $setting ){
  41. //input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only
  42. $input = sanitize_key($input);
  43. //get the list of possible select options
  44. $choices = $setting->manager->get_control( $setting->id )->choices;
  45. //return input if valid or return default option
  46. return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
  47. }
  48. $wp_customize->add_setting( 'understrap_container_type', array(
  49. 'default' => 'container',
  50. 'type' => 'theme_mod',
  51. 'sanitize_callback' => 'understrap_theme_slug_sanitize_select',
  52. 'capability' => 'edit_theme_options',
  53. ) );
  54. $wp_customize->add_control(
  55. new WP_Customize_Control(
  56. $wp_customize,
  57. 'understrap_container_type', array(
  58. 'label' => __( 'Container Width', 'understrap' ),
  59. 'description' => __( "Choose between Bootstrap's container and container-fluid", 'understrap' ),
  60. 'section' => 'understrap_theme_layout_options',
  61. 'settings' => 'understrap_container_type',
  62. 'type' => 'select',
  63. 'choices' => array(
  64. 'container' => __( 'Fixed width container', 'understrap' ),
  65. 'container-fluid' => __( 'Full width container', 'understrap' ),
  66. ),
  67. 'priority' => '10',
  68. )
  69. ) );
  70. $wp_customize->add_setting( 'understrap_sidebar_position', array(
  71. 'default' => 'right',
  72. 'type' => 'theme_mod',
  73. 'sanitize_callback' => 'sanitize_text_field',
  74. 'capability' => 'edit_theme_options',
  75. ) );
  76. $wp_customize->add_control(
  77. new WP_Customize_Control(
  78. $wp_customize,
  79. 'understrap_sidebar_position', array(
  80. 'label' => __( 'Sidebar Positioning', 'understrap' ),
  81. 'description' => __( "Set sidebar's default position. Can either be: right, left, both or none. Note: this can be overridden on individual pages.",
  82. 'understrap' ),
  83. 'section' => 'understrap_theme_layout_options',
  84. 'settings' => 'understrap_sidebar_position',
  85. 'type' => 'select',
  86. 'sanitize_callback' => 'understrap_theme_slug_sanitize_select',
  87. 'choices' => array(
  88. 'right' => __( 'Right sidebar', 'understrap' ),
  89. 'left' => __( 'Left sidebar', 'understrap' ),
  90. 'both' => __( 'Left & Right sidebars', 'understrap' ),
  91. 'none' => __( 'No sidebar', 'understrap' ),
  92. ),
  93. 'priority' => '20',
  94. )
  95. ) );
  96. }
  97. } // endif function_exists( 'understrap_theme_customize_register' ).
  98. add_action( 'customize_register', 'understrap_theme_customize_register' );
  99. /**
  100. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  101. */
  102. if ( ! function_exists( 'understrap_customize_preview_js' ) ) {
  103. /**
  104. * Setup JS integration for live previewing.
  105. */
  106. function understrap_customize_preview_js() {
  107. wp_enqueue_script( 'understrap_customizer', get_template_directory_uri() . '/js/customizer.js',
  108. array( 'customize-preview' ), '20130508', true );
  109. }
  110. }
  111. add_action( 'customize_preview_init', 'understrap_customize_preview_js' );