PluginProbe
LoftLoader / 2.1.0
LoftLoader v2.1.0
trunk 1.0.0 1.0.1 1.0.2 2.0.0 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 All 34 releases
loftloader / inc / class-loftloader-customize.php

class-loftloader-customize.php in LoftLoader 2.1.0, at inc/class-loftloader-customize.php

315 lines 12.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if(!class_exists('LoftLoader_Customize')){
3 /**
4 * Load the Loftloader lite customize related functions
5 *
6 * @author Loft.Ocean
7 * @since 2.0.0
8 */
9 class LoftLoader_Customize{
10 public function __construct(){
11 $this->load_default_settings();
12 if(loftloader_is_customize()){
13 $this->load_customize_controls();
14 add_action('customize_controls_init', array($this, 'remove_sections'), 1000);
15 add_action('customize_controls_enqueue_scripts', array($this, 'customize_scripts'), 9999);
16 add_action('customize_preview_init', array($this, 'preview_scripts'));
17 }
18 }
19
20 private function load_default_settings(){
21 require_once LOFTLOADER_ROOT . 'inc/configs/default-settings.php';
22 }
23
24 public function load_customize_controls(){
25 $config_dir = LOFTLOADER_ROOT . 'inc/configs/';
26 require_once $config_dir . 'customize-main.php';
27 require_once $config_dir . 'customize-range.php';
28 require_once $config_dir . 'customize-background.php';
29 require_once $config_dir . 'customize-loader.php';
30 require_once $config_dir . 'customize-promo.php';
31 require_once $config_dir . 'customize-any-page.php';
32 }
33
34 public function remove_sections(){
35 global $wp_customize;
36 foreach($wp_customize->containers() as $id => $container){
37 if($container instanceof WP_Customize_Panel){
38 (strpos($id, 'loftloader_') === false) ? $wp_customize->remove_panel($id) : '';
39 }
40 else if($container instanceof WP_Customize_Section){
41 (strpos($id, 'loftloader_') === false) ? $wp_customize->remove_section($id) : '';
42 }
43 }
44 }
45
46 public function customize_scripts(){
47 global $wp_scripts, $wp_styles;
48 $js_url = LOFTLOADER_URI . 'assets/js/customize.min.js';
49 $js_dep = array('jquery', 'wp-color-picker', 'jquery-ui-slider', 'customize-controls');
50 $ui_css = LOFTLOADER_URI . 'assets/css/jquery-ui.css';
51 $loader_css = LOFTLOADER_URI . 'assets/css/loftloader-settings.min.css';
52
53 wp_register_script('loftloader-lite-customize', $js_url, $js_dep, LOFTLOADER_ASSET_VERSION);
54 wp_localize_script('loftloader-lite-customize', 'loftloader_lite_i18n', array('name' => esc_html__('LoftLoader Lite', 'loftloader'))); // Change the site title in string "You are customizing ..."
55 wp_enqueue_script('loftloader-lite-customize');
56
57 wp_enqueue_style('loftloader-lite-ui', $ui_css, array(), LOFTLOADER_ASSET_VERSION);
58 wp_enqueue_style('loftloader-lite-customize', $loader_css, array(), LOFTLOADER_ASSET_VERSION);
59
60 foreach($wp_scripts->registered as $h => $o){
61 if(strpos($o->src, 'wp-content/themes') !== false){
62 wp_dequeue_script($h);
63 }
64 };
65 foreach($wp_styles->registered as $h => $o){
66 if(strpos($o->src, 'wp-content/themes') !== false){
67 wp_dequeue_style($h);
68 }
69 };
70 }
71
72 public function preview_scripts(){
73 $js_url = LOFTLOADER_URI . 'assets/js/preview.min.js';
74 wp_register_script('loftloader-lite-preview', $js_url, array('jquery', 'customize-preview'), LOFTLOADER_ASSET_VERSION, true);
75 wp_localize_script('loftloader-lite-preview', 'loftloader_lite', array('preview' => 'on'));
76 wp_enqueue_script('loftloader-lite-preview'); }
77 }
78
79 new LoftLoader_Customize();
80 }
81
82 if(class_exists('WP_Customize_Setting')){
83 /**
84 * LoftLoader related customization api classes
85 *
86 * @since 2.0.0
87 */
88
89 // LoftLoader base section class, changed the json function to modify the customize action text
90 class LoftLoader_Customize_Section extends WP_Customize_Section{
91 public function json() {
92 $array = parent::json();
93 $array['customizeAction'] = esc_html__('Setting', 'loftloader');
94 return $array;
95 }
96 /**
97 * render function for LoftLoader Switch section
98 */
99 protected function render() {
100 if('loftloader_switch' === $this->type){
101 $switch = $this->manager->get_setting('loftloader_main_switch')->value();
102 $classes = 'accordion-section control-section control-section-' . $this->type;
103 ?>
104 <li id="accordion-section-<?php echo $this->id; ?>" class="accordion-section control-section control-section-<?php echo $this->type; ?>">
105 <h3 class="accordion-section-title" tabindex="0">
106 <?php echo $this->title; ?>
107 <span class="screen-reader-text"><?php esc_html_e( 'Press return or enter to open this section', 'loftloader' ); ?></span>
108 <input type="checkbox" name="loftloader-main-switch" value="on" <?php checked($switch, 'on'); ?> />
109 </h3>
110 <ul class="accordion-section-content">
111 <li class="customize-section-description-container">
112 <div class="customize-section-title">
113 <button class="customize-section-back" tabindex="-1">
114 <span class="screen-reader-text"><?php esc_html_e('Back', 'loftloader'); ?></span>
115 </button>
116 <h3>
117 <span class="customize-action"><?php esc_html_e('Setting', 'loftloader'); ?></span><?php echo $this->title; ?>
118 </h3>
119 </div>
120 <?php
121 if(!empty($this->description)){
122 echo '<div class="description customize-section-description">' . $this->description . '</div>';
123 }
124 ?>
125 </li>
126 </ul>
127 </li>
128 <?php
129 }
130 else{
131 parent::render();
132 }
133 }
134 }
135
136 // LoftLoader base customize control class: add class properties as displaying dependency.
137 class LoftLoader_Customize_Control extends WP_Customize_Control{
138 public $filter = false;
139 public $parent_setting_id = '';
140 public $show_filter = array();
141 public $img = '';
142 public $href = '';
143 public function active_callback(){
144 if($this->filter && ($this->manager->get_setting($this->parent_setting_id) instanceof WP_Customize_Setting) && !empty($this->show_filter)){
145 $parent_setting_value = $this->manager->get_setting($this->parent_setting_id)->value();
146 return in_array($parent_setting_value, $this->show_filter) ? true : false;
147 }
148 return true;
149 }
150 public function render_content(){
151 switch($this->type){
152 case 'loftloader-ad':
153 if(!empty($this->label)) : ?> <span class="customize-control-title"><?php echo esc_html($this->label); ?></span> <?php endif;
154 if(!empty($this->img)) : ?> <a href="<?php echo $this->href; ?>" target="_blank"><img src="<?php echo esc_url($this->img); ?>" ></a> <?php endif; ?>
155 <div class="customize-control-notifications-container"></div> <?php
156 break;
157 case 'loftloader-any-page':
158 if(!empty($this->label)) : ?> <span class="customize-control-title"><?php echo esc_html($this->label); ?></span> <?php endif;
159 if(!empty( $this->description)) : ?> <span class="description customize-control-description"><?php echo $this->description ; ?></span> <?php endif; ?>
160 <input type="button" <?php $this->link(); ?> class="button button-primary loftloader-any-page-generate" value="<?php esc_attr_e('Generate', 'loftloader'); ?>" /><br/><br/>
161 <textarea class="loftloader-any-page-shortcode" cols="30" rows="4"></textarea>
162 <div class="customize-control-notifications-container"></div> <?php
163 break;
164 case 'check': ?>
165 <label> <?php
166 if(!empty( $this->label)) : ?>
167 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
168 endif;
169 if(!empty( $this->description)) : ?>
170 <span class="description customize-control-description"><?php echo $this->description; ?></span>
171 <?php endif; ?>
172 <input class="loftlader-checkbox" type="checkbox" value="on" name="<?php echo $this->id; ?>" <?php checked( 'on', $this->value() ); ?> />
173 <input style="display:none;" type="checkbox" value="on" <?php $this->link(); ?> <?php checked( 'on', $this->value() ); ?> />
174 </label> <?php break;
175 default:
176 parent::render_content();
177 }
178 }
179 }
180 // Modify the color control class to add the display dependency logic.
181 class LoftLoader_Customize_Color_Control extends WP_Customize_Color_Control{
182 public $filter = false;
183 public $parent_setting_id = '';
184 public $show_filter = array();
185 public function active_callback(){
186 if($this->filter && ($this->manager->get_setting($this->parent_setting_id) instanceof WP_Customize_Setting) && !empty($this->show_filter)){
187 $parent_setting_value = $this->manager->get_setting($this->parent_setting_id)->value();
188 return in_array($parent_setting_value, $this->show_filter) ? true : false;
189 }
190 return true;
191 }
192 }
193 // Modify the image control class to add the display dependency logic.
194 class LoftLoader_Customize_Image_Control extends WP_Customize_Image_Control{
195 public $filter = false;
196 public $parent_setting_id = '';
197 public $show_filter = array();
198 public function active_callback(){
199 if($this->filter && ($this->manager->get_setting($this->parent_setting_id) instanceof WP_Customize_Setting) && !empty($this->show_filter)){
200 $parent_setting_value = $this->manager->get_setting($this->parent_setting_id)->value();
201 return in_array($parent_setting_value, $this->show_filter) ? true : false;
202 }
203 return true;
204 }
205 }
206 // Add new slider control class with jqueryui slider function
207 class LoftLoader_Customize_Slider_Control extends LoftLoader_Customize_Control{
208 public $input_class = '';
209 public $after_text = '%';
210 public function render_content(){
211 if ( empty( $this->input_attrs ) )
212 return;
213
214 echo '<label class="amount opacity">';
215 if ( ! empty( $this->label ) ) : ?>
216 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
217 <?php endif; ?>
218 <span class="<?php echo $this->input_class; ?>">
219 <input readonly="readonly" type="text" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>" >
220 <?php echo $this->after_text; ?>
221 </span>
222 <?php
223 echo '</label>';
224 ?>
225 <div class="ui-slider loader-ui-slider" data-value="<?php echo $this->manager->get_setting($this->id)->value(); ?>" <?php $this->input_attrs(); ?>></div>
226 <div class="customize-control-notifications-container"></div>
227 <?php
228 }
229 }
230 // Add new radio type control class for loader animation choices.
231 class LoftLoader_Customize_Animation_Types_Control extends WP_Customize_Control{
232 public function render_content(){
233 if ( empty( $this->choices ) )
234 return;
235
236 if ( ! empty( $this->label ) ) : ?>
237 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
238 <?php endif;
239 echo '<button class="customize-more-toggle" aria-expanded="false"><span class="screen-reader-text">' . esc_html__('More info', 'loftloader') . '</span></button>';
240 if ( ! empty( $this->description ) ) : ?>
241 <span class="description customize-control-description" style="display: none;"><?php echo $this->description ; ?></span>
242 <?php endif; ?>
243
244 <div id="loftloader_option_animation">
245 <?php
246 $name = '_customize-radio-' . $this->id;
247 foreach ( $this->choices as $value => $attrs ) :
248 $attr = '';
249 if(!empty($attrs['attr'])){
250 foreach((array)$attrs['attr'] as $attr_name => $attr_value){
251 $attr .= ' ' . $attr_name . '="' . $attr_value . '"';
252 }
253 }
254 $item_id = sanitize_title($this->id . '-' . $value);
255 ?>
256 <label for="<?php echo $item_id; ?>" title="<?php echo esc_attr($attrs['label']); ?>">
257 <input id="<?php echo $item_id; ?>" class="loftloader-radiobtn <?php echo $value; ?>" type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> <?php echo $attr; ?> />
258 <span></span>
259 </label>
260 <?php endforeach; ?>
261 </div>
262 <?php
263 }
264 }
265 // Add new number type control class with text after the element.
266 class LoftLoader_Customize_Number_Text_Control extends LoftLoader_Customize_Control{
267 public $after_text = '';
268 public $input_class = '';
269 public $input_wrap_class = '';
270 public function render_content(){
271 ?>
272 <label>
273 <?php if ( ! empty( $this->label ) ) : ?>
274 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
275 <?php endif;
276 if ( ! empty( $this->description ) ) : ?>
277 <span class="description customize-control-description"><?php echo $this->description; ?></span>
278 <?php endif; ?>
279 <span class="<?php echo esc_attr($this->input_wrap_class); ?>">
280 <input class="<?php echo esc_attr($this->input_class); ?>" type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> /><?php echo empty($this->after_text) ? '' : $this->after_text; ?>
281 </span>
282 </label>
283 <?php
284 }
285 }
286
287 if(!function_exists('loftloader_sanitize_checkbox')){
288 /**
289 * Check the switch checkbox value
290 *
291 * @param string the value from user
292 * @return mix if set return string 'on', otherwise return false
293 */
294 function loftloader_sanitize_checkbox($input){
295 return empty($input) ? 'off' : 'on';
296 }
297 }
298
299 if(!function_exists('loftloader_sanitize_choice')){
300 /**
301 * Check the value is one of the choices from customize control
302 *
303 * @param string the value from user
304 * @param object customize setting object
305 * @return string the value from user or the default setting value
306 */
307
308 function loftloader_sanitize_choice($input, $setting){
309 $choices = $setting->manager->get_control($setting->id)->choices;
310 $choices = array_keys($choices);
311 return in_array($input, $choices) ? $input : $setting->default;
312 }
313 }
314 }
315