PluginProbe
LoftLoader / 2.0.0
LoftLoader v2.0.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.0.0, at inc/class-loftloader-customize.php

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