PluginProbe
LoftLoader / 2.1.5
LoftLoader v2.1.5
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.5, at inc/class-loftloader-customize.php

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