/inc/customizer-includes/catchresponsive-customizer.php

  1. <?php 
  2. /** 
  3. * The main template for implementing Theme/Customzer Options 
  4. * 
  5. * @package Catch Themes 
  6. * @subpackage Catch Responsive 
  7. * @since Catch Responsive 1.0 
  8. */ 
  9.  
  10. if ( ! defined( 'CATCHRESPONSIVE_THEME_VERSION' ) ) { 
  11. header( 'Status: 403 Forbidden' ); 
  12. header( 'HTTP/1.1 403 Forbidden' ); 
  13. exit(); 
  14.  
  15.  
  16. /** 
  17. * Implements Catchresponsive theme options into Theme Customizer. 
  18. * 
  19. * @param $wp_customize Theme Customizer object 
  20. * @return void 
  21. * 
  22. * @since Catch Responsive 1.0 
  23. */ 
  24. function catchresponsive_customize_register( $wp_customize ) { 
  25. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; 
  26.  
  27. /** 
  28. * Set priority of blogname (Site Title) to 1. 
  29. * Strangly, if more than two options is added, Site title is moved below Tagline. This rectifies this issue. 
  30. */ 
  31. $wp_customize->get_control( 'blogname' )->priority = 1; 
  32.  
  33. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; 
  34.  
  35. $options = catchresponsive_get_theme_options(); 
  36.  
  37. $defaults = catchresponsive_get_default_theme_options(); 
  38.  
  39. //Custom Controls 
  40. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/catchresponsive-customizer-custom-controls.php'; 
  41.  
  42. //@remove Remove this block when WordPress 4.8 is released 
  43. if ( ! function_exists( 'has_custom_logo' ) ) { 
  44. // Custom Logo (added to Site Title and Tagline section in Theme Customizer) 
  45. $wp_customize->add_setting( 'catchresponsive_theme_options[logo]', array( 
  46. 'capability' => 'edit_theme_options',  
  47. 'default' => $defaults['logo'],  
  48. 'sanitize_callback' => 'catchresponsive_sanitize_image' 
  49. ) ); 
  50.  
  51. $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'logo', array( 
  52. 'label' => __( 'Logo', 'catch-responsive' ),  
  53. 'priority' => 100,  
  54. 'section' => 'title_tagline',  
  55. 'settings' => 'catchresponsive_theme_options[logo]',  
  56. ) ) ); 
  57.  
  58. $wp_customize->add_setting( 'catchresponsive_theme_options[logo_disable]', array( 
  59. 'capability' => 'edit_theme_options',  
  60. 'default' => $defaults['logo_disable'],  
  61. 'sanitize_callback' => 'catchresponsive_sanitize_checkbox',  
  62. ) ); 
  63.  
  64. $wp_customize->add_control( 'catchresponsive_theme_options[logo_disable]', array( 
  65. 'label' => __( 'Check to disable logo', 'catch-responsive' ),  
  66. 'priority' => 101,  
  67. 'section' => 'title_tagline',  
  68. 'settings' => 'catchresponsive_theme_options[logo_disable]',  
  69. 'type' => 'checkbox',  
  70. ) ); 
  71.  
  72. $wp_customize->add_setting( 'catchresponsive_theme_options[logo_alt_text]', array( 
  73. 'capability' => 'edit_theme_options',  
  74. 'default' => $defaults['logo_alt_text'],  
  75. 'sanitize_callback' => 'sanitize_text_field',  
  76. ) ); 
  77.  
  78. $wp_customize->add_control( 'catchresponsive_logo_alt_text', array( 
  79. 'label' => __( 'Logo Alt Text', 'catch-responsive' ),  
  80. 'priority' => 102,  
  81. 'section' => 'title_tagline',  
  82. 'settings' => 'catchresponsive_theme_options[logo_alt_text]',  
  83. 'type' => 'text',  
  84. ) ); 
  85.  
  86. $wp_customize->add_setting( 'catchresponsive_theme_options[move_title_tagline]', array( 
  87. 'capability' => 'edit_theme_options',  
  88. 'default' => $defaults['move_title_tagline'],  
  89. 'sanitize_callback' => 'catchresponsive_sanitize_checkbox',  
  90. ) ); 
  91.  
  92. $wp_customize->add_control( 'catchresponsive_theme_options[move_title_tagline]', array( 
  93. 'label' => __( 'Check to move Site Title and Tagline before logo', 'catch-responsive' ),  
  94. 'priority' => function_exists( 'has_custom_logo' ) ? 10 : 103,  
  95. 'section' => 'title_tagline',  
  96. 'settings' => 'catchresponsive_theme_options[move_title_tagline]',  
  97. 'type' => 'checkbox',  
  98. ) ); 
  99. // Custom Logo End 
  100.  
  101. // Color Scheme 
  102. $wp_customize->add_setting( 'catchresponsive_theme_options[color_scheme]', array( 
  103. 'capability' => 'edit_theme_options',  
  104. 'default' => $defaults['color_scheme'],  
  105. 'sanitize_callback' => 'catchresponsive_sanitize_select',  
  106. 'transport' => 'postMessage',  
  107. ) ); 
  108.  
  109. $schemes = catchresponsive_color_schemes(); 
  110.  
  111. $choices = array(); 
  112.  
  113. foreach ( $schemes as $scheme ) { 
  114. $choices[ $scheme['value'] ] = $scheme['label']; 
  115.  
  116. $wp_customize->add_control( 'catchresponsive_theme_options[color_scheme]', array( 
  117. 'choices' => $choices,  
  118. 'label' => __( 'Color Scheme', 'catch-responsive' ),  
  119. 'priority' => 5,  
  120. 'section' => 'colors',  
  121. 'settings' => 'catchresponsive_theme_options[color_scheme]',  
  122. 'type' => 'radio',  
  123. ) ); 
  124.  
  125. $wp_customize->add_setting( 'catchresponsive_theme_options[mobile_menu_color_scheme]', array( 
  126. 'capability' => 'edit_theme_options',  
  127. 'default' => $defaults['mobile_menu_color_scheme'],  
  128. 'sanitize_callback' => 'catchresponsive_sanitize_select' 
  129. ) ); 
  130.  
  131. $wp_customize->add_control( 'catchresponsive_theme_options[mobile_menu_color_scheme]', array( 
  132. 'choices' => $choices,  
  133. 'label' => __( 'Mobile Menu Color Scheme', 'catch-responsive' ),  
  134. 'section' => 'colors',  
  135. 'settings' => 'catchresponsive_theme_options[mobile_menu_color_scheme]',  
  136. 'type' => 'radio',  
  137. ) ); 
  138. //End Color Scheme 
  139.  
  140. // Header Options (added to Header section in Theme Customizer) 
  141. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/catchresponsive-customizer-header-options.php'; 
  142.  
  143. //Theme Options 
  144. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/catchresponsive-customizer-theme-options.php'; 
  145.  
  146. //Featured Content Setting 
  147. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/catchresponsive-customizer-featured-content-setting.php'; 
  148.  
  149. //Featured Slider 
  150. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/catchresponsive-customizer-featured-slider.php'; 
  151.  
  152. //Social Links 
  153. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/catchresponsive-customizer-social-icons.php'; 
  154.  
  155. // Reset all settings to default 
  156. $wp_customize->add_section( 'catchresponsive_reset_all_settings', array( 
  157. 'description' => __( 'Caution: Reset all settings to default. Refresh the page after save to view full effects.', 'catch-responsive' ),  
  158. 'priority' => 700,  
  159. 'title' => __( 'Reset all settings', 'catch-responsive' ),  
  160. ) ); 
  161.  
  162. $wp_customize->add_setting( 'catchresponsive_theme_options[reset_all_settings]', array( 
  163. 'capability' => 'edit_theme_options',  
  164. 'default' => $defaults['reset_all_settings'],  
  165. 'sanitize_callback' => 'catchresponsive_sanitize_checkbox',  
  166. 'transport' => 'postMessage',  
  167. ) ); 
  168.  
  169. $wp_customize->add_control( 'catchresponsive_theme_options[reset_all_settings]', array( 
  170. 'label' => __( 'Check to reset all settings to default', 'catch-responsive' ),  
  171. 'section' => 'catchresponsive_reset_all_settings',  
  172. 'settings' => 'catchresponsive_theme_options[reset_all_settings]',  
  173. 'type' => 'checkbox',  
  174. ) ); 
  175. // Reset all settings to default end 
  176.  
  177. //Important Links 
  178. $wp_customize->add_section( 'important_links', array( 
  179. 'priority' => 999,  
  180. 'title' => __( 'Important Links', 'catch-responsive' ),  
  181. ) ); 
  182.  
  183. /** 
  184. * Has dummy Sanitizaition function as it contains no value to be sanitized 
  185. */ 
  186. $wp_customize->add_setting( 'important_links', array( 
  187. 'sanitize_callback' => 'sanitize_text_field',  
  188. ) ); 
  189.  
  190. $wp_customize->add_control( new Catchresponsive_Important_Links( $wp_customize, 'important_links', array( 
  191. 'label' => __( 'Important Links', 'catch-responsive' ),  
  192. 'section' => 'important_links',  
  193. 'settings' => 'important_links',  
  194. 'type' => 'important_links',  
  195. ) ) ); 
  196. //Important Links End 
  197. add_action( 'customize_register', 'catchresponsive_customize_register' ); 
  198.  
  199.  
  200. /** 
  201. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously for catchresponsive. 
  202. * And flushes out all transient data on preview 
  203. * 
  204. * @since Catch Responsive 1.0 
  205. */ 
  206. function catchresponsive_customize_preview() { 
  207. wp_enqueue_script( 'catchresponsive_customizer', get_template_directory_uri() . '/js/catchresponsive-customizer.min.js', array( 'customize-preview' ), '20120827', true ); 
  208.  
  209. //Flush transients on preview 
  210. catchresponsive_flush_transients(); 
  211. add_action( 'customize_preview_init', 'catchresponsive_customize_preview' ); 
  212.  
  213.  
  214. /** 
  215. * Custom scripts and styles on customize.php for catchresponsive. 
  216. * 
  217. * @since Catch Responsive 1.0 
  218. */ 
  219. function catchresponsive_customize_scripts() { 
  220. wp_enqueue_script( 'catchresponsive_customizer_custom', get_template_directory_uri() . '/js/catchresponsive-customizer-custom-scripts.min.js', array( 'customize-controls', 'iris', 'underscore', 'wp-util' ), '20150630', true ); 
  221.  
  222. $catchresponsive_misc_links = array( 
  223. 'reset_message' => esc_html__( 'Refresh the customizer page after saving to view reset effects', 'catch-responsive' ) 
  224. ); 
  225.  
  226. $catchresponsive_misc_links['color_list'] = catchresponsive_color_list(); 
  227.  
  228. //Add Upgrade Button and old WordPress message via localized script 
  229. wp_localize_script( 'catchresponsive_customizer_custom', 'catchresponsive_misc_links', $catchresponsive_misc_links ); 
  230.  
  231. wp_enqueue_script( 'catchresponsive_customizer_custom' ); 
  232. add_action( 'customize_controls_enqueue_scripts', 'catchresponsive_customize_scripts'); 
  233.  
  234.  
  235. /** 
  236. * Returns list of color keys of array with default values for each color scheme as index 
  237. * 
  238. * @since Catch Base 2.1 
  239. */ 
  240. function catchresponsive_color_list() { 
  241. // Get default color scheme values 
  242. $default = catchresponsive_get_default_theme_options(); 
  243. // Get default dark color scheme valies 
  244. $default_dark = catchresponsive_default_dark_color_options(); 
  245.  
  246. $catchresponsive_color_list['background_color']['light'] = $default['background_color']; 
  247. $catchresponsive_color_list['background_color']['dark'] = $default_dark['background_color']; 
  248.  
  249. $catchresponsive_color_list['header_textcolor']['light'] = $default['header_textcolor']; 
  250. $catchresponsive_color_list['header_textcolor']['dark'] = $default_dark['header_textcolor']; 
  251.  
  252. return $catchresponsive_color_list; 
  253.  
  254.  
  255. /** 
  256. * Function to reset date with respect to condition 
  257. */ 
  258. function catchresponsive_reset_data() { 
  259. $options = catchresponsive_get_theme_options(); 
  260. if ( $options['reset_all_settings'] ) { 
  261. remove_theme_mods(); 
  262.  
  263. // Flush out all transients on reset 
  264. catchresponsive_flush_transients(); 
  265. add_action( 'customize_save_after', 'catchresponsive_reset_data' ); 
  266.  
  267.  
  268. //Active callbacks for customizer 
  269. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/catchresponsive-customizer-active-callbacks.php'; 
  270.  
  271. //Sanitize functions for customizer 
  272. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/catchresponsive-customizer-sanitize-functions.php'; 
  273.  
  274. // Upgrade To Pro Button 
  275. require trailingslashit( get_template_directory() ) . 'inc/customizer-includes/upgrade-button/class-customize.php'; 
.