Layers_Customizer

Customizer Initiation File.

Defined (1)

The class is defined in the following location(s).

/core/customizer/init.php  
  1. class Layers_Customizer { 
  2.  
  3. private static $instance; // stores singleton class 
  4.  
  5. /** 
  6. * Get Instance creates a singleton class that's cached to stop duplicate instances 
  7. */ 
  8. public static function get_instance() { 
  9. if ( ! self::$instance ) { 
  10. self::$instance = new self(); 
  11. self::$instance->init(); 
  12. return self::$instance; 
  13.  
  14. /** 
  15. * Construct empty on purpose 
  16. */ 
  17.  
  18. private function __construct() {} 
  19.  
  20. /** 
  21. * Init behaves like, and replaces, construct 
  22. */ 
  23.  
  24. public function init() { 
  25.  
  26. global $wp_customize; 
  27.  
  28. // Setup some folder variables 
  29. $customizer_dir = '/core/customizer/'; 
  30. $controls_dir = '/core/customizer/controls/'; 
  31.  
  32. // Include Config file(s) 
  33. require_once get_template_directory() . $customizer_dir . 'config.php'; 
  34. // Include The Default Settings Class 
  35. require_once get_template_directory() . $customizer_dir . 'defaults.php'; 
  36.  
  37. if( isset( $wp_customize ) ) { 
  38.  
  39. // Include The Panel and Section Registration Class 
  40. require_once get_template_directory() . $customizer_dir . 'registration.php'; 
  41.  
  42. // Include control classes 
  43. require_once get_template_directory() . $controls_dir . 'base.php'; 
  44. require_once get_template_directory() . $controls_dir . 'button.php'; 
  45. require_once get_template_directory() . $controls_dir . 'checkbox.php'; 
  46. require_once get_template_directory() . $controls_dir . 'code.php'; 
  47. require_once get_template_directory() . $controls_dir . 'color.php'; 
  48. require_once get_template_directory() . $controls_dir . 'font.php'; 
  49. require_once get_template_directory() . $controls_dir . 'heading.php'; 
  50. require_once get_template_directory() . $controls_dir . 'number.php'; 
  51. require_once get_template_directory() . $controls_dir . 'range.php'; 
  52. require_once get_template_directory() . $controls_dir . 'select.php'; 
  53. require_once get_template_directory() . $controls_dir . 'select-icons.php'; 
  54. require_once get_template_directory() . $controls_dir . 'select-images.php'; 
  55. require_once get_template_directory() . $controls_dir . 'seperator.php'; 
  56. require_once get_template_directory() . $controls_dir . 'rte.php'; 
  57. require_once get_template_directory() . $controls_dir . 'text.php'; 
  58. require_once get_template_directory() . $controls_dir . 'textarea.php'; 
  59. require_once get_template_directory() . $controls_dir . 'trbl.php'; 
  60.  
  61. // Enqueue Styles 
  62. add_action( 'customize_controls_print_footer_scripts', array( $this, 'admin_enqueue_scripts' ) ); 
  63. add_action( 'admin_enqueue_scripts', array( $this, 'admin_print_styles' ) , 50 ); 
  64. add_action( 'customize_controls_print_styles' , array( $this, 'admin_print_styles' ) ); 
  65. add_action( 'customize_preview_init', array( $this, 'customizer_preview_enqueue_scripts' ) ); 
  66.  
  67. // Render layers customizer menu 
  68. add_action( 'customize_controls_print_footer_scripts' , array( $this, 'render_customizer_menu' ) ); 
  69.  
  70. // Advanced Active Callback functionality - disabled 
  71. add_filter( 'customize_control_active', array( $this, 'customize_active_controls' ), 10, 2 ); 
  72.  
  73. /** 
  74. * Enqueue Widget Scripts 
  75. */ 
  76.  
  77. public function admin_enqueue_scripts() { 
  78.  
  79. // Hover Intent 
  80. wp_enqueue_script( 'hoverIntent' ); 
  81.  
  82. // Media Uploader required scripts 
  83. wp_enqueue_media(); 
  84.  
  85. // Customizer general 
  86. wp_enqueue_script( 
  87. LAYERS_THEME_SLUG . '-admin-customizer' ,  
  88. get_template_directory_uri() . '/core/customizer/js/customizer.js' ,  
  89. array( 
  90. 'customize-controls',  
  91. 'wp-color-picker' 
  92. ),  
  93. LAYERS_VERSION,  
  94. true 
  95. ); 
  96.  
  97. // Localize Scripts 
  98. wp_localize_script( LAYERS_THEME_SLUG . '-admin-customizer' , 'layers_customizer_params', array( 
  99. 'nonce' => wp_create_nonce( 'layers-customizer-actions' ),  
  100. 'builder_page' => ( isset( $_GET[ 'layers-builder' ] ) ? TRUE : FALSE ),  
  101. 'enable_deep_linking' => ( get_theme_mod( 'layers-dev-switch-customizer-state-record' ) ),  
  102. ); 
  103.  
  104. /** 
  105. * Enqueue Customizer Preview Scripts 
  106. */ 
  107.  
  108. public function customizer_preview_enqueue_scripts() { 
  109.  
  110. wp_enqueue_script( 
  111. LAYERS_THEME_SLUG . '-admin-customizer-preview',  
  112. get_template_directory_uri() . '/core/customizer/js/customizer-preview.js',  
  113. array( 'customize-preview-widgets' ),  
  114. LAYERS_VERSION 
  115. ); 
  116.  
  117. wp_enqueue_style( 
  118. LAYERS_THEME_SLUG . '-admin-customizer-preview',  
  119. get_template_directory_uri() . '/core/customizer/css/customizer-preview.css',  
  120. array(),  
  121. LAYERS_VERSION 
  122. ); 
  123.  
  124. /** 
  125. * Enqueue Widget Styles 
  126. */ 
  127.  
  128. public function admin_print_styles() { 
  129.  
  130. wp_enqueue_style( 
  131. LAYERS_THEME_SLUG . '-admin-customizer',  
  132. get_template_directory_uri() . '/core/customizer/css/customizer.css',  
  133. array(),  
  134. LAYERS_VERSION 
  135. ); 
  136.  
  137. /** 
  138. * Render the dropdown of builder pages in Customizer interface. 
  139. */ 
  140.  
  141. public function render_builder_page_dropdown() { 
  142. global $wp_customize; 
  143.  
  144. if(!$wp_customize) return; 
  145.  
  146. //Get builder pages. 
  147. $layers_pages = layers_get_builder_pages(); 
  148.  
  149. // Create builder pages dropdown. 
  150. if( $layers_pages ) { 
  151. ob_start(); ?> 
  152. <div class="layers-customizer-pages-dropdown"> 
  153. <select> 
  154. <option value="init"><?php _e( 'Builder Pages:' , 'layerswp' ) ?></option> 
  155. <?php foreach( $layers_pages as $page ) { ?> 
  156. <?php // Page URL 
  157. $edit_page_url = get_permalink( $page->ID ); ?> 
  158. <option value="<?php echo esc_attr( $edit_page_url ); ?>"><?php echo $page->post_title ?></option> 
  159. <?php } ?> 
  160. </select> 
  161. </div> 
  162. <?php 
  163. // Get the Drop Down HTML 
  164. $drop_down = ob_get_clean(); 
  165.  
  166. // Return the Drop Down 
  167. return $drop_down; 
  168.  
  169. function render_customizer_menu() { 
  170. ?> 
  171. <div id="customize-controls-layers-actions"> 
  172.  
  173. <ul class="layers-customizer-nav"> 
  174. <li> 
  175. <span class="customize-controls-layers-button customize-controls-layers-button-dashboard-main" title="<?php esc_html( _e( 'Layers Dashboard' , 'layerswp' ) ) ?>" href="<?php echo admin_url( 'admin.php?page=layers-add-new-page' ); ?>"></span> 
  176. <ul> 
  177. <?php 
  178. // Construct the Layers Customizer Menu 
  179. $layers_customizer_menu = array( 
  180. 'preview' => array( 
  181. 'text' => __( 'View this page' , 'layerswp' ),  
  182. 'link' => '#',  
  183. 'icon_class' => 'icon-display',  
  184. 'target' => '_blank',  
  185. ),  
  186. 'add-new-page' => array( 
  187. 'text' => __( 'Add new Layers page' , 'layerswp' ),  
  188. 'link' => admin_url( 'admin.php?page=layers-add-new-page' ),  
  189. 'icon_class' => 'dashicons dashicons-plus',  
  190. ),  
  191. 'dashboard' => array( 
  192. 'text' => __( 'Layers Dashboard' , 'layerswp' ),  
  193. 'link' => admin_url( 'admin.php?page=layers-dashboard' ),  
  194. 'icon_class' => 'layers-button-icon-dashboard',  
  195. ),  
  196. ); 
  197.  
  198. // Filter the Layers Customizer Menu 
  199. $layers_customizer_menu = apply_filters( 'layers_customizer_menu', $layers_customizer_menu ); 
  200.  
  201. // Render the Layers Customizer Menu 
  202. foreach ( $layers_customizer_menu as $id => $args ) { 
  203.  
  204. $text = ( isset( $args['text'] ) && '' !== trim( $args['text'] ) ) ? esc_html( $args['text'] ) : '' ; 
  205. $icon_class = ( isset( $args['icon_class'] ) && '' !== trim( $args['icon_class'] ) ) ? esc_attr( $args['icon_class'] ) : '' ; 
  206. $href = ( isset( $args['link'] ) && '' !== trim( $args['link'] ) ) ? 'href="' . esc_url( $args['link'] ) . '"' : '' ; 
  207. $target = ( isset( $args['target'] ) && '' !== trim( $args['target'] ) ) ? 'target="' . esc_attr( $args['target'] ) . '"' : '' ; 
  208. ?> 
  209. <li> 
  210. <a class="customize-controls-layers-button customize-controls-layers-button-<?php echo esc_attr( $id ); ?>" <?php echo $href; ?> <?php echo $target; ?> > 
  211. <i class="<?php echo $icon_class ?>"></i><?php echo $text ?> 
  212. </a> 
  213. </li> 
  214. <?php 
  215. ?> 
  216. </ul> 
  217. </li> 
  218. </ul> 
  219.  
  220. </div> 
  221. <?php 
  222.  
  223. // Advanced Active Callback functionality - for Dev Switches 
  224. function customize_active_controls( $arg1, $arg2 ) { 
  225.  
  226. if ( isset( $arg2->id ) && 0 === strpos( $arg2->id, 'layers-dev-switch' ) ) { 
  227. return ( (bool) get_theme_mod( 'layers-dev-switch-active' ) ); 
  228.  
  229. return $arg1; 
  230.