Version Description
Download this release
Release Info
Developer | _smartik_ |
Plugin | SMK Sidebar Generator |
Version | 3.2.0 |
Comparing to | |
See all releases |
Version 3.2.0
- abstract.php +481 -0
- apply.php +64 -0
- assets/scripts.js +312 -0
- assets/styles.css +272 -0
- condition-cpt.php +121 -0
- condition.php +59 -0
- html.php +121 -0
- lang/smk-sidebar-generator-ro_RO.mo +0 -0
- lang/smk-sidebar-generator-ro_RO.po +137 -0
- lang/smk-sidebar-generator.pot +138 -0
- readme.md +93 -0
- readme.txt +104 -0
- render.php +570 -0
- smk-sidebar-generator.php +173 -0
abstract.php
ADDED
@@ -0,0 +1,481 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* SMK Sidebar Generator Abstract
|
4 |
+
*
|
5 |
+
* -------------------------------------------------------------------------------------
|
6 |
+
* @Author: Smartik
|
7 |
+
* @Author URI: http://smartik.ws/
|
8 |
+
* @Copyright: (c) 2014 Smartik. All rights reserved
|
9 |
+
* -------------------------------------------------------------------------------------
|
10 |
+
*
|
11 |
+
*/
|
12 |
+
|
13 |
+
// Do not allow direct access to this file.
|
14 |
+
if( ! function_exists('add_action') )
|
15 |
+
die();
|
16 |
+
|
17 |
+
// Start object
|
18 |
+
if( ! class_exists('Smk_Sidebar_Generator_Abstract')) {
|
19 |
+
abstract class Smk_Sidebar_Generator_Abstract {
|
20 |
+
|
21 |
+
//------------------------------------//--------------------------------------//
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Plugin version
|
25 |
+
*
|
26 |
+
* Return the current plugin version.
|
27 |
+
*
|
28 |
+
* @return string
|
29 |
+
*/
|
30 |
+
protected $version;
|
31 |
+
|
32 |
+
//------------------------------------//--------------------------------------//
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Html helpers
|
36 |
+
*
|
37 |
+
* Allows to create different HTML elements
|
38 |
+
*
|
39 |
+
* @return string
|
40 |
+
*/
|
41 |
+
protected $html;
|
42 |
+
|
43 |
+
//------------------------------------//--------------------------------------//
|
44 |
+
|
45 |
+
public function __construct(){
|
46 |
+
$this->version = smk_sidebar_version();
|
47 |
+
$this->html = new Smk_Sidebar_Generator_Html;
|
48 |
+
}
|
49 |
+
|
50 |
+
//------------------------------------//--------------------------------------//
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Plugin Settings
|
54 |
+
*
|
55 |
+
* Inner plugin settings.
|
56 |
+
*
|
57 |
+
* @return array
|
58 |
+
*/
|
59 |
+
abstract protected function pluginSettings();
|
60 |
+
|
61 |
+
//------------------------------------//--------------------------------------//
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Page
|
65 |
+
*
|
66 |
+
* Create the admin page
|
67 |
+
*
|
68 |
+
* @return string
|
69 |
+
*/
|
70 |
+
abstract public function page();
|
71 |
+
|
72 |
+
//------------------------------------//--------------------------------------//
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Init the object
|
76 |
+
*
|
77 |
+
* Create a new instance of this plugin.
|
78 |
+
*
|
79 |
+
* @return void
|
80 |
+
*/
|
81 |
+
public function init(){
|
82 |
+
add_action( 'admin_menu', array( $this, 'menu' ) );
|
83 |
+
add_action( 'admin_init', array( $this, 'registerSetting' ) );
|
84 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 99 );
|
85 |
+
add_action( 'widgets_init', array( $this, 'registerGeneratedSidebars' ) );
|
86 |
+
|
87 |
+
$this->setup();
|
88 |
+
|
89 |
+
// update from v2
|
90 |
+
$this->updateSidebarsFromV2();
|
91 |
+
}
|
92 |
+
|
93 |
+
//------------------------------------//--------------------------------------//
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Add to init object
|
97 |
+
*
|
98 |
+
* Add to init object.
|
99 |
+
*
|
100 |
+
* @return void
|
101 |
+
*/
|
102 |
+
public function setup(){}
|
103 |
+
|
104 |
+
//------------------------------------//--------------------------------------//
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Register setting
|
108 |
+
*
|
109 |
+
* Register setting. This allows to update the option on form submit.
|
110 |
+
*
|
111 |
+
* @hook admin_init
|
112 |
+
* @return void
|
113 |
+
*/
|
114 |
+
public function registerSetting() {
|
115 |
+
$settings = $this->pluginSettings();
|
116 |
+
register_setting( $settings['settings_register_name'], $settings['option_name']/*, array( &$this, 'sanitizeData' )*/ );
|
117 |
+
}
|
118 |
+
|
119 |
+
//------------------------------------//--------------------------------------//
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Sanitize data
|
123 |
+
*
|
124 |
+
* Sanitize the data sent to the server. Unset all invalid or empty(none) conditions.
|
125 |
+
*
|
126 |
+
* @return array The sanitized data
|
127 |
+
*/
|
128 |
+
// public function sanitizeData( $data ) {
|
129 |
+
// if( is_array( $data ) && !empty( $data ) ){
|
130 |
+
// $new_data = $data;
|
131 |
+
// foreach ($data as $sidebar_id => $sidebar_settings) {
|
132 |
+
// if( !empty($sidebar_settings['conditions']) && is_array($sidebar_settings['conditions']) ){
|
133 |
+
// foreach ($sidebar_settings['conditions'] as $key => $condition) {
|
134 |
+
// if( !empty($condition['if']) && $condition['if'] == 'none' ){
|
135 |
+
// unset( $new_data[ $sidebar_id ]['conditions'][ $key ] );
|
136 |
+
// }
|
137 |
+
// else{
|
138 |
+
// continue;
|
139 |
+
// }
|
140 |
+
// }
|
141 |
+
// }
|
142 |
+
// }
|
143 |
+
// $data = $new_data;
|
144 |
+
// }
|
145 |
+
// return $data;
|
146 |
+
// }
|
147 |
+
|
148 |
+
//------------------------------------//--------------------------------------//
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Sidebar Widgets
|
152 |
+
*
|
153 |
+
* Get all sidebar with all widgets assigned to it.
|
154 |
+
*
|
155 |
+
* @return array
|
156 |
+
*/
|
157 |
+
public function sidebarWidgets(){
|
158 |
+
return wp_get_sidebars_widgets();
|
159 |
+
}
|
160 |
+
|
161 |
+
//------------------------------------//--------------------------------------//
|
162 |
+
|
163 |
+
/**
|
164 |
+
* All saved widgets types
|
165 |
+
*
|
166 |
+
* Get all saved widget types.
|
167 |
+
*
|
168 |
+
* @return array
|
169 |
+
*/
|
170 |
+
public function widgetsTypes(){
|
171 |
+
$all = $this->sidebarWidgets();
|
172 |
+
$widgets = array();
|
173 |
+
foreach ($all as $part) {
|
174 |
+
foreach ($part as $key => $widget) {
|
175 |
+
$widget_option_name = 'widget_'. substr($widget, 0, -2);
|
176 |
+
$widgets[ $widget_option_name ] = $widget_option_name;
|
177 |
+
}
|
178 |
+
}
|
179 |
+
return $widgets;
|
180 |
+
}
|
181 |
+
|
182 |
+
//------------------------------------//--------------------------------------//
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Widgets Options
|
186 |
+
*
|
187 |
+
* Get all data(options) for each widget type.
|
188 |
+
*
|
189 |
+
* @return array
|
190 |
+
*/
|
191 |
+
public function widgetsOptions(){
|
192 |
+
$options = array();
|
193 |
+
foreach ($this->widgetsTypes() as $key => $value) {
|
194 |
+
$options[ $value ] = get_option( $value );
|
195 |
+
}
|
196 |
+
return $options;
|
197 |
+
}
|
198 |
+
|
199 |
+
//------------------------------------//--------------------------------------//
|
200 |
+
|
201 |
+
/**
|
202 |
+
* All registered sidebars
|
203 |
+
*
|
204 |
+
* Get all registered sidebars.
|
205 |
+
*
|
206 |
+
* @return array
|
207 |
+
*/
|
208 |
+
public function allRegisteredSidebars(){
|
209 |
+
global $wp_registered_sidebars;
|
210 |
+
$all_sidebars = array();
|
211 |
+
|
212 |
+
if ( $wp_registered_sidebars && ! is_wp_error( $wp_registered_sidebars ) ) {
|
213 |
+
|
214 |
+
foreach ( $wp_registered_sidebars as $sidebar ) {
|
215 |
+
$all_sidebars[ $sidebar['id'] ] = $sidebar;
|
216 |
+
}
|
217 |
+
|
218 |
+
}
|
219 |
+
|
220 |
+
return $all_sidebars;
|
221 |
+
}
|
222 |
+
|
223 |
+
//------------------------------------//--------------------------------------//
|
224 |
+
|
225 |
+
/**
|
226 |
+
* All generated sidebars
|
227 |
+
*
|
228 |
+
* Get all generated sidebars.
|
229 |
+
*
|
230 |
+
* @return array
|
231 |
+
*/
|
232 |
+
public function allGeneratedSidebars(){
|
233 |
+
$all = get_option( $this->pluginSettings('option_name'), array() );
|
234 |
+
if( !empty( $all['sidebars'] ) ){
|
235 |
+
return $all['sidebars'];
|
236 |
+
}
|
237 |
+
else{
|
238 |
+
return array();
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
//------------------------------------//--------------------------------------//
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Register sidebars
|
246 |
+
*
|
247 |
+
* Register all generated sidebars
|
248 |
+
*
|
249 |
+
* @hook widgets_init
|
250 |
+
* @return void
|
251 |
+
*/
|
252 |
+
public function registerGeneratedSidebars() {
|
253 |
+
|
254 |
+
//Catch saved options
|
255 |
+
$sidebars = get_option( $this->pluginSettings('option_name'), array() );
|
256 |
+
|
257 |
+
//Make sure if we have valid sidebars
|
258 |
+
if ( !empty( $sidebars['sidebars'] ) && is_array( $sidebars['sidebars'] ) ){
|
259 |
+
|
260 |
+
//Register each sidebar
|
261 |
+
foreach ($sidebars['sidebars'] as $sidebar) {
|
262 |
+
if( isset($sidebar) && !empty($sidebar) ){
|
263 |
+
|
264 |
+
register_sidebar(
|
265 |
+
array(
|
266 |
+
'name' => $sidebar['name'],
|
267 |
+
'id' => $sidebar['id'],
|
268 |
+
'description' => $sidebar['description'],
|
269 |
+
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
270 |
+
'after_widget' => '</div>',
|
271 |
+
'before_title' => '<h3 class="widget-title">',
|
272 |
+
'after_title' => '</h3>'
|
273 |
+
)
|
274 |
+
);
|
275 |
+
|
276 |
+
}
|
277 |
+
}
|
278 |
+
|
279 |
+
}
|
280 |
+
|
281 |
+
}
|
282 |
+
|
283 |
+
//------------------------------------//--------------------------------------//
|
284 |
+
|
285 |
+
/**
|
286 |
+
* All static sidebars
|
287 |
+
*
|
288 |
+
* Get all static sidebars.
|
289 |
+
*
|
290 |
+
* @return array
|
291 |
+
*/
|
292 |
+
public function allStaticSidebars(){
|
293 |
+
$all = $this->allRegisteredSidebars();
|
294 |
+
$generated = $this->allGeneratedSidebars();
|
295 |
+
$static = array();
|
296 |
+
foreach ( $all as $key => $value) {
|
297 |
+
if( ! array_key_exists($key, $generated) ){
|
298 |
+
$static[ $key ] = $value;
|
299 |
+
}
|
300 |
+
}
|
301 |
+
return $static;
|
302 |
+
}
|
303 |
+
|
304 |
+
//------------------------------------//--------------------------------------//
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Menu
|
308 |
+
*
|
309 |
+
* Create a new submenu for this plugin.
|
310 |
+
*
|
311 |
+
* @hook admin_menu
|
312 |
+
* @uses $this->page() to get the page display.
|
313 |
+
* @return void
|
314 |
+
*/
|
315 |
+
public function menu(){
|
316 |
+
$settings = $this->pluginSettings();
|
317 |
+
|
318 |
+
add_submenu_page(
|
319 |
+
$settings['menu_parent'],
|
320 |
+
$settings['name'],
|
321 |
+
$settings['name'],
|
322 |
+
$settings['capability'],
|
323 |
+
$settings['slug'],
|
324 |
+
array( $this, 'page' )
|
325 |
+
);
|
326 |
+
}
|
327 |
+
|
328 |
+
//------------------------------------//--------------------------------------//
|
329 |
+
|
330 |
+
/**
|
331 |
+
* Enqueue
|
332 |
+
*
|
333 |
+
* Enqueue scripts and styles
|
334 |
+
*
|
335 |
+
* @hook admin_enqueue_scripts
|
336 |
+
* @return void
|
337 |
+
*/
|
338 |
+
public function enqueue(){
|
339 |
+
if( $this->isPluginPage() ){
|
340 |
+
$depend = array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-slider');
|
341 |
+
|
342 |
+
wp_register_style( 'smk-sidebar-generator', $this->uri() . 'assets/styles.css', '', $this->version );
|
343 |
+
wp_register_script( 'smk-sidebar-generator', $this->uri() . 'assets/scripts.js', $depend, $this->version, true );
|
344 |
+
wp_enqueue_style( 'smk-sidebar-generator' );
|
345 |
+
wp_enqueue_script( 'smk-sidebar-generator' );
|
346 |
+
}
|
347 |
+
}
|
348 |
+
|
349 |
+
//------------------------------------//--------------------------------------//
|
350 |
+
|
351 |
+
/**
|
352 |
+
* Is plugin page
|
353 |
+
*
|
354 |
+
* Check if the current page is plugin page.
|
355 |
+
*
|
356 |
+
* @return bool
|
357 |
+
*/
|
358 |
+
public function isPluginPage(){
|
359 |
+
$settings = $this->pluginSettings();
|
360 |
+
return isset( $_GET['page'] ) && $_GET['page'] == $settings['slug'] ? true : false;
|
361 |
+
}
|
362 |
+
|
363 |
+
//------------------------------------//--------------------------------------//
|
364 |
+
|
365 |
+
/**
|
366 |
+
* Plugin path
|
367 |
+
*
|
368 |
+
* Absolute plugin path.
|
369 |
+
*
|
370 |
+
* @return string
|
371 |
+
*/
|
372 |
+
public function path(){
|
373 |
+
return plugin_dir_path( __FILE__ );
|
374 |
+
}
|
375 |
+
|
376 |
+
//------------------------------------//--------------------------------------//
|
377 |
+
|
378 |
+
/**
|
379 |
+
* Plugin URI
|
380 |
+
*
|
381 |
+
* Absolute plugin URI.
|
382 |
+
*
|
383 |
+
* @return string
|
384 |
+
*/
|
385 |
+
public function uri(){
|
386 |
+
return plugin_dir_url( __FILE__ );
|
387 |
+
}
|
388 |
+
|
389 |
+
//------------------------------------//--------------------------------------//
|
390 |
+
|
391 |
+
/**
|
392 |
+
* The prefix for sidebar ID
|
393 |
+
*
|
394 |
+
* Generate the prefix for sidebar ID based on current WP setup
|
395 |
+
*
|
396 |
+
* @return string
|
397 |
+
*/
|
398 |
+
public function prefix(){
|
399 |
+
$theme = get_option( 'current_theme', '' );
|
400 |
+
$wordpress_version = get_bloginfo( 'version', '' );
|
401 |
+
// Make the prefix
|
402 |
+
$string = 's' . substr( $theme, 0, 1 ) . $wordpress_version;
|
403 |
+
$string = preg_replace('/[^\w-]/', '', $string);
|
404 |
+
return strtolower( $string ) . '_';
|
405 |
+
}
|
406 |
+
|
407 |
+
//------------------------------------//--------------------------------------//
|
408 |
+
|
409 |
+
/**
|
410 |
+
* Sidebars from v2
|
411 |
+
*
|
412 |
+
* Get all sidebars generated by Smk Sidebars generator v2, move and convert them
|
413 |
+
* for v3 and delete old data. Backwards compatibility function.
|
414 |
+
*
|
415 |
+
* @return void
|
416 |
+
*/
|
417 |
+
public function updateSidebarsFromV2(){
|
418 |
+
if( false === get_transient( 'smk_sidebar_generator_option_v2' ) ){
|
419 |
+
$option_name = $this->pluginSettings('option_name');
|
420 |
+
$old = get_option( 'smk_sidebar_generator_option', array() );
|
421 |
+
$new = get_option( $option_name, array() );
|
422 |
+
$final = $new;
|
423 |
+
|
424 |
+
$v2_sidebars = ! empty( $old['sidebars'] ) ? $old['sidebars'] : array();
|
425 |
+
$v3_sidebars = ! empty( $new['sidebars'] ) ? $new['sidebars'] : array();
|
426 |
+
|
427 |
+
$v2 = array();
|
428 |
+
foreach ($v2_sidebars as $key => $value) {
|
429 |
+
$v2['smk_sidebar_' . $key]['id'] = 'smk_sidebar_' . $value['id'];
|
430 |
+
$v2['smk_sidebar_' . $key]['name'] = $value['name'];
|
431 |
+
$v2['smk_sidebar_' . $key]['description'] = '';
|
432 |
+
}
|
433 |
+
|
434 |
+
$final_sidebars['sidebars'] = wp_parse_args( $v3_sidebars, $v2 );
|
435 |
+
|
436 |
+
$final = wp_parse_args( $final_sidebars, $new );
|
437 |
+
|
438 |
+
update_option( $option_name, $final );
|
439 |
+
delete_option( 'smk_sidebar_generator_option' );
|
440 |
+
set_transient( 'smk_sidebar_generator_option_v2', true );
|
441 |
+
}
|
442 |
+
}
|
443 |
+
|
444 |
+
//------------------------------------//--------------------------------------//
|
445 |
+
|
446 |
+
/**
|
447 |
+
* Debug
|
448 |
+
*
|
449 |
+
* Debud saved data
|
450 |
+
*
|
451 |
+
* @param array $data The data to debug.
|
452 |
+
* @return string
|
453 |
+
*/
|
454 |
+
public function debug($data = array(), $title = ''){
|
455 |
+
if( is_array($data) ){
|
456 |
+
array_walk_recursive( $data, array( $this, 'debugFilter' ) );
|
457 |
+
}
|
458 |
+
if( !empty($title) ){
|
459 |
+
echo '<h3>'. $title .'</h3>';
|
460 |
+
}
|
461 |
+
echo '<pre>';
|
462 |
+
print_r($data);
|
463 |
+
echo '</pre>';
|
464 |
+
}
|
465 |
+
|
466 |
+
//------------------------------------//--------------------------------------//
|
467 |
+
|
468 |
+
/**
|
469 |
+
* Debug filter
|
470 |
+
*
|
471 |
+
* Debud filter special characters.
|
472 |
+
*
|
473 |
+
* @param array $data The data to filter.
|
474 |
+
* @return array
|
475 |
+
*/
|
476 |
+
public function debugFilter(&$data){
|
477 |
+
$data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
|
478 |
+
}
|
479 |
+
|
480 |
+
} // class
|
481 |
+
} // class_exists
|
apply.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Do not allow direct access to this file.
|
3 |
+
if( ! function_exists('add_action') )
|
4 |
+
die();
|
5 |
+
|
6 |
+
// Start object
|
7 |
+
if( ! class_exists('Smk_Sidebar_Generator_Apply')) {
|
8 |
+
class Smk_Sidebar_Generator_Apply extends Smk_Sidebar_Generator{
|
9 |
+
|
10 |
+
public function __construct(){
|
11 |
+
parent::__construct();
|
12 |
+
add_filter( 'sidebars_widgets', array( $this, 'letsDoIt') );
|
13 |
+
}
|
14 |
+
|
15 |
+
public function letsDoIt( $sidebars ){
|
16 |
+
$all_possible_conditions = smk_sidebar_conditions_filter();
|
17 |
+
$generated_data = $this->allGeneratedSidebars();
|
18 |
+
|
19 |
+
foreach ($generated_data as $sidebar_id => $sidebar_settings) {
|
20 |
+
$sidebars_to_replace = !empty($sidebar_settings['replace']) ? $sidebar_settings['replace'] : false;
|
21 |
+
$conditions = !empty($sidebar_settings['conditions']) && is_array($sidebar_settings['conditions']) ? $sidebar_settings['conditions'] : false;
|
22 |
+
$enabled_conditions = !empty($sidebar_settings['enable-conditions']) && 'enabled' == $sidebar_settings['enable-conditions'] ? $sidebar_settings['enable-conditions'] : false;
|
23 |
+
|
24 |
+
// If conditions are enabled
|
25 |
+
if( $sidebars_to_replace && $enabled_conditions && $conditions ){
|
26 |
+
foreach ($conditions as $condition) {
|
27 |
+
if( !empty($condition['if']) && 'none' !== $condition['if'] ){
|
28 |
+
$the_type = explode('::', $condition['if']);
|
29 |
+
if( !empty( $the_type[0] ) && !empty( $the_type[1] ) ){
|
30 |
+
if( array_key_exists($the_type[0], $all_possible_conditions) ){
|
31 |
+
$class = $all_possible_conditions[ $the_type[0] ];
|
32 |
+
if( class_exists($class) ){
|
33 |
+
$newclass = new $class;
|
34 |
+
$second_condition = ( !empty($condition['equalto']) ) ? $condition['equalto'] : array();
|
35 |
+
$can_replace = $newclass->canReplace( $the_type[1], $second_condition );
|
36 |
+
if( $can_replace ){
|
37 |
+
foreach ($sidebars_to_replace as $sidebar_to_replace_id) {
|
38 |
+
if( array_key_exists($sidebar_to_replace_id, $sidebars) && isset($sidebars[ $sidebar_id ]) ){
|
39 |
+
$sidebars[ $sidebar_to_replace_id ] = $sidebars[ $sidebar_id ];
|
40 |
+
}
|
41 |
+
}
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
// If conditions are not enabled and is selected at least one sidebar to replace
|
51 |
+
elseif( $sidebars_to_replace ){
|
52 |
+
foreach ($sidebars_to_replace as $sidebar_to_replace_id) {
|
53 |
+
if( array_key_exists($sidebar_to_replace_id, $sidebars) && isset($sidebars[ $sidebar_id ]) ){
|
54 |
+
$sidebars[ $sidebar_to_replace_id ] = $sidebars[ $sidebar_id ];
|
55 |
+
}
|
56 |
+
}
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
return $sidebars;
|
61 |
+
}
|
62 |
+
|
63 |
+
}
|
64 |
+
}
|
assets/scripts.js
ADDED
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* @Author: Smartik
|
3 |
+
* @Date: 2014-03-12 21:17:04
|
4 |
+
* @Last Modified by: Smartik
|
5 |
+
* @Last Modified time: 2014-07-16 21:09:21
|
6 |
+
*/
|
7 |
+
|
8 |
+
;(function( $ ) {
|
9 |
+
"use strict";
|
10 |
+
|
11 |
+
$(document).ready(function(){
|
12 |
+
|
13 |
+
var smkSidebarGenerator = {
|
14 |
+
|
15 |
+
// Sidebars accordion
|
16 |
+
accordion: function(){
|
17 |
+
jQuery("#smk-sidebars").on("click", "h3.accordion-section-title", function(){
|
18 |
+
var current = $(this);
|
19 |
+
|
20 |
+
if( current.parents("li.accordion-section").hasClass("open") ){
|
21 |
+
$(this).parents("li.accordion-section").removeClass("open");
|
22 |
+
$("#smk-sidebars .accordion-section-content").slideUp("fast");
|
23 |
+
}
|
24 |
+
else{
|
25 |
+
$("#smk-sidebars .accordion-section-content").slideUp("fast");
|
26 |
+
$(this).next().slideDown("fast");
|
27 |
+
|
28 |
+
$("#smk-sidebars li.accordion-section").removeClass("open");
|
29 |
+
$(this).parents("li.accordion-section").addClass("open");
|
30 |
+
}
|
31 |
+
});
|
32 |
+
},
|
33 |
+
|
34 |
+
// Close all accordion sections
|
35 |
+
closeAllAccordionSections: function(){
|
36 |
+
$("#smk-sidebars li.accordion-section").removeClass("open");
|
37 |
+
$("#smk-sidebars .accordion-section-content").slideUp("fast");
|
38 |
+
},
|
39 |
+
|
40 |
+
// Make accordion sections sortable
|
41 |
+
sortableAccordionSections: function(){
|
42 |
+
var blocks = jQuery("#smk-sidebars ul.connected-sidebars-lists, #smk-removed-sidebars ul");
|
43 |
+
blocks.sortable({
|
44 |
+
items: "> li",
|
45 |
+
axis: "y",
|
46 |
+
tolerance: "pointer",
|
47 |
+
connectWith: ".connected-sidebars-lists",
|
48 |
+
handle: ".smk-sidebar-section-icon",
|
49 |
+
// cancel: '.moderate-sidebar, .accordion-section-content',
|
50 |
+
start: function( event, ui ) {
|
51 |
+
smkSidebarGenerator.closeAllAccordionSections();
|
52 |
+
}
|
53 |
+
});
|
54 |
+
blocks.find('h3.accordion-section-title').disableSelection();
|
55 |
+
},
|
56 |
+
|
57 |
+
// Random ID
|
58 |
+
randomID: function(_nr, mode){
|
59 |
+
var text = "",
|
60 |
+
nb = "0123456789",
|
61 |
+
lt = "abcdefghijklmnopqrstuvwxyz",
|
62 |
+
possible;
|
63 |
+
if( mode == 'l' ){
|
64 |
+
possible = lt;
|
65 |
+
}
|
66 |
+
else if( mode == 'n' ){
|
67 |
+
possible = nb;
|
68 |
+
}
|
69 |
+
else{
|
70 |
+
possible = nb + lt;
|
71 |
+
}
|
72 |
+
|
73 |
+
for( var i=0; i < _nr; i++ ){
|
74 |
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
75 |
+
}
|
76 |
+
|
77 |
+
return text;
|
78 |
+
},
|
79 |
+
|
80 |
+
// Add new sidebar
|
81 |
+
addNew: function(){
|
82 |
+
|
83 |
+
var counter = $('#smk-sidebar-generator-counter').val();
|
84 |
+
counter = ( counter ) ? parseInt( counter, 10 ) : 0;
|
85 |
+
|
86 |
+
jQuery(".add-new-sidebar").on("click", function(event){
|
87 |
+
counter = counter + 1;
|
88 |
+
var template = $('.sidebar-template').clone(),
|
89 |
+
sidebar_prefix = $(this).data('sidebars-prefix'),
|
90 |
+
id = sidebar_prefix + counter + smkSidebarGenerator.randomID(2, 'n') + smkSidebarGenerator.randomID(3, 'l');
|
91 |
+
|
92 |
+
template.removeClass('sidebar-template');
|
93 |
+
|
94 |
+
// Inputs
|
95 |
+
template.find('input, select').each(function(){
|
96 |
+
var name = $(this).attr('name');
|
97 |
+
var value = $(this).attr('value');
|
98 |
+
$(this).attr( 'name', name.replace( '__id__', id ) );
|
99 |
+
if( $(this).attr( 'value' ) ){
|
100 |
+
$(this).attr( 'value', value.replace( '__id__', id ).replace( '__index__', counter ) );
|
101 |
+
}
|
102 |
+
});
|
103 |
+
|
104 |
+
// Condition button
|
105 |
+
var new_button_name = template.find('.condition-add').data( 'name' ).replace( '__id__', id );
|
106 |
+
template.find('.condition-add').attr( 'data-name', new_button_name );
|
107 |
+
template.find('.condition-add').attr( 'data-sidebar-id', id );
|
108 |
+
|
109 |
+
// Index
|
110 |
+
var h3 = template.find('h3.accordion-section-title span.name').html().replace( '__index__', counter );
|
111 |
+
template.find('h3.accordion-section-title span.name').html( h3 );
|
112 |
+
|
113 |
+
// Shortcode
|
114 |
+
var shortcode = template.find('.smk-sidebar-shortcode').html().replace( '__id__', id );
|
115 |
+
template.find('.smk-sidebar-shortcode').html( shortcode );
|
116 |
+
|
117 |
+
// Template ID
|
118 |
+
var template_id = template.attr('id');
|
119 |
+
template.attr('id', template_id.replace( '__id__', id ))
|
120 |
+
|
121 |
+
// Close other accordion sections
|
122 |
+
smkSidebarGenerator.closeAllAccordionSections();
|
123 |
+
|
124 |
+
// Append the new sidebar as a new accordion section and slide down it
|
125 |
+
template.appendTo('#smk-sidebars ul.connected-sidebars-lists').addClass("open").hide();
|
126 |
+
template.find(".accordion-section-content").show();
|
127 |
+
template.slideDown('fast');
|
128 |
+
|
129 |
+
$('#smk-sidebar-generator-counter').val( counter );
|
130 |
+
|
131 |
+
event.stopImmediatePropagation();
|
132 |
+
}).disableSelection();
|
133 |
+
},
|
134 |
+
|
135 |
+
// Live name and description update
|
136 |
+
liveSet: function(){
|
137 |
+
var container = jQuery('#smk-sidebars');
|
138 |
+
|
139 |
+
container.on('change', '.smk-sidebar-name', function(){
|
140 |
+
$(this).parents('li').find('h3.accordion-section-title span.name').html( $(this).val() );
|
141 |
+
|
142 |
+
}).on('keyup', '.smk-sidebar-name', function(){
|
143 |
+
$(this).parents('li').find('h3.accordion-section-title span.name').html( $(this).val() );
|
144 |
+
|
145 |
+
});
|
146 |
+
|
147 |
+
container.on('change', '.smk-sidebar-description', function(){
|
148 |
+
$(this).parents('li').find('h3.accordion-section-title span.description').html( $(this).val() );
|
149 |
+
|
150 |
+
}).on('keyup', '.smk-sidebar-description', function(){
|
151 |
+
$(this).parents('li').find('h3.accordion-section-title span.description').html( $(this).val() );
|
152 |
+
|
153 |
+
});
|
154 |
+
},
|
155 |
+
|
156 |
+
// Delete sidebar
|
157 |
+
deleteSidebar: function(){
|
158 |
+
jQuery("#smk-sidebars").on("click", ".smk-delete-sidebar", function(){
|
159 |
+
|
160 |
+
$('.wrap').addClass('sbg-removed-active');// Show removed sidebars
|
161 |
+
|
162 |
+
$(this).parents('li').slideUp('fast', function() {
|
163 |
+
$(this).find('.accordion-section-content').hide();
|
164 |
+
$(this).appendTo('#smk-removed-sidebars ul').slideDown('fast').removeClass('open');
|
165 |
+
});
|
166 |
+
});
|
167 |
+
},
|
168 |
+
|
169 |
+
// Restore sidebar
|
170 |
+
restoreSidebar: function(){
|
171 |
+
jQuery("#smk-removed-sidebars").on("click", ".smk-restore-sidebar", function(){
|
172 |
+
$(this).parents('li').slideUp('fast', function() {
|
173 |
+
$(this).find('.accordion-section-content').hide();
|
174 |
+
$(this).appendTo('#smk-sidebars ul.connected-sidebars-lists').slideDown('fast').removeClass('open');
|
175 |
+
});
|
176 |
+
});
|
177 |
+
},
|
178 |
+
|
179 |
+
// Get specific options for current condition choice via ajax
|
180 |
+
targetIfCondition: function(){
|
181 |
+
jQuery("#smk-sidebars").on("change", ".condition-if", function(){
|
182 |
+
var condition_parent = $(this).parents('.condition-parent'),
|
183 |
+
selected = $(this).val(),
|
184 |
+
to_change = condition_parent.find('.condition-equalto');
|
185 |
+
|
186 |
+
to_change.empty();
|
187 |
+
|
188 |
+
jQuery.ajax({
|
189 |
+
type: "POST",
|
190 |
+
url: ajaxurl,
|
191 |
+
dataType: "json",
|
192 |
+
data: {
|
193 |
+
'action': 'smk-sidebar-generator_load_equalto',
|
194 |
+
'data': { condition_if: selected }
|
195 |
+
},
|
196 |
+
success: function(response){
|
197 |
+
$.each(response, function(key, value) {
|
198 |
+
to_change.prepend($("<option></option>").attr("value",key).text(value));
|
199 |
+
});
|
200 |
+
|
201 |
+
$("body").append( $("<script />", {
|
202 |
+
id: 'condition_if_' + selected.replace("::", "_"),
|
203 |
+
html: response
|
204 |
+
}) );
|
205 |
+
},
|
206 |
+
complete: function(response){
|
207 |
+
}
|
208 |
+
});//ajax
|
209 |
+
});
|
210 |
+
},
|
211 |
+
|
212 |
+
// Clone a condition. Mainly used to add new condition. That's a fake clone
|
213 |
+
conditionAdd: function(){
|
214 |
+
$('#smk-sidebars').on('click', '.condition-add', function( event ){
|
215 |
+
event.preventDefault();
|
216 |
+
var condition_all = $(this).prev('.created-conditions'),
|
217 |
+
_name_ = $(this).data('name'),
|
218 |
+
_sidebar_id_ = $(this).data('sidebar-id'),
|
219 |
+
cloned_elem = $('.smk-sidebars-condition-template .condition-parent').clone(),
|
220 |
+
max_index = 0;
|
221 |
+
|
222 |
+
condition_all.find('select').each(function(){
|
223 |
+
var
|
224 |
+
name = $(this).attr('name'),
|
225 |
+
this_nr = name.match(/\[(\d+)\]/),
|
226 |
+
the_number = parseInt( this_nr[1], 10 );
|
227 |
+
|
228 |
+
if( the_number > max_index ){
|
229 |
+
max_index = the_number;
|
230 |
+
}
|
231 |
+
});
|
232 |
+
|
233 |
+
cloned_elem.find('select').each(function( index, elem ){
|
234 |
+
var new_name = $(elem).attr('name');
|
235 |
+
$(elem).attr( 'name', new_name.replace( '__cond_name__', _name_ ).replace( '__id__', _sidebar_id_ ).replace( /\[\d+\]/g, '['+ (max_index + 1) +']' ) );
|
236 |
+
});
|
237 |
+
cloned_elem.find('select option').each(function(){
|
238 |
+
$(this).removeAttr('selected');
|
239 |
+
});
|
240 |
+
|
241 |
+
cloned_elem.hide(); //Hide new condition
|
242 |
+
condition_all.append( cloned_elem ); //Appent it
|
243 |
+
cloned_elem.slideDown('fast'); //... and finally slide it down
|
244 |
+
|
245 |
+
smkSidebarGenerator.sortableconditions();
|
246 |
+
});
|
247 |
+
},
|
248 |
+
|
249 |
+
// Remove a condition
|
250 |
+
conditionRemove: function(){
|
251 |
+
$('#smk-sidebars').on('click', '.condition-remove', function(){
|
252 |
+
if( $(this).parents('.created-conditions').find('.condition-parent').length > 1 ){
|
253 |
+
$(this).parents('.condition-parent').slideUp( "fast", function() {
|
254 |
+
$(this).remove();
|
255 |
+
});
|
256 |
+
}
|
257 |
+
});
|
258 |
+
},
|
259 |
+
|
260 |
+
// Enable conditions
|
261 |
+
enableConditions: function(){
|
262 |
+
$('#smk-sidebars').on('change', '.smk-sidebar-enable-conditions', function(){
|
263 |
+
var _t = $(this),
|
264 |
+
_crConditions = _t.parents('.smk-sidebar-row').children('.created-conditions'),
|
265 |
+
_conditionsBtn = _t.parents('.smk-sidebar-row').children('.condition-add');
|
266 |
+
if( _t.is( ":checked" ) ){
|
267 |
+
_crConditions.removeClass('disabled-conditions');
|
268 |
+
_conditionsBtn.removeAttr('disabled', 'disabled');
|
269 |
+
}
|
270 |
+
else{
|
271 |
+
_crConditions.addClass('disabled-conditions');
|
272 |
+
_conditionsBtn.attr('disabled', 'disabled');
|
273 |
+
}
|
274 |
+
});
|
275 |
+
},
|
276 |
+
|
277 |
+
// Make conditions sortable
|
278 |
+
sortableconditions: function(){
|
279 |
+
var blocks = jQuery("#smk-sidebars .created-conditions");
|
280 |
+
blocks.sortable({
|
281 |
+
items: "> .condition-parent",
|
282 |
+
axis: "y",
|
283 |
+
tolerance: "pointer",
|
284 |
+
handle: ".smk-sidebar-condition-icon",
|
285 |
+
// cancel: '.condition-clone, .condition-remove'
|
286 |
+
});
|
287 |
+
// blocks.disableSelection();
|
288 |
+
},
|
289 |
+
|
290 |
+
// Init all
|
291 |
+
init: function(){
|
292 |
+
smkSidebarGenerator.accordion();
|
293 |
+
smkSidebarGenerator.sortableAccordionSections();
|
294 |
+
smkSidebarGenerator.addNew();
|
295 |
+
smkSidebarGenerator.liveSet();
|
296 |
+
smkSidebarGenerator.deleteSidebar();
|
297 |
+
smkSidebarGenerator.restoreSidebar();
|
298 |
+
smkSidebarGenerator.targetIfCondition();
|
299 |
+
smkSidebarGenerator.conditionAdd();
|
300 |
+
smkSidebarGenerator.conditionRemove();
|
301 |
+
smkSidebarGenerator.enableConditions();
|
302 |
+
smkSidebarGenerator.sortableconditions();
|
303 |
+
},
|
304 |
+
|
305 |
+
};
|
306 |
+
|
307 |
+
// Construct the object
|
308 |
+
smkSidebarGenerator.init();
|
309 |
+
|
310 |
+
}); //document ready
|
311 |
+
|
312 |
+
})(jQuery);
|
assets/styles.css
ADDED
@@ -0,0 +1,272 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* @Author: Smartik
|
3 |
+
* @Date: 2014-03-12 21:17:04
|
4 |
+
* @Last Modified by: Smartik
|
5 |
+
* @Last Modified time: 2014-07-16 21:09:29
|
6 |
+
*/
|
7 |
+
/*
|
8 |
+
-------------------------------------------------------------------------------
|
9 |
+
General view
|
10 |
+
-------------------------------------------------------------------------------
|
11 |
+
*/
|
12 |
+
|
13 |
+
#smk-sidebars > ul,
|
14 |
+
#smk-removed-sidebars > ul{
|
15 |
+
min-height: 40px;
|
16 |
+
border: 1px solid #ddd;
|
17 |
+
}
|
18 |
+
#smk-sidebars > ul > li:last-of-type,
|
19 |
+
#smk-removed-sidebars > ul > li:last-of-type{
|
20 |
+
border-bottom: 0;
|
21 |
+
}
|
22 |
+
.smk-sidebars-grid{
|
23 |
+
display: block;
|
24 |
+
float: left;
|
25 |
+
width: 100%;
|
26 |
+
margin: 0;
|
27 |
+
max-width: 1000px;
|
28 |
+
}
|
29 |
+
.smk-sidebars-grid.removed-sidebars{
|
30 |
+
display: none;
|
31 |
+
}
|
32 |
+
.sbg-removed-active .smk-sidebars-grid.removed-sidebars{
|
33 |
+
display: block;
|
34 |
+
}
|
35 |
+
/*
|
36 |
+
-------------------------------------------------------------------------------
|
37 |
+
Head section
|
38 |
+
-------------------------------------------------------------------------------
|
39 |
+
*/
|
40 |
+
.smk-sidebars-list .accordion-section-title{
|
41 |
+
position: relative;
|
42 |
+
padding-right: 150px;
|
43 |
+
}
|
44 |
+
.smk-sidebars-list .accordion-section-title .description{
|
45 |
+
font-size: 13px;
|
46 |
+
font-weight: 400;
|
47 |
+
font-style: normal;
|
48 |
+
color: #666;
|
49 |
+
margin-left: 10px;
|
50 |
+
}
|
51 |
+
|
52 |
+
.smk-sidebars-list .accordion-section-title .smk-sidebar-section-icon{
|
53 |
+
padding: 0;
|
54 |
+
color: #aaa;
|
55 |
+
cursor: move;
|
56 |
+
margin-right: 5px;
|
57 |
+
}
|
58 |
+
.smk-sidebars-list .accordion-section-title .smk-sidebar-section-icon:hover{
|
59 |
+
color: #82B82B;
|
60 |
+
}
|
61 |
+
|
62 |
+
/* Moderate sidebar
|
63 |
+
------------------------------------------------*/
|
64 |
+
.smk-sidebars-list .accordion-section-title .moderate-sidebar{
|
65 |
+
position: absolute;
|
66 |
+
font-size: 13px;
|
67 |
+
font-weight: 700;
|
68 |
+
font-style: normal;
|
69 |
+
color: #5F72C0;
|
70 |
+
margin-left: 10px;
|
71 |
+
right: 30px;
|
72 |
+
top: 11px;
|
73 |
+
}
|
74 |
+
.smk-sidebars-list .accordion-section-title .moderate-sidebar span{
|
75 |
+
padding: 1px 7px;
|
76 |
+
border-radius: 2px;
|
77 |
+
display: inline-block;
|
78 |
+
}
|
79 |
+
/* Delete
|
80 |
+
------------------------------------------------*/
|
81 |
+
.smk-sidebars-list .accordion-section-title .moderate-sidebar .smk-delete-sidebar{
|
82 |
+
color: #CF0018;
|
83 |
+
}
|
84 |
+
.smk-sidebars-list .accordion-section-title .moderate-sidebar .smk-delete-sidebar:hover{
|
85 |
+
color: #fff;
|
86 |
+
background: #CF0018;
|
87 |
+
}
|
88 |
+
|
89 |
+
/* Restore
|
90 |
+
------------------------------------------------*/
|
91 |
+
.smk-sidebars-list .accordion-section-title .moderate-sidebar .smk-restore-sidebar{
|
92 |
+
color: #82B82B;
|
93 |
+
display: none;
|
94 |
+
}
|
95 |
+
.smk-sidebars-list .accordion-section-title .moderate-sidebar .smk-restore-sidebar:hover{
|
96 |
+
color: #fff;
|
97 |
+
background: #82B82B;
|
98 |
+
}
|
99 |
+
|
100 |
+
/* Removed sidebar styles
|
101 |
+
------------------------------------------------*/
|
102 |
+
#smk-removed-sidebars .accordion-section-title .description,
|
103 |
+
#smk-removed-sidebars .accordion-section-title .moderate-sidebar span{
|
104 |
+
display: none;
|
105 |
+
}
|
106 |
+
#smk-removed-sidebars .accordion-section-title .moderate-sidebar .smk-restore-sidebar{
|
107 |
+
display: inline-block;
|
108 |
+
}
|
109 |
+
|
110 |
+
/*
|
111 |
+
-------------------------------------------------------------------------------
|
112 |
+
Content section
|
113 |
+
-------------------------------------------------------------------------------
|
114 |
+
*/
|
115 |
+
.smk-sidebar-row label{
|
116 |
+
display: block;
|
117 |
+
font-weight: 700;
|
118 |
+
margin: 10px 0 5px;
|
119 |
+
}
|
120 |
+
.smk-sidebar-row input,
|
121 |
+
.smk-sidebar-row textarea,
|
122 |
+
.smk-sidebar-row select{
|
123 |
+
margin-bottom: 10px;
|
124 |
+
}
|
125 |
+
.smk-sidebar-row input[type="checkbox"]{
|
126 |
+
margin: 0 5px 0 0;
|
127 |
+
}
|
128 |
+
.smk-sidebar-row.smk-sidebar-grid-4{
|
129 |
+
display: inline-block;
|
130 |
+
float: left;
|
131 |
+
width: 29%;
|
132 |
+
margin-right: 1%;
|
133 |
+
}
|
134 |
+
.smk-sidebar-row.smk-sidebar-grid-8{
|
135 |
+
display: inline-block;
|
136 |
+
float: left;
|
137 |
+
width: 69%;
|
138 |
+
margin-left: 1%;
|
139 |
+
}
|
140 |
+
.add-new-sidebar{
|
141 |
+
font-size: 12px;
|
142 |
+
padding: 3px 6px;
|
143 |
+
margin: 0 7px;
|
144 |
+
border-radius: 2px;
|
145 |
+
cursor: pointer;
|
146 |
+
}
|
147 |
+
.add-new-sidebar:hover{}
|
148 |
+
|
149 |
+
/*
|
150 |
+
-------------------------------------------------------------------------------
|
151 |
+
Fields
|
152 |
+
-------------------------------------------------------------------------------
|
153 |
+
*/
|
154 |
+
.smk-sidebar-row .sidebars-to-replace-select{
|
155 |
+
width: 100%;
|
156 |
+
max-width: 278px;
|
157 |
+
}
|
158 |
+
.smk-sidebar-row .condition-if,
|
159 |
+
.smk-sidebar-row .condition-equalto{
|
160 |
+
width: 100%;
|
161 |
+
}
|
162 |
+
|
163 |
+
/*
|
164 |
+
-------------------------------------------------------------------------------
|
165 |
+
Conditions
|
166 |
+
-------------------------------------------------------------------------------
|
167 |
+
*/
|
168 |
+
.smk-sidebar-row .created-conditions.disabled-conditions{
|
169 |
+
position: relative;
|
170 |
+
}
|
171 |
+
.smk-sidebar-row .created-conditions.disabled-conditions,
|
172 |
+
.smk-sidebar-row .created-conditions.disabled-conditions input,
|
173 |
+
.smk-sidebar-row .created-conditions.disabled-conditions select,
|
174 |
+
.smk-sidebar-row .created-conditions.disabled-conditions textarea{
|
175 |
+
color: #aaa;
|
176 |
+
border-color: #ccc;
|
177 |
+
}
|
178 |
+
.smk-sidebar-row .created-conditions.disabled-conditions:before{
|
179 |
+
content: " ";
|
180 |
+
display: block;
|
181 |
+
position: absolute;
|
182 |
+
top: 0;
|
183 |
+
right: 0;
|
184 |
+
bottom: 0;
|
185 |
+
left: 0;
|
186 |
+
margin: 0;
|
187 |
+
padding: 0;
|
188 |
+
background: rgba(255, 255, 255, 0.35);
|
189 |
+
z-index: 10;
|
190 |
+
}
|
191 |
+
.smk-sidebar-row .created-conditions .condition-parent:nth-child(odd){
|
192 |
+
background: #fafafa;
|
193 |
+
border: 1px solid #eee;
|
194 |
+
border-left: 0;
|
195 |
+
border-right: 0;
|
196 |
+
}
|
197 |
+
.smk-sidebar-row .created-conditions .condition-parent{
|
198 |
+
position: relative;
|
199 |
+
padding-left: 30px;
|
200 |
+
padding-right: 30px;
|
201 |
+
}
|
202 |
+
.smk-sidebar-row .created-conditions .condition-parent > .conditions-first{
|
203 |
+
display: inline-block;
|
204 |
+
width: 28%;
|
205 |
+
vertical-align: top;
|
206 |
+
padding-right: 2%;
|
207 |
+
}
|
208 |
+
.smk-sidebar-row .created-conditions .condition-parent > .conditions-second{
|
209 |
+
display: inline-block;
|
210 |
+
width: 68%;
|
211 |
+
vertical-align: top;
|
212 |
+
padding-left: 2%;
|
213 |
+
}
|
214 |
+
.smk-sidebar-row .created-conditions .condition-parent .condition-label{
|
215 |
+
display: block;
|
216 |
+
margin: 5px 0 2px;
|
217 |
+
padding-left: 0;
|
218 |
+
}
|
219 |
+
.smk-sidebar-row .created-conditions .condition-parent span.condition-remove{
|
220 |
+
position: absolute;
|
221 |
+
display: block;
|
222 |
+
right: 0;
|
223 |
+
top: 0;
|
224 |
+
padding: 1px 3px;
|
225 |
+
margin: 3px;
|
226 |
+
border-radius: 2px;
|
227 |
+
color: #CF0018;
|
228 |
+
cursor: pointer;
|
229 |
+
float: right;
|
230 |
+
}
|
231 |
+
.smk-sidebar-row .created-conditions .condition-parent span.condition-remove .dashicons,
|
232 |
+
.smk-sidebar-row .created-conditions .condition-parent span.condition-remove .dashicons-before:before{
|
233 |
+
font-size: 14px;
|
234 |
+
line-height: 14px;
|
235 |
+
width: 14px;
|
236 |
+
height: 14px;
|
237 |
+
margin: 2px 0;
|
238 |
+
}
|
239 |
+
.smk-sidebar-row .created-conditions .condition-parent span.condition-remove .dashicons-before:before{
|
240 |
+
text-align: center;
|
241 |
+
padding: 3px 0;
|
242 |
+
}
|
243 |
+
.smk-sidebar-row .created-conditions .condition-parent .condition-remove:hover{
|
244 |
+
color: #fff;
|
245 |
+
background: #CF0018;
|
246 |
+
}
|
247 |
+
.smk-sidebar-row .condition-add{
|
248 |
+
margin: 10px 0;
|
249 |
+
}
|
250 |
+
.smk-sidebar-row .smk-sidebar-condition-icon{
|
251 |
+
position: absolute;
|
252 |
+
display: block;
|
253 |
+
height: 100%;
|
254 |
+
left: 0;
|
255 |
+
top: 0;
|
256 |
+
bottom: 0;
|
257 |
+
padding: 3px 0;
|
258 |
+
color: #aaa;
|
259 |
+
cursor: move;
|
260 |
+
}
|
261 |
+
.smk-sidebar-row .smk-sidebar-condition-icon:hover{
|
262 |
+
color: #82B82B;
|
263 |
+
}
|
264 |
+
|
265 |
+
/*
|
266 |
+
-------------------------------------------------------------------------------
|
267 |
+
Clear Floated Elements
|
268 |
+
-------------------------------------------------------------------------------
|
269 |
+
*/
|
270 |
+
/* http://www.yuiblog.com/blog/2010/09/27/clearfix-reloaded-overflowhidden-demystified */
|
271 |
+
.sbg-clearfix:before,.sbg-clearfix:after{content:'.';display:block;overflow:hidden;visibility:hidden;font-size:0;line-height:0;width:0;height:0;}
|
272 |
+
.sbg-clearfix:after{clear:both;}
|
condition-cpt.php
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Smk_Sidebar_Generator_Condition_Cpt extends Smk_Sidebar_Generator_Condition{
|
3 |
+
public $type = 'post_type';
|
4 |
+
|
5 |
+
public function __construct(){
|
6 |
+
$this->name = __('Post types', 'smk-sidebar-generator');
|
7 |
+
}
|
8 |
+
|
9 |
+
// key => value
|
10 |
+
public function prepareMainData(){
|
11 |
+
$pt_args = array(
|
12 |
+
'public' => true,
|
13 |
+
'_builtin' => false
|
14 |
+
);
|
15 |
+
$pt = array(
|
16 |
+
'post' => _x('Posts', 'Post type name', 'smk-sidebar-generator'),
|
17 |
+
'page' => _x('Pages', 'Post type name', 'smk-sidebar-generator'),
|
18 |
+
);
|
19 |
+
$post_types = get_post_types( $pt_args, 'objects' );
|
20 |
+
if( !empty($post_types) ){
|
21 |
+
foreach ($post_types as $post_type) {
|
22 |
+
$pt[ $post_type->name ] = $post_type->label;
|
23 |
+
}
|
24 |
+
}
|
25 |
+
return $pt;
|
26 |
+
}
|
27 |
+
|
28 |
+
// key => value
|
29 |
+
public function prepareSecondaryData( $main_value ){
|
30 |
+
$the_type = $this->selected( $main_value );
|
31 |
+
$all_posts = array();
|
32 |
+
|
33 |
+
if( 'post' == $the_type ){
|
34 |
+
$all_posts['all_single'] = ' - '. __('All single', 'smk-sidebar-generator') .' - ';
|
35 |
+
}
|
36 |
+
elseif( 'page' == $the_type ){
|
37 |
+
$all_posts['all_pages'] = ' - '. __('All pages', 'smk-sidebar-generator') .' - ';
|
38 |
+
}
|
39 |
+
else{
|
40 |
+
$all_posts['all_archives_single'] = ' - '. __('Any(archives or single)', 'smk-sidebar-generator') .' - ';
|
41 |
+
$all_posts['all_single'] = ' - '. __('All single', 'smk-sidebar-generator') .' - ';
|
42 |
+
}
|
43 |
+
|
44 |
+
if( !empty($the_type) ){
|
45 |
+
$posts = get_posts(array(
|
46 |
+
'post_type' => $the_type,
|
47 |
+
'post_status' => 'publish',
|
48 |
+
'posts_per_page' => -1,
|
49 |
+
));
|
50 |
+
|
51 |
+
foreach ( $posts as $post ) {
|
52 |
+
setup_postdata( $post );
|
53 |
+
$id = $post->ID;
|
54 |
+
$all_posts[ $id ] = $post->post_title;
|
55 |
+
}
|
56 |
+
// wp_reset_postdata();
|
57 |
+
}
|
58 |
+
return $all_posts;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Check if can be replaced
|
63 |
+
*
|
64 |
+
* Check if the current condition settings meets the criteria and can replace a sidebar. Rturn true if is allowed to replace the sidebar.
|
65 |
+
*
|
66 |
+
* @param string $first_selection The first selection is the second string from the explode type::this_selection. "this_selection" is the post type
|
67 |
+
* @param array $second_selection = equalto !!! IT is an ARRAY or empty array.
|
68 |
+
* @return bool True if can replace
|
69 |
+
*/
|
70 |
+
public function canReplace( $first_selection, $second_selection ){
|
71 |
+
$can = false;
|
72 |
+
|
73 |
+
// BLOG. "post"
|
74 |
+
if( 'post' == $first_selection ){
|
75 |
+
if( empty($second_selection) ){
|
76 |
+
if( is_home() || is_archive() || is_singular( 'post' ) ){
|
77 |
+
$can = true;
|
78 |
+
}
|
79 |
+
}
|
80 |
+
else{
|
81 |
+
if( in_array('all_single', (array) $second_selection) && is_singular( 'post' ) ){
|
82 |
+
$can = true;
|
83 |
+
}
|
84 |
+
elseif( is_single( $second_selection ) ){
|
85 |
+
$can = true;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
// PAGES. "page"
|
91 |
+
elseif( 'page' == $first_selection ){
|
92 |
+
if( ( empty($second_selection) || in_array('all_pages', (array) $second_selection) ) && is_page() ){
|
93 |
+
$can = true;
|
94 |
+
}
|
95 |
+
elseif( is_page( $second_selection ) ){
|
96 |
+
$can = true;
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
// Custom Post Type
|
101 |
+
else{
|
102 |
+
if( empty($second_selection) ){
|
103 |
+
if( is_singular( $first_selection ) || is_post_type_archive( $first_selection ) ){
|
104 |
+
$can = true;
|
105 |
+
}
|
106 |
+
}
|
107 |
+
elseif( 'all_archives_single' && ( is_singular( $first_selection ) || is_post_type_archive( $first_selection ) ) ){
|
108 |
+
$can = true;
|
109 |
+
}
|
110 |
+
elseif( 'all_archives' && is_post_type_archive( $first_selection ) ){
|
111 |
+
$can = true;
|
112 |
+
}
|
113 |
+
elseif( is_single( $second_selection ) ){
|
114 |
+
$can = true;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
return $can;
|
119 |
+
}
|
120 |
+
|
121 |
+
}
|
condition.php
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
abstract class Smk_Sidebar_Generator_Condition{
|
3 |
+
public $type;
|
4 |
+
public $name;
|
5 |
+
|
6 |
+
public function __construct(){
|
7 |
+
$this->name = get_class( $this );
|
8 |
+
}
|
9 |
+
|
10 |
+
// Return key => value options
|
11 |
+
public function prepareMainData(){
|
12 |
+
return array();
|
13 |
+
}
|
14 |
+
|
15 |
+
// Return key => value options
|
16 |
+
public function prepareSecondaryData( $main_value ){
|
17 |
+
$array = array( 'all' => __('All', 'smk-sidebar-generator') );
|
18 |
+
return $array;
|
19 |
+
}
|
20 |
+
|
21 |
+
public function getMainData(){
|
22 |
+
$dataif = $this->prepareMainData();
|
23 |
+
$newdata = array();
|
24 |
+
if( !empty($dataif) && is_array($dataif) ){
|
25 |
+
foreach ($dataif as $key => $value) {
|
26 |
+
$newdata[ $this->type . '::' . $key ] = $value;
|
27 |
+
}
|
28 |
+
return array(
|
29 |
+
'label' => $this->name,
|
30 |
+
'options' => $newdata,
|
31 |
+
);
|
32 |
+
}
|
33 |
+
else{
|
34 |
+
return array();
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
public function selected( $main_value ){
|
39 |
+
$the_type = explode('::', $main_value);
|
40 |
+
if( !empty( $the_type[0] ) && !empty( $the_type[1] ) ){
|
41 |
+
return $the_type[1];
|
42 |
+
}
|
43 |
+
else{
|
44 |
+
return false;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
public function getSecondaryData( $main_value ){
|
49 |
+
return $this->prepareSecondaryData( $main_value );
|
50 |
+
}
|
51 |
+
|
52 |
+
// $first_selection = type::this_selection
|
53 |
+
// $second_selection = equalto
|
54 |
+
// Should return true or false
|
55 |
+
public function canReplace( $first_selection, $second_selection ){
|
56 |
+
$can = false;
|
57 |
+
return $can;
|
58 |
+
}
|
59 |
+
}
|
html.php
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Title
|
4 |
+
*
|
5 |
+
* Description
|
6 |
+
*
|
7 |
+
* -------------------------------------------------------------------------------------
|
8 |
+
* @Author: Smartik
|
9 |
+
* @Author URI: http://smartik.ws/
|
10 |
+
* @Copyright: (c) 2014 Smartik. All rights reserved
|
11 |
+
* -------------------------------------------------------------------------------------
|
12 |
+
*
|
13 |
+
*/
|
14 |
+
if( ! class_exists('Smk_Sidebar_Generator_Html') ){
|
15 |
+
class Smk_Sidebar_Generator_Html{
|
16 |
+
|
17 |
+
public function input( $id = '', $name = '', $value = '', $atts = array() ){
|
18 |
+
$main = array(
|
19 |
+
'id' => $id,
|
20 |
+
'name' => $name,
|
21 |
+
'value' => esc_html( $value ),
|
22 |
+
);
|
23 |
+
$all_args = wp_parse_args($atts, $main);
|
24 |
+
|
25 |
+
return '<input'. $this->mergeAttributes($all_args) .' />';
|
26 |
+
}
|
27 |
+
|
28 |
+
public function select( $id = '', $name = '', $value = '', $atts = array() ){
|
29 |
+
$main = array(
|
30 |
+
'id' => $id,
|
31 |
+
'name' => $name,
|
32 |
+
);
|
33 |
+
$all_args = wp_parse_args($atts, $main);
|
34 |
+
|
35 |
+
$field = '<select'. $this->mergeAttributes($all_args, array('value') ) .'>';
|
36 |
+
if( !empty( $atts['options'] ) && is_array( $atts['options'] ) ){
|
37 |
+
foreach ( $atts['options'] as $key => $option ) {
|
38 |
+
if( !is_array($option) ){
|
39 |
+
$selected = ( in_array($key, (array) $value) ) ? ' selected="selected"' : '';
|
40 |
+
$field .= '<option value="'. $key .'"'. $selected .'>'. $option .'</option>';
|
41 |
+
}
|
42 |
+
else{
|
43 |
+
$optg_label = !empty($option['label']) ? $option['label'] : '';
|
44 |
+
if( !empty( $option['options']) ){
|
45 |
+
$field .= '<optgroup label="'. $optg_label .'">';
|
46 |
+
foreach ( (array) $option['options'] as $gokey => $govalue) {
|
47 |
+
$selected = ( in_array($gokey, (array) $value) ) ? ' selected="selected"' : '';
|
48 |
+
$field .= '<option value="'. $gokey .'"'. $selected .'>'. $govalue .'</option>';
|
49 |
+
}
|
50 |
+
$field .= '</optgroup>';
|
51 |
+
}
|
52 |
+
}
|
53 |
+
}
|
54 |
+
}
|
55 |
+
$field .= '</select>';
|
56 |
+
|
57 |
+
return $field;
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
protected function mergeAttributes($atts = array(), $exclude = array()){
|
63 |
+
|
64 |
+
// Dissalow certain attributes.
|
65 |
+
if( !empty($exclude) && is_array($exclude) ){
|
66 |
+
foreach ( (array) $exclude as $ex) {
|
67 |
+
unset( $atts[$ex] );
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
//If have attributes, proceed.
|
72 |
+
if( !empty($atts) ){
|
73 |
+
|
74 |
+
$return = array();
|
75 |
+
foreach ($atts as $att => $val) {
|
76 |
+
$att = trim( $att );
|
77 |
+
switch ($att) {
|
78 |
+
case 'class':
|
79 |
+
$return[] = $this->makeAttribute($att, $this->getHtmlClass($val) );
|
80 |
+
break;
|
81 |
+
|
82 |
+
case 'options':
|
83 |
+
continue;
|
84 |
+
break;
|
85 |
+
|
86 |
+
default:
|
87 |
+
if( !empty($att) ){
|
88 |
+
$return[] = $this->makeAttribute($att, $val);
|
89 |
+
}
|
90 |
+
break;
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
$final = implode(' ', $return);
|
95 |
+
return ( !empty($final) ) ? ' '. $final : '';
|
96 |
+
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
protected function getHtmlClass($att_val){
|
101 |
+
if( is_array($att_val) ){
|
102 |
+
foreach ($att_val as $class) {
|
103 |
+
$classes[] = sanitize_html_class($class);
|
104 |
+
}
|
105 |
+
}
|
106 |
+
elseif( is_string($att_val) ){
|
107 |
+
$classes[] = sanitize_html_class($att_val);
|
108 |
+
}
|
109 |
+
else{
|
110 |
+
$classes[] = array();
|
111 |
+
}
|
112 |
+
return implode( ' ', $classes );
|
113 |
+
}
|
114 |
+
|
115 |
+
protected function makeAttribute($attribute, $value = ''){
|
116 |
+
if( !empty($value) )
|
117 |
+
return ( ! is_bool($value) && !is_array($value) ) ? $attribute .'="'. esc_attr( $value ) .'"' : $attribute;
|
118 |
+
}
|
119 |
+
|
120 |
+
}
|
121 |
+
}
|
lang/smk-sidebar-generator-ro_RO.mo
ADDED
Binary file
|
lang/smk-sidebar-generator-ro_RO.po
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: SMK Sidebar Generator\n"
|
4 |
+
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: Tue Dec 01 2015 13:14:59 GMT+0200 (Eastern Europe "
|
6 |
+
"Standard Time)\n"
|
7 |
+
"PO-Revision-Date: Tue Dec 01 2015 13:48:53 GMT+0200 (Eastern Europe Standard "
|
8 |
+
"Time)\n"
|
9 |
+
"Last-Translator: Andrei <smartik89@gmail.com>\n"
|
10 |
+
"Language-Team: \n"
|
11 |
+
"Language: Romanian\n"
|
12 |
+
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 :(((n%100>19)||(( n%100==0)&&(n!"
|
13 |
+
"=0)))? 2 : 1))\n"
|
14 |
+
"MIME-Version: 1.0\n"
|
15 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
16 |
+
"Content-Transfer-Encoding: 8bit\n"
|
17 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
18 |
+
"X-Poedit-Basepath: .\n"
|
19 |
+
"X-Poedit-SearchPath-0: .\n"
|
20 |
+
"X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
|
21 |
+
"__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;"
|
22 |
+
"_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;"
|
23 |
+
"esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;"
|
24 |
+
"esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
|
25 |
+
"X-Generator: Loco - https://localise.biz/\n"
|
26 |
+
"X-Loco-Target-Locale: ro_RO"
|
27 |
+
|
28 |
+
#: condition-cpt.php:6
|
29 |
+
msgid "Post types"
|
30 |
+
msgstr "Tip de posturi"
|
31 |
+
|
32 |
+
#: condition-cpt.php:16
|
33 |
+
msgctxt "Post type name"
|
34 |
+
msgid "Posts"
|
35 |
+
msgstr "Posturi"
|
36 |
+
|
37 |
+
#: condition-cpt.php:17
|
38 |
+
msgctxt "Post type name"
|
39 |
+
msgid "Pages"
|
40 |
+
msgstr "Pagini"
|
41 |
+
|
42 |
+
#: condition-cpt.php:34 /condition-cpt.php:41
|
43 |
+
msgid "All single"
|
44 |
+
msgstr "Toate individuale"
|
45 |
+
|
46 |
+
#: condition-cpt.php:37
|
47 |
+
msgid "All pages"
|
48 |
+
msgstr "Toate paginile"
|
49 |
+
|
50 |
+
#: condition-cpt.php:40
|
51 |
+
msgid "Any(archives or single)"
|
52 |
+
msgstr "Orice(arhive sau individuale)"
|
53 |
+
|
54 |
+
#: condition.php:17
|
55 |
+
msgid "All"
|
56 |
+
msgstr "Toate"
|
57 |
+
|
58 |
+
#: render.php:36
|
59 |
+
msgid "Sidebar Generator"
|
60 |
+
msgstr "Sidebar Generator"
|
61 |
+
|
62 |
+
#: render.php:109
|
63 |
+
msgid "Add new"
|
64 |
+
msgstr "Adaugă"
|
65 |
+
|
66 |
+
#: render.php:113
|
67 |
+
msgid "Sidebars"
|
68 |
+
msgstr "Sidebaruri"
|
69 |
+
|
70 |
+
#: render.php:114
|
71 |
+
msgid "All available sidebars."
|
72 |
+
msgstr "Toate sidebarurile disponibile"
|
73 |
+
|
74 |
+
#: render.php:202
|
75 |
+
msgid "Enable conditions:"
|
76 |
+
msgstr "Permite condiţii:"
|
77 |
+
|
78 |
+
#: render.php:219
|
79 |
+
msgid "Add condition"
|
80 |
+
msgstr "Adaugă condiţie"
|
81 |
+
|
82 |
+
#: render.php:249
|
83 |
+
msgid "Delete"
|
84 |
+
msgstr "Şterge"
|
85 |
+
|
86 |
+
#: render.php:250
|
87 |
+
msgid "Restore"
|
88 |
+
msgstr "Restabileşte"
|
89 |
+
|
90 |
+
#: render.php:288
|
91 |
+
msgid "Remove condition"
|
92 |
+
msgstr "Şterge condiţia"
|
93 |
+
|
94 |
+
#: render.php:306
|
95 |
+
msgid "Name:"
|
96 |
+
msgstr "Nume:"
|
97 |
+
|
98 |
+
#: render.php:332
|
99 |
+
msgid "ID:"
|
100 |
+
msgstr "ID:"
|
101 |
+
|
102 |
+
#: render.php:358
|
103 |
+
msgid "Description:"
|
104 |
+
msgstr "Descriere:"
|
105 |
+
|
106 |
+
#: render.php:394
|
107 |
+
msgid "Sidebars to replace:"
|
108 |
+
msgstr "Sidebaruri de înlocuit:"
|
109 |
+
|
110 |
+
#: render.php:408
|
111 |
+
msgid "Shortcode:"
|
112 |
+
msgstr "Shortcode:"
|
113 |
+
|
114 |
+
#: render.php:426
|
115 |
+
msgid "None"
|
116 |
+
msgstr "Nimic"
|
117 |
+
|
118 |
+
#: render.php:443
|
119 |
+
msgid "Replace if"
|
120 |
+
msgstr "Înlocuieşte dacă"
|
121 |
+
|
122 |
+
#: render.php:470
|
123 |
+
msgid "and is equal to"
|
124 |
+
msgstr "şi este egal cu"
|
125 |
+
|
126 |
+
#: render.php:535
|
127 |
+
msgid "Removed"
|
128 |
+
msgstr "Şters"
|
129 |
+
|
130 |
+
#: render.php:536
|
131 |
+
msgid "These sidebars will be removed on the next page refresh."
|
132 |
+
msgstr "Aceste sidebaruri vor fi şterse la următoarea reîncărcare a acestei pagini."
|
133 |
+
|
134 |
+
#: render.php:556
|
135 |
+
#, php-format
|
136 |
+
msgid "New sidebar %s"
|
137 |
+
msgstr "Sidebar nou %s"
|
lang/smk-sidebar-generator.pot
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Loco Gettext template
|
2 |
+
#, fuzzy
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: SMK Sidebar Generator\n"
|
6 |
+
"Report-Msgid-Bugs-To: \n"
|
7 |
+
"POT-Creation-Date: Tue Dec 01 2015 13:14:59 GMT+0200 (Eastern Europe "
|
8 |
+
"Standard Time)\n"
|
9 |
+
"POT-Revision-Date: Tue Dec 01 2015 13:15:20 GMT+0200 (Eastern Europe "
|
10 |
+
"Standard Time)\n"
|
11 |
+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
12 |
+
"Last-Translator: \n"
|
13 |
+
"Language-Team: \n"
|
14 |
+
"Language: \n"
|
15 |
+
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION\n"
|
16 |
+
"MIME-Version: 1.0\n"
|
17 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18 |
+
"Content-Transfer-Encoding: 8bit\n"
|
19 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
20 |
+
"X-Poedit-Basepath: .\n"
|
21 |
+
"X-Poedit-SearchPath-0: .\n"
|
22 |
+
"X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
|
23 |
+
"__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;"
|
24 |
+
"_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;"
|
25 |
+
"esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;"
|
26 |
+
"esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
|
27 |
+
"X-Generator: Loco - https://localise.biz/"
|
28 |
+
|
29 |
+
#: /condition-cpt.php:6
|
30 |
+
msgid "Post types"
|
31 |
+
msgstr ""
|
32 |
+
|
33 |
+
#: /condition-cpt.php:16
|
34 |
+
msgctxt "Post type name"
|
35 |
+
msgid "Posts"
|
36 |
+
msgstr ""
|
37 |
+
|
38 |
+
#: /condition-cpt.php:17
|
39 |
+
msgctxt "Post type name"
|
40 |
+
msgid "Pages"
|
41 |
+
msgstr ""
|
42 |
+
|
43 |
+
#: /condition-cpt.php:34 /condition-cpt.php:41
|
44 |
+
msgid "All single"
|
45 |
+
msgstr ""
|
46 |
+
|
47 |
+
#: /condition-cpt.php:37
|
48 |
+
msgid "All pages"
|
49 |
+
msgstr ""
|
50 |
+
|
51 |
+
#: /condition-cpt.php:40
|
52 |
+
msgid "Any(archives or single)"
|
53 |
+
msgstr ""
|
54 |
+
|
55 |
+
#: /condition.php:17
|
56 |
+
msgid "All"
|
57 |
+
msgstr ""
|
58 |
+
|
59 |
+
#: /render.php:36
|
60 |
+
msgid "Sidebar Generator"
|
61 |
+
msgstr ""
|
62 |
+
|
63 |
+
#: /render.php:109
|
64 |
+
msgid "Add new"
|
65 |
+
msgstr ""
|
66 |
+
|
67 |
+
#: /render.php:113
|
68 |
+
msgid "Sidebars"
|
69 |
+
msgstr ""
|
70 |
+
|
71 |
+
#: /render.php:114
|
72 |
+
msgid "All available sidebars."
|
73 |
+
msgstr ""
|
74 |
+
|
75 |
+
#: /render.php:202
|
76 |
+
msgid "Enable conditions:"
|
77 |
+
msgstr ""
|
78 |
+
|
79 |
+
#: /render.php:219
|
80 |
+
msgid "Add condition"
|
81 |
+
msgstr ""
|
82 |
+
|
83 |
+
#: /render.php:249
|
84 |
+
msgid "Delete"
|
85 |
+
msgstr ""
|
86 |
+
|
87 |
+
#: /render.php:250
|
88 |
+
msgid "Restore"
|
89 |
+
msgstr ""
|
90 |
+
|
91 |
+
#: /render.php:288
|
92 |
+
msgid "Remove condition"
|
93 |
+
msgstr ""
|
94 |
+
|
95 |
+
#: /render.php:306
|
96 |
+
msgid "Name:"
|
97 |
+
msgstr ""
|
98 |
+
|
99 |
+
#: /render.php:332
|
100 |
+
msgid "ID:"
|
101 |
+
msgstr ""
|
102 |
+
|
103 |
+
#: /render.php:358
|
104 |
+
msgid "Description:"
|
105 |
+
msgstr ""
|
106 |
+
|
107 |
+
#: /render.php:394
|
108 |
+
msgid "Sidebars to replace:"
|
109 |
+
msgstr ""
|
110 |
+
|
111 |
+
#: /render.php:408
|
112 |
+
msgid "Shortcode:"
|
113 |
+
msgstr ""
|
114 |
+
|
115 |
+
#: /render.php:426
|
116 |
+
msgid "None"
|
117 |
+
msgstr ""
|
118 |
+
|
119 |
+
#: /render.php:443
|
120 |
+
msgid "Replace if"
|
121 |
+
msgstr ""
|
122 |
+
|
123 |
+
#: /render.php:470
|
124 |
+
msgid "and is equal to"
|
125 |
+
msgstr ""
|
126 |
+
|
127 |
+
#: /render.php:535
|
128 |
+
msgid "Removed"
|
129 |
+
msgstr ""
|
130 |
+
|
131 |
+
#: /render.php:536
|
132 |
+
msgid "These sidebars will be removed on the next page refresh."
|
133 |
+
msgstr ""
|
134 |
+
|
135 |
+
#: /render.php:556
|
136 |
+
#, php-format
|
137 |
+
msgid "New sidebar %s"
|
138 |
+
msgstr ""
|
readme.md
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This plugin generates as many sidebars as you need. Then allows you to place them on any page you wish.
|
2 |
+
|
3 |
+
#### Version 3.0 is here!
|
4 |
+
The new version 3.x has many advantages compared with the old 2.x. First and the most important is that it remove the need to add some special code to the theme in order to display the generated sidebar. That's because it now can override the default sidebar and apply special conditions for any page on your site.
|
5 |
+
|
6 |
+
|
7 |
+
<!--**Demo video:** http://youtu.be/fluNdMnSCKA-->
|
8 |
+
|
9 |
+
<!--iframe width="560" height="315" src="//www.youtube.com/embed/fluNdMnSCKA" frameborder="0" allowfullscreen></iframe-->
|
10 |
+
|
11 |
+
* Author : Smartik - http://smartik.ws/
|
12 |
+
* License : GPLv2
|
13 |
+
* Development branch: https://github.com/Smartik89/Wordpress-Sidebar-Generator
|
14 |
+
* Issue tracker: https://github.com/Smartik89/Wordpress-Sidebar-Generator/issues
|
15 |
+
|
16 |
+
####Features:
|
17 |
+
* Unlimited number of sidebars.
|
18 |
+
* Replace default theme sidebars using the conditions or globaly just by selecting the sidebar that you want to replace.
|
19 |
+
* Show the generated sidebars on any page you wish without touching a single line of code in your theme.
|
20 |
+
* Drag to sort sidebar position.
|
21 |
+
|
22 |
+
####How to install this plugin?
|
23 |
+
Like any other Wordpress plugin. <br />
|
24 |
+
Drop `smk-sidebar-generator` to `wp-content/plugins/`.<br />
|
25 |
+
More info here: http://codex.wordpress.org/Managing_Plugins#Installing_Plugins
|
26 |
+
|
27 |
+
####Backward compatibility.
|
28 |
+
|
29 |
+
Because you probably still need them, these functions are still here to not break your site.
|
30 |
+
**Note:** The following code is for vesion 2.x In the latest version of this plugin they are not required. Do not use them anymore!!!
|
31 |
+
|
32 |
+
**Display a sidebar using `smk_sidebar` function:**
|
33 |
+
<pre>
|
34 |
+
if(function_exists('smk_sidebar'){
|
35 |
+
smk_sidebar('sidebarID');
|
36 |
+
}
|
37 |
+
</pre>
|
38 |
+
**Display a sidebar using wp native function:**
|
39 |
+
<pre>
|
40 |
+
if(function_exists('dynamic_sidebar') && dynamic_sidebar('sidebarID')) :
|
41 |
+
endif;
|
42 |
+
</pre>
|
43 |
+
|
44 |
+
**Display a sidebar using built-in shortcode:**
|
45 |
+
<pre>
|
46 |
+
[smk_sidebar id="sidebarID"]
|
47 |
+
</pre>
|
48 |
+
|
49 |
+
== Installation ==
|
50 |
+
|
51 |
+
1. Upload the `smk-sidebar-generator` folder to the `/wp-content/plugins/` directory
|
52 |
+
2. Activate the SMK Sidebar Generator plugin through the 'Plugins' menu in WordPress
|
53 |
+
3. Configure the plugin by going to the SMK Sidebars menu that appears in your admin menu
|
54 |
+
|
55 |
+
== Changelog ==
|
56 |
+
|
57 |
+
= 3.1 =
|
58 |
+
* Added localization support(if you want to translate it in your language, create a pull requests on Github).
|
59 |
+
* Added shortcode with ID to each sidebar.
|
60 |
+
|
61 |
+
= 3.0 =
|
62 |
+
* **Complete rewrite from scratch.** The plugin now allows to create an unlimited number of sidebars without the need to touch a single line of code in your theme.
|
63 |
+
* Now you can use conditions to apply the sidebar on any page, post ar CPT you wish. _Soon will be added support for taxonomies, 404 page and other(please suggest)_.
|
64 |
+
* The widgets now use the theme style and tags. That means the newly generated sidebars will look good on any theme, no need for additional styling.
|
65 |
+
* Modular code. You can create and register your own conditions. That's mainly not required but can be handy for some developers.
|
66 |
+
|
67 |
+
= 2.3.2 =
|
68 |
+
* Quick fix UI. When a new sidebar is created, it display an incorect info and it was fixed only after page refresh.
|
69 |
+
* Removed unused files, since version 3.0 is on development `smk_sidebar_metabox.php` was removed, as it was never used and is not required for the next versions.
|
70 |
+
|
71 |
+
= 2.3.1 =
|
72 |
+
* Quick fix for shortcode smk_sidebar ID. Shortcode did not work because the ID was not set correctly.
|
73 |
+
* Added new tab "How to use?" and links to docs.
|
74 |
+
|
75 |
+
= 2.3 =
|
76 |
+
* **Added import/export functions.**
|
77 |
+
* Changes to `smk_sidebar` shortcode. Previously to get a sidebar required only an integer number, now you can get any sidebar using the shortcode just giving the id, even if the sidebar is not generated using Sidebar Generator plugin.
|
78 |
+
* Added plugin version to enqueued scripts and style.
|
79 |
+
|
80 |
+
= 2.2 =
|
81 |
+
* Confirm sidebar remove.
|
82 |
+
* Bug fix: Sidebars could not be added when all previous sidebars were removed.
|
83 |
+
* Bug fix: Fixed ajax name validation.
|
84 |
+
|
85 |
+
= 2.1.1 =
|
86 |
+
* enqueue styles and scripts only on plugin page, not on all WP dashboard pages.
|
87 |
+
* `admin_enqueue_scripts` make use of `SMK_SBG_URI` constant.
|
88 |
+
|
89 |
+
= 2.1 =
|
90 |
+
* `smk_get_all_sidebars()` function is included in plugin. Anyways, you must include it in your theme `functions.php`, because if you'll deactivate the plugin it will return a fatal error.
|
91 |
+
|
92 |
+
= 2.0 =
|
93 |
+
* Initial release
|
readme.txt
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== SMK Sidebar Generator ===
|
2 |
+
Contributors: _smartik_
|
3 |
+
Tags: sidebar, widget, generator, custom, unlimited
|
4 |
+
Requires at least: 4.0
|
5 |
+
Tested up to: 5.3
|
6 |
+
Stable tag: 3.2.0
|
7 |
+
License: GPLv2 or later
|
8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
|
10 |
+
This plugin generates as many sidebars as you need. Then allows you to place them on any page you wish.
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
This plugin generates as many sidebars as you need. Then allows you to place them on any page you wish.
|
14 |
+
|
15 |
+
#### Version 3.0 is here!
|
16 |
+
The new version 3.x has many advantages compared with the old 2.x. First and the most important is that it remove the need to add some special code to the theme in order to display the generated sidebar. That's because it now can override the default sidebar and apply special conditions for any page on your site.
|
17 |
+
|
18 |
+
|
19 |
+
<!--**Demo video:** http://youtu.be/fluNdMnSCKA-->
|
20 |
+
|
21 |
+
<!--iframe width="560" height="315" src="//www.youtube.com/embed/fluNdMnSCKA" frameborder="0" allowfullscreen></iframe-->
|
22 |
+
|
23 |
+
####Features:
|
24 |
+
* Unlimited number of sidebars.
|
25 |
+
* Replace default theme sidebars using the conditions or globaly just by selecting the sidebar that you want to replace.
|
26 |
+
* Show the generated sidebars on any page you wish without touching a single line of code in your theme.
|
27 |
+
* Drag to sort sidebar position.
|
28 |
+
|
29 |
+
####How to install this plugin?
|
30 |
+
Like any other Wordpress plugin. <br />
|
31 |
+
Drop `smk-sidebar-generator` to `wp-content/plugins/`.<br />
|
32 |
+
More info here: http://codex.wordpress.org/Managing_Plugins#Installing_Plugins
|
33 |
+
|
34 |
+
####Backward compatibility.
|
35 |
+
|
36 |
+
Because you probably still need them, these functions are still here to not break your site.
|
37 |
+
**Note:** The following code is for vesion 2.x In the latest version of this plugin they are not required. Do not use them anymore!!!
|
38 |
+
|
39 |
+
**Display a sidebar using `smk_sidebar` function:**
|
40 |
+
<pre>
|
41 |
+
if(function_exists('smk_sidebar'){
|
42 |
+
smk_sidebar('sidebarID');
|
43 |
+
}
|
44 |
+
</pre>
|
45 |
+
**Display a sidebar using wp native function:**
|
46 |
+
<pre>
|
47 |
+
if(function_exists('dynamic_sidebar') && dynamic_sidebar('sidebarID')) :
|
48 |
+
endif;
|
49 |
+
</pre>
|
50 |
+
|
51 |
+
**Display a sidebar using built-in shortcode:**
|
52 |
+
<pre>
|
53 |
+
[smk_sidebar id="sidebarID"]
|
54 |
+
</pre>
|
55 |
+
|
56 |
+
== Installation ==
|
57 |
+
|
58 |
+
1. Upload the `smk-sidebar-generator` folder to the `/wp-content/plugins/` directory
|
59 |
+
2. Activate the SMK Sidebar Generator plugin through the 'Plugins' menu in WordPress
|
60 |
+
3. Configure the plugin by going to the SMK Sidebars menu that appears in your admin menu
|
61 |
+
|
62 |
+
== Screenshots ==
|
63 |
+
1. Admin panel
|
64 |
+
|
65 |
+
|
66 |
+
== Changelog ==
|
67 |
+
|
68 |
+
= 3.1 =
|
69 |
+
* Added localization support(if you want to translate it in your language, create a pull requests on Github).
|
70 |
+
* Added shortcode with ID to each sidebar.
|
71 |
+
|
72 |
+
= 3.0 =
|
73 |
+
* **Complete rewrite from scratch.** The plugin now allows to create an unlimited number of sidebars without the need to touch a single line of code in your theme.
|
74 |
+
* Now you can use conditions to apply the sidebar on any page, post ar CPT you wish. _Soon will be added support for taxonomies, 404 page and other(please suggest)_.
|
75 |
+
* The widgets now use the theme style and tags. That means the newly generated sidebars will look good on any theme, no need for additional styling.
|
76 |
+
* Modular code. You can create and register your own conditions. That's mainly not required but can be handy for some developers.
|
77 |
+
|
78 |
+
= 2.3.2 =
|
79 |
+
* Quick fix UI. When a new sidebar is created, it display an incorect info and it was fixed only after page refresh.
|
80 |
+
* Removed unused files, since version 3.0 is on development `smk_sidebar_metabox.php` was removed, as it was never used and is not required for the next versions.
|
81 |
+
|
82 |
+
= 2.3.1 =
|
83 |
+
* Quick fix for shortcode smk_sidebar ID. Shortcode did not work because the ID was not set correctly.
|
84 |
+
* Added new tab "How to use?" and links to docs.
|
85 |
+
|
86 |
+
= 2.3 =
|
87 |
+
* **Added import/export functions.**
|
88 |
+
* Changes to `smk_sidebar` shortcode. Previously to get a sidebar required only an integer number, now you can get any sidebar using the shortcode just giving the id, even if the sidebar is not generated using Sidebar Generator plugin.
|
89 |
+
* Added plugin version to enqueued scripts and style.
|
90 |
+
|
91 |
+
= 2.2 =
|
92 |
+
* Confirm sidebar remove.
|
93 |
+
* Bug fix: Sidebars could not be added when all previous sidebars were removed.
|
94 |
+
* Bug fix: Fixed ajax name validation.
|
95 |
+
|
96 |
+
= 2.1.1 =
|
97 |
+
* enqueue styles and scripts only on plugin page, not on all WP dashboard pages.
|
98 |
+
* `admin_enqueue_scripts` make use of `SMK_SBG_URI` constant.
|
99 |
+
|
100 |
+
= 2.1 =
|
101 |
+
* `smk_get_all_sidebars()` function is included in plugin. Anyways, you must include it in your theme `functions.php`, because if you'll deactivate the plugin it will return a fatal error.
|
102 |
+
|
103 |
+
= 2.0 =
|
104 |
+
* Initial release
|
render.php
ADDED
@@ -0,0 +1,570 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Smk Sidebar Generator Render
|
4 |
+
*
|
5 |
+
* -------------------------------------------------------------------------------------
|
6 |
+
* @Author: Smartik
|
7 |
+
* @Author URI: http://smartik.ws/
|
8 |
+
* @Copyright: (c) 2014 Smartik. All rights reserved
|
9 |
+
* -------------------------------------------------------------------------------------
|
10 |
+
*
|
11 |
+
*/
|
12 |
+
|
13 |
+
// Do not allow direct access to this file.
|
14 |
+
if( ! function_exists('add_action') )
|
15 |
+
die();
|
16 |
+
|
17 |
+
// Start object
|
18 |
+
if( class_exists('Smk_Sidebar_Generator_Abstract')) {
|
19 |
+
class Smk_Sidebar_Generator extends Smk_Sidebar_Generator_Abstract {
|
20 |
+
|
21 |
+
public function setup(){
|
22 |
+
add_action( 'wp_ajax_smk-sidebar-generator_load_equalto', array( $this, 'equaltoAjax' ) );
|
23 |
+
}
|
24 |
+
|
25 |
+
//------------------------------------//--------------------------------------//
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Plugin Settings
|
29 |
+
*
|
30 |
+
* Inner plugin settings.
|
31 |
+
*
|
32 |
+
* @return array
|
33 |
+
*/
|
34 |
+
protected function pluginSettings( $key = '' ){
|
35 |
+
$settings = array(
|
36 |
+
'name' => __('Sidebar Generator', 'smk-sidebar-generator'),
|
37 |
+
'slug' => strtolower( __CLASS__ ),
|
38 |
+
'version' => $this->version,
|
39 |
+
'capability' => 'manage_options',
|
40 |
+
'menu_parent' => 'themes.php',
|
41 |
+
'option_name' => 'smk_sidebar_generator',
|
42 |
+
'settings_register_name' => 'smk_sidebar_generator_register',
|
43 |
+
);
|
44 |
+
|
45 |
+
if( !empty($key) && array_key_exists($key, $settings) ){
|
46 |
+
return $settings[ $key ];
|
47 |
+
}
|
48 |
+
else{
|
49 |
+
return $settings;
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
//------------------------------------//--------------------------------------//
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Page
|
57 |
+
*
|
58 |
+
* Create the admin page
|
59 |
+
*
|
60 |
+
* @return string
|
61 |
+
*/
|
62 |
+
public function page(){
|
63 |
+
echo '<div class="smk-sidebars-list-template" style="display: none;">';
|
64 |
+
$this->sidebarListTemplate();
|
65 |
+
echo '</div>';
|
66 |
+
echo '<div class="smk-sidebars-condition-template" style="display: none;">';
|
67 |
+
echo $this->aSingleCondition('__cond_name__', '', 0, 'all');
|
68 |
+
echo '</div>';
|
69 |
+
$this->pageOpen();
|
70 |
+
settings_fields( $this->pluginSettings('settings_register_name') );
|
71 |
+
|
72 |
+
$counter = get_option( $this->pluginSettings('option_name'), array() );
|
73 |
+
$counterval = ! empty( $counter['counter'] ) ? absint( $counter['counter'] ) : intval( '0' );
|
74 |
+
echo $this->html->input(
|
75 |
+
'smk-sidebar-generator-counter', // ID
|
76 |
+
$this->pluginSettings( 'option_name' ) . '[counter]',
|
77 |
+
absint( $counterval ),
|
78 |
+
array(
|
79 |
+
'type' => 'hidden',
|
80 |
+
)
|
81 |
+
);
|
82 |
+
|
83 |
+
$this->allSidebarsList();
|
84 |
+
|
85 |
+
submit_button();
|
86 |
+
$this->pageClose();
|
87 |
+
|
88 |
+
|
89 |
+
// Debug start
|
90 |
+
// $this->debug( $this->allStaticSidebars(), 'All static sidebars' );
|
91 |
+
// $this->debug( $this->allGeneratedSidebars(), 'All generated sidebars' );
|
92 |
+
// global $sidebars_widgets;
|
93 |
+
// $this->debug( $sidebars_widgets, 'All sidebars and their widgets' );
|
94 |
+
// $this->debug( smk_sidebar_conditions_filter(), 'All conditions' );
|
95 |
+
}
|
96 |
+
|
97 |
+
//------------------------------------//--------------------------------------//
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Page Open
|
101 |
+
*
|
102 |
+
* Outputs the top part of HTML for this page.
|
103 |
+
*
|
104 |
+
* @return string
|
105 |
+
*/
|
106 |
+
public function pageOpen($echo = true){
|
107 |
+
$html = '<div class="wrap sbg-clearfix">';
|
108 |
+
$html .= '<h2>'. $this->pluginSettings( 'name' ) .'
|
109 |
+
<span class="add-new-h2 add-new-sidebar" data-sidebars-prefix="'. $this->prefix() .'">'. __('Add new', 'smk-sidebar-generator') .'</span>
|
110 |
+
</h2>';
|
111 |
+
$html .= '<div class="smk-sidebars-grid">';
|
112 |
+
$html .= '<h3>
|
113 |
+
'. __('Sidebars', 'smk-sidebar-generator') .'
|
114 |
+
<span class="tip dashicons-before dashicons-editor-help" title="'. __('All available sidebars.', 'smk-sidebar-generator') .'"></span>
|
115 |
+
</h3>';
|
116 |
+
$html .= '<form method="post" action="options.php" class="smk-sidebar-generator_main_form">';
|
117 |
+
if( $echo ) { echo $html; } else { return $html; }
|
118 |
+
}
|
119 |
+
|
120 |
+
//------------------------------------//--------------------------------------//
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Page Close
|
124 |
+
*
|
125 |
+
* Outputs the bottom part of HTML for this page.
|
126 |
+
*
|
127 |
+
* @return string
|
128 |
+
*/
|
129 |
+
public function pageClose($echo = true){
|
130 |
+
$html = '</form>';
|
131 |
+
$html .= '</div>';
|
132 |
+
$html .= $this->allRemovedSidebarsList( false );
|
133 |
+
$html .= '</div>';
|
134 |
+
if( $echo ) { echo $html; } else { return $html; }
|
135 |
+
}
|
136 |
+
|
137 |
+
//------------------------------------//--------------------------------------//
|
138 |
+
|
139 |
+
/**
|
140 |
+
* All sidebars list
|
141 |
+
*
|
142 |
+
* All sidebars list
|
143 |
+
*
|
144 |
+
* @return string The HTML.
|
145 |
+
*/
|
146 |
+
public function allSidebarsList($echo = true){
|
147 |
+
$all = $this->allGeneratedSidebars();
|
148 |
+
$list = '<div id="smk-sidebars" class="accordion-container smk-sidebars-list">';
|
149 |
+
$list .= '<ul class="connected-sidebars-lists">';
|
150 |
+
if( !empty( $all ) ){
|
151 |
+
foreach ( (array) $all as $id => $s ) {
|
152 |
+
$list .= $this->aSingleListItem( $s );
|
153 |
+
}
|
154 |
+
}
|
155 |
+
$list .= '</ul>';
|
156 |
+
$list .= '</div>';
|
157 |
+
if( $echo ) { echo $list; } else { return $list; }
|
158 |
+
}
|
159 |
+
|
160 |
+
//------------------------------------//--------------------------------------//
|
161 |
+
|
162 |
+
/**
|
163 |
+
* A single sidebar list
|
164 |
+
*
|
165 |
+
* Output the HTML for a single sidebar list.
|
166 |
+
*
|
167 |
+
* @param array $sidebar_data Sidebar data
|
168 |
+
* @param array $settings Sidebar custom settings
|
169 |
+
* @return string The HTML.
|
170 |
+
*/
|
171 |
+
public function aSingleListItem($sidebar_data, $settings = false){
|
172 |
+
$settings = ( $settings && is_array( $settings ) ) ? $settings : $this->pluginSettings();
|
173 |
+
$name = $settings['option_name'] .'[sidebars]['. $sidebar_data['id'] .']';
|
174 |
+
|
175 |
+
// All pages
|
176 |
+
$all_pages = get_pages();
|
177 |
+
$pages_options = '';
|
178 |
+
foreach ( $all_pages as $page ) {
|
179 |
+
$pages_options .= '<option value="' . $page->ID . '">';
|
180 |
+
$pages_options .= $page->post_title;
|
181 |
+
$pages_options .= '</option>';
|
182 |
+
}
|
183 |
+
|
184 |
+
if( !empty($sidebar_data) ) :
|
185 |
+
$the_sidebar = $this->sidebarAccordion('open', $sidebar_data, $settings, false);
|
186 |
+
|
187 |
+
$the_sidebar .= '<div class="sbg-clearfix">';
|
188 |
+
$the_sidebar .= $this->fieldName($name, $sidebar_data);
|
189 |
+
$the_sidebar .= $this->fieldDescription($name, $sidebar_data);
|
190 |
+
$the_sidebar .= '</div>'; //.sbg-clearfix
|
191 |
+
|
192 |
+
$the_sidebar .= '<div class="sbg-clearfix">';
|
193 |
+
$the_sidebar .= $this->fieldId($name, $sidebar_data);
|
194 |
+
$the_sidebar .= $this->fieldToReplace($name, $sidebar_data);
|
195 |
+
|
196 |
+
// Conditions
|
197 |
+
$the_sidebar .= '<div class="smk-sidebar-row conditions-all smk-sidebar-grid-8">';
|
198 |
+
|
199 |
+
$conditions_checked = isset( $sidebar_data['enable-conditions'] ) ? ' checked="checked"' : '';
|
200 |
+
$the_sidebar .= '<label>
|
201 |
+
<input type="checkbox" name="'. $name. '[enable-conditions]" value="enabled" '. $conditions_checked .' class="smk-sidebar-enable-conditions" />'.
|
202 |
+
__('Enable conditions:', 'smk-sidebar-generator')
|
203 |
+
.'</label>';
|
204 |
+
|
205 |
+
|
206 |
+
$disbled_conditions = empty($conditions_checked) ? ' disabled-conditions' : '';
|
207 |
+
$the_sidebar .= '<div class="created-conditions'. $disbled_conditions .'">';
|
208 |
+
if( !empty($sidebar_data['conditions']) ){
|
209 |
+
foreach ( (array) $sidebar_data['conditions'] as $index => $condition) {
|
210 |
+
$the_sidebar .= $this->aSingleCondition($name, $sidebar_data, $index, $condition['if']);
|
211 |
+
}
|
212 |
+
}
|
213 |
+
else{
|
214 |
+
$the_sidebar .= $this->aSingleCondition($name, $sidebar_data, 0, 'all');
|
215 |
+
}
|
216 |
+
$the_sidebar .= '</div>'; //.created-conditions
|
217 |
+
|
218 |
+
$disbled_conditions_btn = empty($conditions_checked) ? ' disabled="disabled"' : '';
|
219 |
+
$the_sidebar .= ' <button class="condition-add button"'. $disbled_conditions_btn .' data-name="'. $name .'" data-sidebar-id="'. $sidebar_data['id'] .'">'. __('Add condition', 'smk-sidebar-generator') .'</button>';
|
220 |
+
$the_sidebar .= '</div>'; //.conditions-all
|
221 |
+
$the_sidebar .= '</div>'; //.sbg-clearfix
|
222 |
+
|
223 |
+
$the_sidebar .= $this->sidebarAccordion('close', $sidebar_data, $settings, false);
|
224 |
+
return $the_sidebar;
|
225 |
+
endif;
|
226 |
+
}
|
227 |
+
|
228 |
+
//------------------------------------//--------------------------------------//
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Sidebar Accordion
|
232 |
+
*
|
233 |
+
* Global parts of a single sidebar accordion
|
234 |
+
*
|
235 |
+
* @param string $part `open` or `close`
|
236 |
+
* @return string The HTML.
|
237 |
+
*/
|
238 |
+
public function sidebarAccordion($part, $sidebar_data = array(), $settings = array(), $echo = true){
|
239 |
+
|
240 |
+
$class = ( !empty( $settings['class'] ) ) ? ' '. $settings['class'] : '';
|
241 |
+
if( $part == 'open' ){
|
242 |
+
$the_sidebar = '
|
243 |
+
<li id="'. $sidebar_data['id'] .'" class="control-section accordion-section'. $class .'">
|
244 |
+
<h3 class="accordion-section-title hndle">
|
245 |
+
<span class="smk-sidebar-section-icon dashicons dashicons-editor-justify"></span>
|
246 |
+
<span class="name">'. $sidebar_data['name'] .'</span>
|
247 |
+
<span class="description">'. $sidebar_data['description'] .'</span>
|
248 |
+
<div class="moderate-sidebar">
|
249 |
+
<span class="smk-delete-sidebar">'. __('Delete', 'smk-sidebar-generator') .'</span>
|
250 |
+
<span class="smk-restore-sidebar">'. __('Restore', 'smk-sidebar-generator') .'</span>
|
251 |
+
</div>
|
252 |
+
</h3>
|
253 |
+
<div class="accordion-section-content" style="display: none;">
|
254 |
+
<div class="inside">';
|
255 |
+
}
|
256 |
+
elseif( $part == 'close' ){
|
257 |
+
$the_sidebar = '</div>
|
258 |
+
</div>
|
259 |
+
</li>';
|
260 |
+
}
|
261 |
+
else{
|
262 |
+
$the_sidebar = '';
|
263 |
+
}
|
264 |
+
|
265 |
+
if( $echo ) { echo $the_sidebar; } else { return $the_sidebar; }
|
266 |
+
}
|
267 |
+
|
268 |
+
//------------------------------------//--------------------------------------//
|
269 |
+
|
270 |
+
/**
|
271 |
+
* A single condition
|
272 |
+
*
|
273 |
+
* Display a single condition
|
274 |
+
*
|
275 |
+
* @param string $name HTML field name
|
276 |
+
* @param string $sidebar_data Data for current sidebar
|
277 |
+
* @return string The HTML
|
278 |
+
*/
|
279 |
+
public function aSingleCondition($name, $sidebar_data, $index = 0, $condition_if = 'all'){
|
280 |
+
$the_sidebar = '<div class="condition-parent sbg-clearfix">';
|
281 |
+
$the_sidebar .= '<span class="smk-sidebar-condition-icon dashicons dashicons-menu"></span>';
|
282 |
+
$the_sidebar .= '<div class="conditions-first">';
|
283 |
+
$the_sidebar .= $this->fieldConditionMain( $name, $sidebar_data, $index );
|
284 |
+
$the_sidebar .= '</div>';
|
285 |
+
$the_sidebar .= '<div class="conditions-second">';
|
286 |
+
$the_sidebar .= $this->fieldConditionEqualTo($name, $sidebar_data, $index, $condition_if);
|
287 |
+
$the_sidebar .= '</div>';
|
288 |
+
$the_sidebar .= ' <span class="condition-remove" title="'. __('Remove condition', 'smk-sidebar-generator') .'"> <i class="dashicons dashicons-no-alt"></i> </span>';
|
289 |
+
$the_sidebar .= '</div>';
|
290 |
+
return $the_sidebar;
|
291 |
+
}
|
292 |
+
|
293 |
+
//------------------------------------//--------------------------------------//
|
294 |
+
|
295 |
+
/**
|
296 |
+
* Sidebar field name
|
297 |
+
*
|
298 |
+
* Display sidebar name field
|
299 |
+
*
|
300 |
+
* @param string $name HTML field name
|
301 |
+
* @param string $sidebar_data Data for current sidebar
|
302 |
+
* @return string The HTML
|
303 |
+
*/
|
304 |
+
public function fieldName($name, $sidebar_data){
|
305 |
+
return '<div class="smk-sidebar-row smk-sidebar-grid-4">
|
306 |
+
<label>'. __('Name:', 'smk-sidebar-generator') .'</label>'.
|
307 |
+
$this->html->input(
|
308 |
+
'', // ID
|
309 |
+
$name. '[name]',
|
310 |
+
$sidebar_data['name'],
|
311 |
+
array(
|
312 |
+
'type' => 'text',
|
313 |
+
'class' => array( 'smk-sidebar-name', 'widefat' ),
|
314 |
+
)
|
315 |
+
)
|
316 |
+
.'</div>';
|
317 |
+
}
|
318 |
+
|
319 |
+
//------------------------------------//--------------------------------------//
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Sidebar field ID
|
323 |
+
*
|
324 |
+
* Display sidebar ID field
|
325 |
+
*
|
326 |
+
* @param string $name HTML field name
|
327 |
+
* @param string $sidebar_data Data for current sidebar
|
328 |
+
* @return string The HTML
|
329 |
+
*/
|
330 |
+
public function fieldId($name, $sidebar_data){
|
331 |
+
return '<div class="smk-sidebar-row" style="display: none;">
|
332 |
+
<label>'. __('ID:', 'smk-sidebar-generator') .'</label>'.
|
333 |
+
$this->html->input(
|
334 |
+
'', // ID
|
335 |
+
$name. '[id]',
|
336 |
+
$sidebar_data['id'],
|
337 |
+
array(
|
338 |
+
'type' => 'text',
|
339 |
+
'class' => array( 'smk-sidebar-id' ),
|
340 |
+
)
|
341 |
+
)
|
342 |
+
.'</div>';
|
343 |
+
}
|
344 |
+
|
345 |
+
//------------------------------------//--------------------------------------//
|
346 |
+
|
347 |
+
/**
|
348 |
+
* Sidebar field description
|
349 |
+
*
|
350 |
+
* Display sidebar description field
|
351 |
+
*
|
352 |
+
* @param string $name HTML field name
|
353 |
+
* @param string $sidebar_data Data for current sidebar
|
354 |
+
* @return string The HTML
|
355 |
+
*/
|
356 |
+
public function fieldDescription($name, $sidebar_data){
|
357 |
+
return '<div class="smk-sidebar-row smk-sidebar-grid-8">
|
358 |
+
<label>'. __('Description:', 'smk-sidebar-generator') .'</label>'.
|
359 |
+
$this->html->input(
|
360 |
+
'', // ID
|
361 |
+
$name. '[description]',
|
362 |
+
$sidebar_data['description'],
|
363 |
+
array(
|
364 |
+
'type' => 'text',
|
365 |
+
'class' => array( 'smk-sidebar-description', 'widefat' ),
|
366 |
+
)
|
367 |
+
)
|
368 |
+
.'</div>';
|
369 |
+
}
|
370 |
+
|
371 |
+
//------------------------------------//--------------------------------------//
|
372 |
+
|
373 |
+
/**
|
374 |
+
* Sidebar field To Replace
|
375 |
+
*
|
376 |
+
* Display sidebar To Replace field
|
377 |
+
*
|
378 |
+
* @param string $name HTML field name
|
379 |
+
* @param string $sidebar_data Data for current sidebar
|
380 |
+
* @return string The HTML
|
381 |
+
*/
|
382 |
+
public function fieldToReplace($name, $sidebar_data){
|
383 |
+
|
384 |
+
// To replace
|
385 |
+
$static = $this->allStaticSidebars();
|
386 |
+
$static_sidebars = '';
|
387 |
+
foreach ($static as $key => $value) {
|
388 |
+
$static_sidebars[ $key ] = $value['name'];
|
389 |
+
}
|
390 |
+
|
391 |
+
$replace = !empty( $sidebar_data['replace'] ) ? $sidebar_data['replace'] : array();
|
392 |
+
|
393 |
+
return '<div class="smk-sidebar-row smk-sidebar-grid-4">
|
394 |
+
<label>'. __('Sidebars to replace:', 'smk-sidebar-generator') .'</label>'.
|
395 |
+
$this->html->select(
|
396 |
+
'', // ID
|
397 |
+
$name. '[replace][]',
|
398 |
+
$replace,
|
399 |
+
array(
|
400 |
+
'multiple' => 'multiple',
|
401 |
+
'options' => $static_sidebars,
|
402 |
+
'size' => 9,
|
403 |
+
'class' => array( 'sidebars-to-replace-select' ),
|
404 |
+
)
|
405 |
+
)
|
406 |
+
.'
|
407 |
+
<br />
|
408 |
+
<label>'. __('Shortcode:', 'smk-sidebar-generator') .'</label>
|
409 |
+
<code class="smk-sidebar-shortcode">smk_sidebar="'. $sidebar_data['id'] .'"</code>
|
410 |
+
</div>';
|
411 |
+
}
|
412 |
+
|
413 |
+
//------------------------------------//--------------------------------------//
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Sidebar field Condition main
|
417 |
+
*
|
418 |
+
* Display sidebar Condition main field
|
419 |
+
*
|
420 |
+
* @param string $name HTML field name
|
421 |
+
* @param string $sidebar_data Data for current sidebar
|
422 |
+
* @return string The HTML
|
423 |
+
*/
|
424 |
+
public function fieldConditionMain($name, $sidebar_data, $index = 0){
|
425 |
+
|
426 |
+
$options = array( 'none' => __('None', 'smk-sidebar-generator') );
|
427 |
+
$all_conditions = smk_sidebar_conditions_filter();
|
428 |
+
if( !empty($all_conditions) && is_array($all_conditions) ){
|
429 |
+
foreach ($all_conditions as $type => $class) {
|
430 |
+
if( class_exists($class) ){
|
431 |
+
$newclass = new $class;
|
432 |
+
$newoptions = $newclass->getMainData();
|
433 |
+
if( !empty($newoptions) && is_array($newoptions) ){
|
434 |
+
$options[] = $newoptions;
|
435 |
+
}
|
436 |
+
}
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
+
$saved = ! empty( $sidebar_data['conditions'][ absint( $index ) ]['if'] ) ?
|
441 |
+
$sidebar_data['conditions'][ absint( $index ) ]['if'] : '';
|
442 |
+
|
443 |
+
return '<span class="condition-label">'. __('Replace if', 'smk-sidebar-generator') .' </span>'.
|
444 |
+
$this->html->select(
|
445 |
+
'', // ID
|
446 |
+
$name. '[conditions]['. absint( $index ) .'][if]',
|
447 |
+
$saved,
|
448 |
+
array(
|
449 |
+
'options' => $options,
|
450 |
+
'class' => array('condition-if'),
|
451 |
+
)
|
452 |
+
);
|
453 |
+
}
|
454 |
+
|
455 |
+
//------------------------------------//--------------------------------------//
|
456 |
+
|
457 |
+
/**
|
458 |
+
* Sidebar field Condition EqualTo
|
459 |
+
*
|
460 |
+
* Display sidebar Condition EqualTo field
|
461 |
+
*
|
462 |
+
* @param string $name HTML field name
|
463 |
+
* @param string $sidebar_data Data for current sidebar
|
464 |
+
* @return string The HTML
|
465 |
+
*/
|
466 |
+
public function fieldConditionEqualTo($name, $sidebar_data, $index = 0, $type){
|
467 |
+
|
468 |
+
$saved = ! empty( $sidebar_data['conditions'][ absint( $index ) ]['equalto'] ) ? $sidebar_data['conditions'][ absint( $index ) ]['equalto'] : '';
|
469 |
+
|
470 |
+
return '<span class="condition-label">'. __('and is equal to', 'smk-sidebar-generator') .'</span>' .
|
471 |
+
$this->html->select(
|
472 |
+
'', // ID
|
473 |
+
$name. '[conditions]['. absint( $index ) .'][equalto][]',
|
474 |
+
$saved,
|
475 |
+
array(
|
476 |
+
'options' => $this->getEqualToOptions($type),
|
477 |
+
'multiple' => 'multiple',
|
478 |
+
'size' => 5,
|
479 |
+
'class' => array('condition-equalto'),
|
480 |
+
)
|
481 |
+
);
|
482 |
+
}
|
483 |
+
|
484 |
+
//------------------------------------//--------------------------------------//
|
485 |
+
|
486 |
+
/**
|
487 |
+
* Get Equal to Options
|
488 |
+
*
|
489 |
+
* @param string $type Example pot_type::page
|
490 |
+
* @return array
|
491 |
+
*/
|
492 |
+
public function getEqualToOptions($type){
|
493 |
+
$the_type = explode('::', $type);
|
494 |
+
$options = array();
|
495 |
+
$all_conditions = smk_sidebar_conditions_filter();
|
496 |
+
|
497 |
+
if( !empty($all_conditions) && is_array($all_conditions) ){
|
498 |
+
if( array_key_exists($the_type[0], $all_conditions) ){
|
499 |
+
$class = $all_conditions[ $the_type[0] ];
|
500 |
+
if( class_exists($class) ){
|
501 |
+
$newclass = new $class;
|
502 |
+
$newoptions = $newclass->getSecondaryData( $type );
|
503 |
+
if( !empty($newoptions) && is_array($newoptions) ){
|
504 |
+
$options = $options + (array) $newoptions;
|
505 |
+
}
|
506 |
+
}
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
return $options;
|
511 |
+
}
|
512 |
+
|
513 |
+
public function equaltoAjax(){
|
514 |
+
$data = $_POST['data'];
|
515 |
+
$type = $data['condition_if'];
|
516 |
+
$opt = $this->getEqualToOptions($type);
|
517 |
+
|
518 |
+
echo json_encode( $opt );
|
519 |
+
|
520 |
+
die();
|
521 |
+
}
|
522 |
+
|
523 |
+
//------------------------------------//--------------------------------------//
|
524 |
+
|
525 |
+
/**
|
526 |
+
* All removed sidebars list
|
527 |
+
*
|
528 |
+
* All removed sidebars list
|
529 |
+
*
|
530 |
+
* @return string The HTML.
|
531 |
+
*/
|
532 |
+
public function allRemovedSidebarsList($echo = true){
|
533 |
+
$list = '<div class="smk-sidebars-grid removed-sidebars">
|
534 |
+
<h3>
|
535 |
+
'. __('Removed', 'smk-sidebar-generator') .'
|
536 |
+
<span class="tip dashicons-before dashicons-editor-help" title="'. __('These sidebars will be removed on the next page refresh.', 'smk-sidebar-generator') .'"></span>
|
537 |
+
</h3>
|
538 |
+
<div id="smk-removed-sidebars" class="accordion-container smk-sidebars-list">
|
539 |
+
<ul class="connected-sidebars-lists"></ul>
|
540 |
+
</div>
|
541 |
+
</div>';
|
542 |
+
if( $echo ) { echo $list; } else { return $list; }
|
543 |
+
}
|
544 |
+
|
545 |
+
//------------------------------------//--------------------------------------//
|
546 |
+
|
547 |
+
/**
|
548 |
+
* Sidebar Template
|
549 |
+
*
|
550 |
+
* Create the template for new sidebars generation
|
551 |
+
*
|
552 |
+
* @return string The HTML.
|
553 |
+
*/
|
554 |
+
public function sidebarListTemplate($echo = true){
|
555 |
+
$sidebar_data = array(
|
556 |
+
'name' => sprintf( __('New sidebar %s', 'smk-sidebar-generator'), '__index__' ),
|
557 |
+
'id' => '__id__',
|
558 |
+
'description' => '',
|
559 |
+
);
|
560 |
+
|
561 |
+
$settings = array(
|
562 |
+
'option_name' => $this->pluginSettings('option_name'),
|
563 |
+
'class' => 'sidebar-template',
|
564 |
+
);
|
565 |
+
$item = $this->aSingleListItem( $sidebar_data, $settings );
|
566 |
+
if( $echo ) { echo $item; } else { return $item; }
|
567 |
+
}
|
568 |
+
|
569 |
+
}
|
570 |
+
}
|
smk-sidebar-generator.php
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Plugin Name: SMK Sidebar Generator
|
4 |
+
* Plugin URI: https://zerowp.com/sidebar-generator
|
5 |
+
* Description: Generate an unlimited number of sidebars and assign them to any page using the conditional options without touching a single line of code.
|
6 |
+
* Author: Andrei Surdu
|
7 |
+
* Version: 3.2.0
|
8 |
+
* Author URI: https://zerowp.com
|
9 |
+
* Licence: GPLv2
|
10 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
+
*/
|
12 |
+
|
13 |
+
// Do not allow direct access to this file.
|
14 |
+
if( ! function_exists('add_action') )
|
15 |
+
die();
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Plugin version
|
19 |
+
*
|
20 |
+
* Get the current plugin version.
|
21 |
+
*
|
22 |
+
* @return string
|
23 |
+
*/
|
24 |
+
function smk_sidebar_version(){
|
25 |
+
if( is_admin() ){
|
26 |
+
$data = get_file_data( __FILE__, array( 'Version' ) );
|
27 |
+
return empty( $data ) ? '' : $data[0];
|
28 |
+
}
|
29 |
+
else{
|
30 |
+
return false;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* All conditions
|
36 |
+
*
|
37 |
+
* All condtions will be accessible from this function
|
38 |
+
*
|
39 |
+
* @return array All conditions type => class_name
|
40 |
+
*/
|
41 |
+
function smk_sidebar_conditions_filter(){
|
42 |
+
return apply_filters( 'smk_sidebar_conditions_filter', array() );
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Register a condition
|
47 |
+
*
|
48 |
+
* Register a condition and inject it in the main array
|
49 |
+
*
|
50 |
+
* @param string $name Condition class name
|
51 |
+
* @return void
|
52 |
+
*/
|
53 |
+
class Smk_Sidebar_Generator_Register_Condition{
|
54 |
+
public $name;
|
55 |
+
public $allCond;
|
56 |
+
|
57 |
+
public function __construct( $name ){
|
58 |
+
$this->name = $name;
|
59 |
+
$this->allCond = smk_sidebar_conditions_filter();
|
60 |
+
add_filter( 'smk_sidebar_conditions_filter', array( $this, 'add') );
|
61 |
+
}
|
62 |
+
public function add(){
|
63 |
+
if( class_exists( $this->name ) ){
|
64 |
+
$class = new $this->name;
|
65 |
+
if( ! array_key_exists($class->type, $this->allCond) ){
|
66 |
+
return array( $class->type => $this->name );
|
67 |
+
}
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Register condition helper
|
74 |
+
*
|
75 |
+
* @param string $name Condition class name
|
76 |
+
* @use Smk_Sidebar_Generator_Register_Condition
|
77 |
+
* @return void
|
78 |
+
*/
|
79 |
+
function smk_register_condition( $name ){
|
80 |
+
new Smk_Sidebar_Generator_Register_Condition( $name );
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
//------------------------------------//--------------------------------------//
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Translate plugin
|
88 |
+
*
|
89 |
+
* Load plugin languages
|
90 |
+
*
|
91 |
+
*/
|
92 |
+
add_action('plugins_loaded', 'smk_sidebar_load_textdomain');
|
93 |
+
function smk_sidebar_load_textdomain() {
|
94 |
+
load_plugin_textdomain( 'smk-sidebar-generator', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
|
95 |
+
}
|
96 |
+
|
97 |
+
/*
|
98 |
+
-------------------------------------------------------------------------------
|
99 |
+
Smk Sidebar function
|
100 |
+
-------------------------------------------------------------------------------
|
101 |
+
*/
|
102 |
+
function smk_sidebar($id){
|
103 |
+
if(function_exists('dynamic_sidebar') && dynamic_sidebar($id)) :
|
104 |
+
endif;
|
105 |
+
return true;
|
106 |
+
}
|
107 |
+
|
108 |
+
/*
|
109 |
+
-------------------------------------------------------------------------------
|
110 |
+
Smk All Sidebars
|
111 |
+
-------------------------------------------------------------------------------
|
112 |
+
*/
|
113 |
+
if(! function_exists('smk_get_all_sidebars') ) {
|
114 |
+
function smk_get_all_sidebars(){
|
115 |
+
global $wp_registered_sidebars;
|
116 |
+
$all_sidebars = array();
|
117 |
+
if ( $wp_registered_sidebars && ! is_wp_error( $wp_registered_sidebars ) ) {
|
118 |
+
|
119 |
+
foreach ( $wp_registered_sidebars as $sidebar ) {
|
120 |
+
$all_sidebars[ $sidebar['id'] ] = $sidebar['name'];
|
121 |
+
}
|
122 |
+
|
123 |
+
}
|
124 |
+
return $all_sidebars;
|
125 |
+
}
|
126 |
+
}
|
127 |
+
|
128 |
+
/*
|
129 |
+
----------------------------------------------------------------------
|
130 |
+
Shortcode
|
131 |
+
----------------------------------------------------------------------
|
132 |
+
*/
|
133 |
+
// [smk_sidebar id="X"] //X is the sidebar ID
|
134 |
+
function smk_sidebar_shortcode( $atts ) {
|
135 |
+
|
136 |
+
extract( shortcode_atts( array(
|
137 |
+
'id' => null,
|
138 |
+
), $atts ) );
|
139 |
+
smk_sidebar($id);
|
140 |
+
}
|
141 |
+
add_shortcode( 'smk_sidebar', 'smk_sidebar_shortcode' );
|
142 |
+
|
143 |
+
/* Plugin path
|
144 |
+
------------------------------------------------*/
|
145 |
+
$path = plugin_dir_path( __FILE__ );
|
146 |
+
|
147 |
+
/* HTML helper
|
148 |
+
------------------------------------------------*/
|
149 |
+
require_once $path . 'html.php';
|
150 |
+
|
151 |
+
/* Conditions
|
152 |
+
------------------------------------------------*/
|
153 |
+
require_once $path . 'condition.php';
|
154 |
+
require_once $path . 'condition-cpt.php';
|
155 |
+
|
156 |
+
/* Init conditions
|
157 |
+
------------------------------------------------*/
|
158 |
+
smk_register_condition( 'Smk_Sidebar_Generator_Condition_Cpt' );
|
159 |
+
|
160 |
+
/* Plugin work
|
161 |
+
------------------------------------------------*/
|
162 |
+
require_once $path . 'abstract.php';
|
163 |
+
require_once $path . 'render.php';
|
164 |
+
require_once $path . 'apply.php';
|
165 |
+
|
166 |
+
/* Init plugin
|
167 |
+
------------------------------------------------*/
|
168 |
+
$smk_sidebar_generator = new Smk_Sidebar_Generator;
|
169 |
+
$smk_sidebar_generator->init();
|
170 |
+
|
171 |
+
/* Apply conditions
|
172 |
+
------------------------------------------------*/
|
173 |
+
$applySidebars = new Smk_Sidebar_Generator_Apply;
|