Version Description
- Fix" Incorrect conditional replacement.
- Compatibility with WordPress 5.5
Download this release
Release Info
Developer | _smartik_ |
Plugin | SMK Sidebar Generator |
Version | 3.4.0 |
Comparing to | |
See all releases |
Code changes from version 3.3.1 to 3.4.0
- condition-cpt.php +114 -108
- readme.txt +13 -13
- smk-sidebar-generator.php +15 -13
condition-cpt.php
CHANGED
@@ -1,121 +1,127 @@
|
|
1 |
<?php
|
2 |
class Smk_Sidebar_Generator_Condition_Cpt extends Smk_Sidebar_Generator_Condition{
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
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 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
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 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
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( in_array(get_the_ID(), (array)$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( in_array(get_the_ID(), (array)$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(
|
108 |
+
in_array('all_archives_single', (array) $second_selection) &&
|
109 |
+
(
|
110 |
+
is_singular( $first_selection ) ||
|
111 |
+
is_post_type_archive( $first_selection )
|
112 |
+
)
|
113 |
+
){
|
114 |
+
$can = true;
|
115 |
+
}
|
116 |
+
elseif( in_array('all_single', (array) $second_selection) && is_single( $first_selection ) ){
|
117 |
+
$can = true;
|
118 |
+
}
|
119 |
+
elseif( in_array(get_the_ID(), (array)$second_selection)){
|
120 |
+
$can = true;
|
121 |
+
}
|
122 |
+
}
|
123 |
|
124 |
+
return $can;
|
125 |
+
}
|
126 |
+
|
127 |
+
}
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: _smartik_
|
3 |
Tags: sidebar, widget, generator, custom, unlimited
|
4 |
Requires at least: 4.0
|
5 |
-
Tested up to: 5.
|
6 |
-
Stable tag: 3.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -12,9 +12,6 @@ This plugin generates as many sidebars as you need. Then allows you to place the
|
|
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 |
|
@@ -22,7 +19,7 @@ The new version 3.x has many advantages compared with the old 2.x. First and the
|
|
22 |
|
23 |
####Features:
|
24 |
* Unlimited number of sidebars.
|
25 |
-
* Replace default theme sidebars using the conditions or
|
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 |
|
@@ -31,21 +28,20 @@ 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
|
38 |
|
39 |
**Display a sidebar using `smk_sidebar` function:**
|
40 |
<pre>
|
41 |
if(function_exists('smk_sidebar'){
|
42 |
-
|
43 |
}
|
44 |
</pre>
|
45 |
**Display a sidebar using wp native function:**
|
46 |
<pre>
|
47 |
-
|
48 |
-
endif;
|
49 |
</pre>
|
50 |
|
51 |
**Display a sidebar using built-in shortcode:**
|
@@ -65,6 +61,10 @@ if(function_exists('dynamic_sidebar') && dynamic_sidebar('sidebarID')) :
|
|
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.
|
@@ -76,7 +76,7 @@ if(function_exists('dynamic_sidebar') && dynamic_sidebar('sidebarID')) :
|
|
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
|
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 =
|
@@ -100,5 +100,5 @@ if(function_exists('dynamic_sidebar') && dynamic_sidebar('sidebarID')) :
|
|
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
|
2 |
Contributors: _smartik_
|
3 |
Tags: sidebar, widget, generator, custom, unlimited
|
4 |
Requires at least: 4.0
|
5 |
+
Tested up to: 5.5
|
6 |
+
Stable tag: 3.4.0
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
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 |
|
16 |
<!--**Demo video:** http://youtu.be/fluNdMnSCKA-->
|
17 |
|
19 |
|
20 |
####Features:
|
21 |
* Unlimited number of sidebars.
|
22 |
+
* Replace default theme sidebars using the conditions or globally just by selecting the sidebar that you want to replace.
|
23 |
* Show the generated sidebars on any page you wish without touching a single line of code in your theme.
|
24 |
* Drag to sort sidebar position.
|
25 |
|
28 |
Drop `smk-sidebar-generator` to `wp-content/plugins/`.<br />
|
29 |
More info here: http://codex.wordpress.org/Managing_Plugins#Installing_Plugins
|
30 |
|
31 |
+
####Backward compatibility.
|
32 |
|
33 |
Because you probably still need them, these functions are still here to not break your site.
|
34 |
+
**Note:** The following code is for version 2.x In the latest version of this plugin they are not required. Do not use them anymore!!!
|
35 |
|
36 |
**Display a sidebar using `smk_sidebar` function:**
|
37 |
<pre>
|
38 |
if(function_exists('smk_sidebar'){
|
39 |
+
smk_sidebar('sidebarID');
|
40 |
}
|
41 |
</pre>
|
42 |
**Display a sidebar using wp native function:**
|
43 |
<pre>
|
44 |
+
dynamic_sidebar('sidebarID'));
|
|
|
45 |
</pre>
|
46 |
|
47 |
**Display a sidebar using built-in shortcode:**
|
61 |
|
62 |
== Changelog ==
|
63 |
|
64 |
+
= 3.4.0 =
|
65 |
+
* Fix" Incorrect conditional replacement.
|
66 |
+
* Compatibility with WordPress 5.5
|
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.
|
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 incorrect 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 =
|
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
|
smk-sidebar-generator.php
CHANGED
@@ -1,25 +1,27 @@
|
|
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.
|
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() ){
|
@@ -36,7 +38,7 @@ function smk_sidebar_version(){
|
|
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() );
|
@@ -48,7 +50,7 @@ function smk_sidebar_conditions_filter(){
|
|
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;
|
@@ -74,7 +76,7 @@ class Smk_Sidebar_Generator_Register_Condition{
|
|
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 );
|
@@ -100,7 +102,7 @@ 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 |
}
|
@@ -115,11 +117,11 @@ if(! function_exists('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 |
}
|
@@ -132,7 +134,7 @@ Shortcode
|
|
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 ) );
|
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.4.0
|
8 |
* Author URI: https://zerowp.com
|
9 |
* Licence: GPLv2
|
10 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
+
* Requires PHP: 5.3
|
12 |
+
* Requires at least: 4.0
|
13 |
*/
|
14 |
|
15 |
// Do not allow direct access to this file.
|
16 |
+
if( ! function_exists('add_action') )
|
17 |
die();
|
18 |
|
19 |
/**
|
20 |
* Plugin version
|
21 |
*
|
22 |
* Get the current plugin version.
|
23 |
+
*
|
24 |
+
* @return string
|
25 |
*/
|
26 |
function smk_sidebar_version(){
|
27 |
if( is_admin() ){
|
38 |
*
|
39 |
* All condtions will be accessible from this function
|
40 |
*
|
41 |
+
* @return array All conditions type => class_name
|
42 |
*/
|
43 |
function smk_sidebar_conditions_filter(){
|
44 |
return apply_filters( 'smk_sidebar_conditions_filter', array() );
|
50 |
* Register a condition and inject it in the main array
|
51 |
*
|
52 |
* @param string $name Condition class name
|
53 |
+
* @return void
|
54 |
*/
|
55 |
class Smk_Sidebar_Generator_Register_Condition{
|
56 |
public $name;
|
76 |
*
|
77 |
* @param string $name Condition class name
|
78 |
* @use Smk_Sidebar_Generator_Register_Condition
|
79 |
+
* @return void
|
80 |
*/
|
81 |
function smk_register_condition( $name ){
|
82 |
new Smk_Sidebar_Generator_Register_Condition( $name );
|
102 |
-------------------------------------------------------------------------------
|
103 |
*/
|
104 |
function smk_sidebar($id){
|
105 |
+
if(function_exists('dynamic_sidebar') && dynamic_sidebar($id)) :
|
106 |
endif;
|
107 |
return true;
|
108 |
}
|
117 |
global $wp_registered_sidebars;
|
118 |
$all_sidebars = array();
|
119 |
if ( $wp_registered_sidebars && ! is_wp_error( $wp_registered_sidebars ) ) {
|
120 |
+
|
121 |
foreach ( $wp_registered_sidebars as $sidebar ) {
|
122 |
$all_sidebars[ $sidebar['id'] ] = $sidebar['name'];
|
123 |
}
|
124 |
+
|
125 |
}
|
126 |
return $all_sidebars;
|
127 |
}
|
134 |
*/
|
135 |
// [smk_sidebar id="X"] //X is the sidebar ID
|
136 |
function smk_sidebar_shortcode( $atts ) {
|
137 |
+
|
138 |
extract( shortcode_atts( array(
|
139 |
'id' => null,
|
140 |
), $atts ) );
|