No Description

customizer.php 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * XShop Theme Customizer
  4. *
  5. * @package XShop
  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 xshop_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. //select sanitization function
  17. function xshop_sanitize_select( $input, $setting ){
  18. $input = sanitize_key($input);
  19. $choices = $setting->manager->get_control( $setting->id )->choices;
  20. return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
  21. }
  22. $wp_customize->add_panel( 'xshop_settings', array(
  23. 'priority' => 50,
  24. 'title' => __('XShop Theme settings', 'xshop'),
  25. 'description' => __('All XShop theme settings', 'xshop'),
  26. ) );
  27. $wp_customize->add_section('xshop_header', array(
  28. 'title' => __('XShop Header Settings', 'xshop'),
  29. 'capability' => 'edit_theme_options',
  30. 'description' => __('XShop theme header settings', 'xshop'),
  31. 'panel' => 'xshop_settings',
  32. ));
  33. $wp_customize->add_setting('xshop_header_address1', array(
  34. 'capability' => 'edit_theme_options',
  35. 'type' => 'theme_mod',
  36. 'default' => '',
  37. 'sanitize_callback' => 'sanitize_text_field',
  38. 'transport' => 'refresh',
  39. ));
  40. $wp_customize->add_control('xshop_header_address1', array(
  41. 'label' => __('Header Address One', 'xshop'),
  42. 'section' => 'xshop_header',
  43. 'settings' => 'xshop_header_address1',
  44. 'type' => 'text',
  45. ));
  46. $wp_customize->add_setting('xshop_header_address2', array(
  47. 'capability' => 'edit_theme_options',
  48. 'type' => 'theme_mod',
  49. 'default' => '',
  50. 'sanitize_callback' => 'sanitize_text_field',
  51. 'transport' => 'refresh',
  52. ));
  53. $wp_customize->add_control('xshop_header_address2', array(
  54. 'label' => __('Header Address Two', 'xshop'),
  55. 'section' => 'xshop_header',
  56. 'settings' => 'xshop_header_address2',
  57. 'type' => 'text',
  58. ));
  59. //xshop blog settings
  60. $wp_customize->add_section('xshop_blog', array(
  61. 'title' => __('XShop Blog Settings', 'xshop'),
  62. 'capability' => 'edit_theme_options',
  63. 'description' => __('XShop theme blog settings', 'xshop'),
  64. 'panel' => 'xshop_settings',
  65. ));
  66. $wp_customize->add_setting('xshop_blog_container', array(
  67. 'default' => 'container',
  68. 'capability' => 'edit_theme_options',
  69. 'type' => 'theme_mod',
  70. 'sanitize_callback' => 'xshop_sanitize_select',
  71. 'transport' => 'refresh',
  72. ));
  73. $wp_customize->add_control('xshop_blog_container', array(
  74. 'label' => __('Container type', 'xshop'),
  75. 'description'=> __('You can set standard container or full width container. ', 'xshop'),
  76. 'section' => 'xshop_blog',
  77. 'settings' => 'xshop_blog_container',
  78. 'type' => 'select',
  79. 'choices' => array(
  80. 'container' => __('Standard Container', 'xshop'),
  81. 'container-fluid' => __('Full width Container', 'xshop'),
  82. ),
  83. ));
  84. $wp_customize->add_setting('xshop_blog_layout', array(
  85. 'default' => 'rightside',
  86. 'capability' => 'edit_theme_options',
  87. 'type' => 'theme_mod',
  88. 'sanitize_callback' => 'xshop_sanitize_select',
  89. 'transport' => 'refresh',
  90. ));
  91. $wp_customize->add_control('xshop_blog_layout', array(
  92. 'label' => __('Select Blog Layout', 'xshop'),
  93. 'description'=> __('Right and Left sidebar only show when sidebar widget is available. ', 'xshop'),
  94. 'section' => 'xshop_blog',
  95. 'settings' => 'xshop_blog_layout',
  96. 'type' => 'select',
  97. 'choices' => array(
  98. 'rightside' => __('Right Sidebar', 'xshop'),
  99. 'leftside' => __('Left Sidebar', 'xshop'),
  100. 'fullwidth' => __('No Sidebar', 'xshop'),
  101. ),
  102. ));
  103. $wp_customize->add_setting('xshop_blog_style', array(
  104. 'default' => 'grid',
  105. 'capability' => 'edit_theme_options',
  106. 'type' => 'theme_mod',
  107. 'sanitize_callback' => 'xshop_sanitize_select',
  108. 'transport' => 'refresh',
  109. ));
  110. $wp_customize->add_control('xshop_blog_style', array(
  111. 'label' => __('Select Blog Style', 'xshop'),
  112. 'section' => 'xshop_blog',
  113. 'settings' => 'xshop_blog_style',
  114. 'type' => 'select',
  115. 'choices' => array(
  116. 'grid' => __('Grid Style', 'xshop'),
  117. 'classic' => __('Classic Style', 'xshop'),
  118. ),
  119. ));
  120. //xshop page settings
  121. $wp_customize->add_section('xshop_page', array(
  122. 'title' => __('XShop Page Settings', 'xshop'),
  123. 'capability' => 'edit_theme_options',
  124. 'description' => __('XShop theme blog settings', 'xshop'),
  125. 'panel' => 'xshop_settings',
  126. ));
  127. $wp_customize->add_setting('xshop_page_container', array(
  128. 'default' => 'container',
  129. 'capability' => 'edit_theme_options',
  130. 'type' => 'theme_mod',
  131. 'sanitize_callback' => 'xshop_sanitize_select',
  132. 'transport' => 'refresh',
  133. ));
  134. $wp_customize->add_control('xshop_page_container', array(
  135. 'label' => __('Page Container type', 'xshop'),
  136. 'description'=> __('You can set standard container or full width container for page. ', 'xshop'),
  137. 'section' => 'xshop_page',
  138. 'settings' => 'xshop_page_container',
  139. 'type' => 'select',
  140. 'choices' => array(
  141. 'container' => __('Standard Container', 'xshop'),
  142. 'container-fluid' => __('Full width Container', 'xshop'),
  143. ),
  144. ));
  145. $wp_customize->add_setting('xshop_page_header', array(
  146. 'default' => 'show',
  147. 'capability' => 'edit_theme_options',
  148. 'type' => 'theme_mod',
  149. 'sanitize_callback' => 'xshop_sanitize_select',
  150. 'transport' => 'refresh',
  151. ));
  152. $wp_customize->add_control('xshop_page_header', array(
  153. 'label' => __('Show Page header', 'xshop'),
  154. 'section' => 'xshop_page',
  155. 'settings' => 'xshop_page_header',
  156. 'type' => 'select',
  157. 'choices' => array(
  158. 'show' => __('Show all pages', 'xshop'),
  159. 'hide-home' => __('Hide Only Front Page', 'xshop'),
  160. 'hide' => __('Hide All Pages', 'xshop'),
  161. ),
  162. ));
  163. if ( isset( $wp_customize->selective_refresh ) ) {
  164. $wp_customize->selective_refresh->add_partial(
  165. 'blogname',
  166. array(
  167. 'selector' => '.site-title a',
  168. 'render_callback' => 'xshop_customize_partial_blogname',
  169. )
  170. );
  171. $wp_customize->selective_refresh->add_partial(
  172. 'blogdescription',
  173. array(
  174. 'selector' => '.site-description',
  175. 'render_callback' => 'xshop_customize_partial_blogdescription',
  176. )
  177. );
  178. }
  179. }
  180. add_action( 'customize_register', 'xshop_customize_register' );
  181. /**
  182. * Render the site title for the selective refresh partial.
  183. *
  184. * @return void
  185. */
  186. function xshop_customize_partial_blogname() {
  187. bloginfo( 'name' );
  188. }
  189. /**
  190. * Render the site tagline for the selective refresh partial.
  191. *
  192. * @return void
  193. */
  194. function xshop_customize_partial_blogdescription() {
  195. bloginfo( 'description' );
  196. }
  197. /**
  198. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  199. */
  200. function xshop_customize_preview_js() {
  201. wp_enqueue_script( 'xshop-customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), XSHOP_VERSION, true );
  202. }
  203. add_action( 'customize_preview_init', 'xshop_customize_preview_js' );