Cherry Sidebars - Version 1.0.2

Version Description

  • FIX: custom sidebars option name
  • FIX: WooCommerce Ajax Navigation: sidebars_widgets filter should check WP_Query
Download this release

Release Info

Developer TemplateMonster 2002
Plugin Icon 128x128 Cherry Sidebars
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0 to 1.0.2

admin/includes/class-cherry-custom-sidebar.php CHANGED
@@ -1,249 +1,253 @@
1
- <?php
2
- /**
3
- * Class for render and saving custom sidebars.
4
- *
5
- * @package Cherry_Sidebars
6
- * @author Template Monster
7
- * @license GPL-3.0+
8
- * @copyright 2002-2016, Template Monster
9
- */
10
-
11
- // If this file is called directly, abort.
12
- if ( ! defined( 'WPINC' ) ) {
13
- die;
14
- }
15
-
16
- if ( ! class_exists( 'Cherry_Custom_Sidebar' ) ) {
17
-
18
- /**
19
- * Class for render and saving custom sidebars.
20
- *
21
- * @since 1.0.0
22
- */
23
- class Cherry_Custom_Sidebar {
24
-
25
- /**
26
- * Holds the instances of this class.
27
- *
28
- * @since 1.0.0
29
- * @var object
30
- */
31
- private static $instance = null;
32
-
33
- /**
34
- * Sets up the needed actions for adding and saving the meta boxes.
35
- *
36
- * @since 1.0.0
37
- */
38
- public function __construct() {
39
-
40
- // Add the `Layout` meta box on the 'add_meta_boxes' hook.
41
- add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
42
-
43
- // Saves the post format on the post editing page.
44
- add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
45
-
46
- // Registrate dynamic sidebar
47
- add_action( 'register_sidebar', array( $this, 'register_dynamic_sidebar' ) );
48
- }
49
-
50
- /**
51
- * Adds the meta box if the post type supports 'cherry-post-style' and the current user has
52
- * permission to edit post meta.
53
- *
54
- * @since 1.0.0
55
- * @param string $post_type The post type of the current post being edited.
56
- * @param object $post The current post object.
57
- * @return void
58
- */
59
- public function add_meta_boxes( $post_type, $post ) {
60
- $allowed_post_types = apply_filters(
61
- 'cherry_sidebar_post_type',
62
- array(
63
- 'page',
64
- 'post',
65
- 'portfolio',
66
- 'testimonial',
67
- 'service',
 
 
 
68
  'team',
69
- 'product',
70
- )
71
- );
72
-
73
- if ( in_array( $post_type, $allowed_post_types )
74
- && ( current_user_can( 'edit_post_meta', $post->ID )
75
- || current_user_can( 'add_post_meta', $post->ID )
76
- || current_user_can( 'delete_post_meta', $post->ID ) )
77
- ) {
78
-
79
- /**
80
- * Filter the array of 'add_meta_box' parametrs.
81
- *
82
- * @since 1.0.0
83
- */
84
- $metabox = apply_filters( 'cherry_custom_sidebar', array(
85
- 'id' => 'cherry-sidebars',
86
- 'title' => __( 'Post Sidebars', 'cherry' ),
87
- 'page' => $post_type,
88
- 'context' => 'side',
89
- 'priority' => 'default',
90
- 'callback_args' => false,
91
- ) );
92
-
93
- /**
94
- * Add meta box to the administrative interface.
95
- *
96
- * @link http://codex.wordpress.org/Function_Reference/add_meta_box
97
- */
98
- add_meta_box(
99
- $metabox['id'],
100
- $metabox['title'],
101
- array( $this, 'callback_metabox' ),
102
- $metabox['page'],
103
- $metabox['context'],
104
- $metabox['priority'],
105
- $metabox['callback_args']
106
- );
107
- }
108
- }
109
-
110
- /**
111
- * Displays a meta box of radio selectors on the post editing screen, which allows theme users to select
112
- * the layout they wish to use for the specific post.
113
- *
114
- * @since 1.0.0
115
- * @param object $post The post object currently being edited.
116
- * @param array $metabox Specific information about the meta box being loaded.
117
- * @return void
118
- */
119
- public function callback_metabox( $post, $metabox ) {
120
- wp_nonce_field( basename( __FILE__ ), 'cherry-sidebar-nonce' );
121
-
122
- global $wp_registered_sidebars;
123
-
124
- $select_sidebar = $this->get_post_sidebar( $post->ID );
125
- $select_options = array( '' => __( 'Sidebar not selected', 'cherry-sidebars' ) );
126
-
127
- foreach ( $wp_registered_sidebars as $sidebar => $sidebar_value ) {
128
- $select_options[ $sidebar_value['id'] ] = $sidebar_value['name'];
129
- }
130
-
131
- foreach ( $wp_registered_sidebars as $sidebar => $sidebar_value ) {
132
- if ( array_key_exists( 'dynamic-sidebar',$sidebar_value ) ) {
133
- continue;
134
- }
135
-
136
- if ( array_key_exists( 'is_global',$sidebar_value ) && false === $sidebar_value['is_global'] ) {
137
- continue;
138
- }
139
-
140
- $output = '<p><strong>' . $sidebar_value['name'] . '</strong></p>';
141
-
142
- $value = ( is_array( $select_sidebar ) && array_key_exists( $sidebar_value['id'], $select_sidebar ) ) ? $select_sidebar[ $sidebar_value['id'] ] : '' ;
143
-
144
- $ui_select = new UI_Select(
145
- array(
146
- 'id' => $sidebar_value['id'],
147
- 'name' => 'theme_sidebar[' . $sidebar_value['id'] . ']',
148
- 'value' => $value,
149
- 'options' => $select_options,
150
-
151
- )
152
- );
153
-
154
- $output .= $ui_select->render();
155
-
156
- echo $output;
157
- };
158
-
159
- ?>
160
- <p class="howto">
161
- <?php printf(
162
- __( 'You can choose page sidebars or create a new sidebar on %swidgets page%s .', 'cherry-sidebars' ),
163
- '<a href="widgets.php" target="_blank" title="' . __( 'Widgets Page', 'cherry-sidebars' ) . '">',
164
- '</a>'
165
- ); ?>
166
- </p>
167
- <?php
168
- }
169
-
170
- /**
171
- * Register dynamic sidebar.
172
- *
173
- * @since 1.0.0
174
- * @return void
175
- */
176
- public function register_dynamic_sidebar() {
177
- global $wp_registered_sidebars;
178
-
179
- $instance = new Cherry_Sidebar_Utils();
180
- $cusotm_sidebar_array = $instance->get_custom_sidebar_array();
181
-
182
- unset( $cusotm_sidebar_array['cherry-sidebars-counter'] );
183
- $wp_registered_sidebars = array_merge( $wp_registered_sidebars, $cusotm_sidebar_array );
184
- }
185
-
186
- /**
187
- * Saves the post style metadata if on the post editing screen in the admin.
188
- *
189
- * @since 1.0.0
190
- * @param int $post_id The ID of the current post being saved.
191
- * @param object $post The post object currently being saved.
192
- * @return void|int
193
- */
194
- public function save_post( $post_id, $post = '' ) {
195
-
196
- if ( ! is_object( $post ) ) {
197
- $post = get_post();
198
- }
199
-
200
- // Verify the nonce for the post formats meta box.
201
- if ( ! isset( $_POST['cherry-sidebar-nonce'] )
202
- || ! wp_verify_nonce( $_POST['cherry-sidebar-nonce'], basename( __FILE__ ) )
203
- ) {
204
- return $post_id;
205
- }
206
-
207
- // Get the meta key.
208
- $meta_key = 'post_sidebar';
209
-
210
- // Get the all submitted `page-sidebar-manager` data.
211
- $sidebar_id = $_POST['theme_sidebar'];
212
-
213
- update_post_meta( $post_id, $meta_key, $sidebar_id );
214
- }
215
-
216
- /**
217
- * Function get post or page sidebar.
218
- *
219
- * @since 1.0.0
220
- * @param int $post_id The ID of the current post being saved.
221
- * @return string $post_sidebar Sidebar id value.
222
- */
223
- public function get_post_sidebar( $post_id ) {
224
-
225
- // Get the $post_sidebar.
226
- $post_sidebar = get_post_meta( $post_id, 'post_sidebar', true );
227
-
228
- return $post_sidebar;
229
- }
230
-
231
- /**
232
- * Returns the instance.
233
- *
234
- * @since 1.0.0
235
- * @return object
236
- */
237
- public static function get_instance() {
238
-
239
- // If the single instance hasn't been set, set it now.
240
- if ( null == self::$instance ) {
241
- self::$instance = new self;
242
- }
243
-
244
- return self::$instance;
245
- }
246
- }
247
-
248
- Cherry_Custom_Sidebar::get_instance();
249
- }
 
1
+ <?php
2
+ /**
3
+ * Class for render and saving custom sidebars.
4
+ *
5
+ * @package Cherry_Sidebars
6
+ * @author Template Monster
7
+ * @license GPL-3.0+
8
+ * @copyright 2002-2016, Template Monster
9
+ */
10
+
11
+ // If this file is called directly, abort.
12
+ if ( ! defined( 'WPINC' ) ) {
13
+ die;
14
+ }
15
+
16
+ if ( ! class_exists( 'Cherry_Custom_Sidebar' ) ) {
17
+
18
+ /**
19
+ * Class for render and saving custom sidebars.
20
+ *
21
+ * @since 1.0.0
22
+ */
23
+ class Cherry_Custom_Sidebar {
24
+
25
+ /**
26
+ * Holds the instances of this class.
27
+ *
28
+ * @since 1.0.0
29
+ * @var object
30
+ */
31
+ private static $instance = null;
32
+
33
+ /**
34
+ * Sets up the needed actions for adding and saving the meta boxes.
35
+ *
36
+ * @since 1.0.0
37
+ */
38
+ public function __construct() {
39
+
40
+ // Add the `Layout` meta box on the 'add_meta_boxes' hook.
41
+ add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
42
+
43
+ // Saves the post format on the post editing page.
44
+ add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
45
+
46
+ // Registrate dynamic sidebar
47
+ add_action( 'register_sidebar', array( $this, 'register_dynamic_sidebar' ) );
48
+ }
49
+
50
+ /**
51
+ * Adds the meta box if the post type supports 'cherry-post-style' and the current user has
52
+ * permission to edit post meta.
53
+ *
54
+ * @since 1.0.0
55
+ * @param string $post_type The post type of the current post being edited.
56
+ * @param object $post The current post object.
57
+ * @return void
58
+ */
59
+ public function add_meta_boxes( $post_type, $post ) {
60
+
61
+ cherry_sidebars()->init_modules();
62
+
63
+ $allowed_post_types = apply_filters(
64
+ 'cherry_sidebar_post_type',
65
+ array(
66
+ 'page',
67
+ 'post',
68
+ 'portfolio',
69
+ 'testimonial',
70
+ 'service',
71
  'team',
72
+ 'product',
73
+ )
74
+ );
75
+
76
+ if ( in_array( $post_type, $allowed_post_types )
77
+ && ( current_user_can( 'edit_post_meta', $post->ID )
78
+ || current_user_can( 'add_post_meta', $post->ID )
79
+ || current_user_can( 'delete_post_meta', $post->ID ) )
80
+ ) {
81
+
82
+ /**
83
+ * Filter the array of 'add_meta_box' parametrs.
84
+ *
85
+ * @since 1.0.0
86
+ */
87
+ $metabox = apply_filters( 'cherry_custom_sidebar', array(
88
+ 'id' => 'cherry-sidebars',
89
+ 'title' => __( 'Post Sidebars', 'cherry' ),
90
+ 'page' => $post_type,
91
+ 'context' => 'side',
92
+ 'priority' => 'default',
93
+ 'callback_args' => false,
94
+ ) );
95
+
96
+ /**
97
+ * Add meta box to the administrative interface.
98
+ *
99
+ * @link http://codex.wordpress.org/Function_Reference/add_meta_box
100
+ */
101
+ add_meta_box(
102
+ $metabox['id'],
103
+ $metabox['title'],
104
+ array( $this, 'callback_metabox' ),
105
+ $metabox['page'],
106
+ $metabox['context'],
107
+ $metabox['priority'],
108
+ $metabox['callback_args']
109
+ );
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Displays a meta box of radio selectors on the post editing screen, which allows theme users to select
115
+ * the layout they wish to use for the specific post.
116
+ *
117
+ * @since 1.0.0
118
+ * @param object $post The post object currently being edited.
119
+ * @param array $metabox Specific information about the meta box being loaded.
120
+ * @return void
121
+ */
122
+ public function callback_metabox( $post, $metabox ) {
123
+ cherry_sidebars()->init_modules();
124
+ wp_nonce_field( basename( __FILE__ ), 'cherry-sidebar-nonce' );
125
+
126
+ global $wp_registered_sidebars;
127
+
128
+ $select_sidebar = $this->get_post_sidebar( $post->ID );
129
+ $select_options = array( '' => __( 'Sidebar not selected', 'cherry-sidebars' ) );
130
+
131
+ foreach ( $wp_registered_sidebars as $sidebar => $sidebar_value ) {
132
+ $select_options[ $sidebar_value['id'] ] = $sidebar_value['name'];
133
+ }
134
+
135
+ foreach ( $wp_registered_sidebars as $sidebar => $sidebar_value ) {
136
+ if ( array_key_exists( 'dynamic-sidebar',$sidebar_value ) ) {
137
+ continue;
138
+ }
139
+
140
+ if ( array_key_exists( 'is_global',$sidebar_value ) && false === $sidebar_value['is_global'] ) {
141
+ continue;
142
+ }
143
+
144
+ $output = '<p><strong>' . $sidebar_value['name'] . '</strong></p>';
145
+
146
+ $value = ( is_array( $select_sidebar ) && array_key_exists( $sidebar_value['id'], $select_sidebar ) ) ? $select_sidebar[ $sidebar_value['id'] ] : '' ;
147
+
148
+ $ui_select = new UI_Select(
149
+ array(
150
+ 'id' => $sidebar_value['id'],
151
+ 'name' => 'theme_sidebar[' . $sidebar_value['id'] . ']',
152
+ 'value' => $value,
153
+ 'options' => $select_options,
154
+
155
+ )
156
+ );
157
+
158
+ $output .= $ui_select->render();
159
+
160
+ echo $output;
161
+ };
162
+
163
+ ?>
164
+ <p class="howto">
165
+ <?php printf(
166
+ __( 'You can choose page sidebars or create a new sidebar on %swidgets page%s .', 'cherry-sidebars' ),
167
+ '<a href="widgets.php" target="_blank" title="' . __( 'Widgets Page', 'cherry-sidebars' ) . '">',
168
+ '</a>'
169
+ ); ?>
170
+ </p>
171
+ <?php
172
+ }
173
+
174
+ /**
175
+ * Register dynamic sidebar.
176
+ *
177
+ * @since 1.0.0
178
+ * @return void
179
+ */
180
+ public function register_dynamic_sidebar() {
181
+ global $wp_registered_sidebars;
182
+
183
+ $instance = new Cherry_Sidebar_Utils();
184
+ $cusotm_sidebar_array = $instance->get_custom_sidebar_array();
185
+
186
+ unset( $cusotm_sidebar_array['cherry-sidebars-counter'] );
187
+ $wp_registered_sidebars = array_merge( $wp_registered_sidebars, $cusotm_sidebar_array );
188
+ }
189
+
190
+ /**
191
+ * Saves the post style metadata if on the post editing screen in the admin.
192
+ *
193
+ * @since 1.0.0
194
+ * @param int $post_id The ID of the current post being saved.
195
+ * @param object $post The post object currently being saved.
196
+ * @return void|int
197
+ */
198
+ public function save_post( $post_id, $post = '' ) {
199
+
200
+ if ( ! is_object( $post ) ) {
201
+ $post = get_post();
202
+ }
203
+
204
+ // Verify the nonce for the post formats meta box.
205
+ if ( ! isset( $_POST['cherry-sidebar-nonce'] )
206
+ || ! wp_verify_nonce( $_POST['cherry-sidebar-nonce'], basename( __FILE__ ) )
207
+ ) {
208
+ return $post_id;
209
+ }
210
+
211
+ // Get the meta key.
212
+ $meta_key = 'post_sidebar';
213
+
214
+ // Get the all submitted `page-sidebar-manager` data.
215
+ $sidebar_id = $_POST['theme_sidebar'];
216
+
217
+ update_post_meta( $post_id, $meta_key, $sidebar_id );
218
+ }
219
+
220
+ /**
221
+ * Function get post or page sidebar.
222
+ *
223
+ * @since 1.0.0
224
+ * @param int $post_id The ID of the current post being saved.
225
+ * @return string $post_sidebar Sidebar id value.
226
+ */
227
+ public function get_post_sidebar( $post_id ) {
228
+
229
+ // Get the $post_sidebar.
230
+ $post_sidebar = get_post_meta( $post_id, 'post_sidebar', true );
231
+
232
+ return $post_sidebar;
233
+ }
234
+
235
+ /**
236
+ * Returns the instance.
237
+ *
238
+ * @since 1.0.0
239
+ * @return object
240
+ */
241
+ public static function get_instance() {
242
+
243
+ // If the single instance hasn't been set, set it now.
244
+ if ( null == self::$instance ) {
245
+ self::$instance = new self;
246
+ }
247
+
248
+ return self::$instance;
249
+ }
250
+ }
251
+
252
+ Cherry_Custom_Sidebar::get_instance();
253
+ }
admin/includes/class-cherry-sidebars-admin.php CHANGED
@@ -1,146 +1,147 @@
1
- <?php
2
- /**
3
- * Sets up the admin functionality for the plugin.
4
- *
5
- * @package Cherry_Sidebars
6
- * @author Template Monster
7
- * @license GPL-3.0+
8
- * @copyright 2002-2016, Template Monster
9
- */
10
-
11
- // If this file is called directly, abort.
12
- if ( ! defined( 'WPINC' ) ) {
13
- die();
14
- }
15
-
16
- /**
17
- * Class for admin functionally.
18
- *
19
- * @since 1.0.0
20
- */
21
- class Cherry_Sidebars_Admin {
22
-
23
- /**
24
- * Holds the instances of this class.
25
- *
26
- * @since 1.0.0
27
- * @var object
28
- */
29
- private static $instance = null;
30
-
31
- /**
32
- * Sets up needed actions/filters for the admin to initialize.
33
- *
34
- * @since 1.0.0
35
- * @return void
36
- */
37
- public function __construct() {
38
-
39
- // Load admin javascript and stylesheet.
40
- add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_assets' ), 1 );
41
-
42
- add_action( 'after_setup_theme', array( $this, 'widgets_ajax_page' ) );
43
- add_action( 'sidebar_admin_setup', array( $this, 'registrates_custom_sidebar' ) );
44
- add_action( 'widgets_admin_page', array( $this, 'edit_wp_registered_sidebars' ) );
45
- add_action( 'sidebar_admin_page', array( $this, 'widgets_page' ) );
46
- }
47
-
48
- /**
49
- * Register and Enqueue admin-specific stylesheet and javascript.
50
- *
51
- * @since 1.0.0
52
- * @param string $hook_suffix Hook suffix.
53
- * @return void
54
- */
55
- public function add_admin_assets( $hook_suffix ) {
56
-
57
- if ( 'widgets.php' === $hook_suffix ) {
58
- wp_register_script( 'cherry_admin_sidebars_js', trailingslashit( CHERRY_SIDEBARS_URI ) . 'admin/assets/js/min/cherry-admin-sidebars.min.js', array( 'jquery' ), CHERRY_SIDEBARS_VERSION, true );
59
- wp_register_style( 'cherry_admin_sidebars_css', trailingslashit( CHERRY_SIDEBARS_URI ) . 'admin/assets/css/cherry-admin-sidebars.css', array(), CHERRY_SIDEBARS_VERSION, 'all' );
60
-
61
- wp_register_style( 'interface-builder', trailingslashit( CHERRY_SIDEBARS_URI ) . 'admin/assets/css/interface-builder.css', array(), CHERRY_SIDEBARS_VERSION, 'all' );
62
-
63
- $cherry_framework_object = array( 'ajax_nonce_new_sidebar' => wp_create_nonce( 'new_custom_sidebar' ) , 'ajax_nonce_remove_sidebar' => wp_create_nonce( 'remove_custom_sidebar' ) );
64
- wp_localize_script( 'cherry_admin_sidebars_js', 'cherryFramework', $cherry_framework_object );
65
-
66
- wp_enqueue_script( 'cherry_admin_sidebars_js' );
67
- wp_enqueue_style( 'cherry_admin_sidebars_css' );
68
- wp_enqueue_style( 'interface-builder' );
69
-
70
- } elseif ( false !== strpos( $hook_suffix, 'post' ) ) {
71
- wp_register_style( 'cherry-sidebars-post-page', trailingslashit( CHERRY_SIDEBARS_URI ) . 'admin/assets/css/cherry-sidebars-post-page.css', array(), CHERRY_SIDEBARS_VERSION, 'all' );
72
- wp_enqueue_style( 'cherry-sidebars-post-page' );
73
- }
74
- }
75
-
76
- /**
77
- * Returns the instance.
78
- *
79
- * @since 1.0.0
80
- */
81
- public function widgets_page() {
82
- require_once( trailingslashit( CHERRY_SIDEBARS_DIR ) . 'admin/views/cherry-widgets-page.php' );
83
- }
84
-
85
- /**
86
- * Registration new custom sidebars.
87
- *
88
- * @since 1.0.0
89
- * @return void
90
- */
91
- public function registrates_custom_sidebar() {
92
- global $wp_registered_sidebars;
93
-
94
- $instance = new Cherry_Sidebar_Utils();
95
- $sidebars_array = $instance->get_custom_sidebar_array();
96
- unset( $sidebars_array['cherry-sidebars-counter'] );
97
-
98
- $wp_registered_sidebars = array_merge( $wp_registered_sidebars, $sidebars_array );
99
- }
100
-
101
- /**
102
- * Editing registered sidebars.
103
- *
104
- * @since 1.0.0
105
- * @return void
106
- */
107
- public function edit_wp_registered_sidebars() {
108
- global $wp_registered_sidebars;
109
-
110
- $instance = new Cherry_Sidebar_Utils();
111
- $sidebars_array = $instance->get_custom_sidebar_array();
112
- unset( $sidebars_array['cherry-sidebars-counter'] );
113
- $sidebars_array_lengh = count( $sidebars_array );
114
-
115
- foreach ( $sidebars_array as $sidebar => $custom_sidebar ) {
116
- unset( $wp_registered_sidebars[ $sidebar ] );
117
- }
118
- }
119
-
120
- /**
121
- * Returns the instance.
122
- *
123
- * @since 1.0.0
124
- */
125
- public function widgets_ajax_page() {
126
- require_once( trailingslashit( CHERRY_SIDEBARS_DIR ) . 'admin/views/cherry-new-sidebar.php' );
127
- }
128
-
129
- /**
130
- * Returns the instance.
131
- *
132
- * @since 1.0.0
133
- * @return object
134
- */
135
- public static function get_instance() {
136
-
137
- // If the single instance hasn't been set, set it now.
138
- if ( null == self::$instance ) {
139
- self::$instance = new self;
140
- }
141
-
142
- return self::$instance;
143
- }
144
- }
145
-
146
- Cherry_Sidebars_Admin::get_instance();
 
1
+ <?php
2
+ /**
3
+ * Sets up the admin functionality for the plugin.
4
+ *
5
+ * @package Cherry_Sidebars
6
+ * @author Template Monster
7
+ * @license GPL-3.0+
8
+ * @copyright 2002-2016, Template Monster
9
+ */
10
+
11
+ // If this file is called directly, abort.
12
+ if ( ! defined( 'WPINC' ) ) {
13
+ die();
14
+ }
15
+
16
+ /**
17
+ * Class for admin functionally.
18
+ *
19
+ * @since 1.0.0
20
+ */
21
+ class Cherry_Sidebars_Admin {
22
+
23
+ /**
24
+ * Holds the instances of this class.
25
+ *
26
+ * @since 1.0.0
27
+ * @var object
28
+ */
29
+ private static $instance = null;
30
+
31
+ /**
32
+ * Sets up needed actions/filters for the admin to initialize.
33
+ *
34
+ * @since 1.0.0
35
+ * @return void
36
+ */
37
+ public function __construct() {
38
+
39
+ // Load admin javascript and stylesheet.
40
+ add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_assets' ), 1 );
41
+
42
+ add_action( 'after_setup_theme', array( $this, 'widgets_ajax_page' ), 10 );
43
+ add_action( 'sidebar_admin_setup', array( $this, 'registrates_custom_sidebar' ), 10 );
44
+ add_action( 'widgets_admin_page', array( $this, 'edit_wp_registered_sidebars' ), 10 );
45
+ add_action( 'sidebar_admin_page', array( $this, 'widgets_page' ), 10 );
46
+ }
47
+
48
+ /**
49
+ * Register and Enqueue admin-specific stylesheet and javascript.
50
+ *
51
+ * @since 1.0.0
52
+ * @param string $hook_suffix Hook suffix.
53
+ * @return void
54
+ */
55
+ public function add_admin_assets( $hook_suffix ) {
56
+
57
+ if ( 'widgets.php' === $hook_suffix ) {
58
+ wp_register_script( 'cherry_admin_sidebars_js', trailingslashit( CHERRY_SIDEBARS_URI ) . 'admin/assets/js/min/cherry-admin-sidebars.min.js', array( 'jquery' ), CHERRY_SIDEBARS_VERSION, true );
59
+ wp_register_style( 'cherry_admin_sidebars_css', trailingslashit( CHERRY_SIDEBARS_URI ) . 'admin/assets/css/cherry-admin-sidebars.css', array(), CHERRY_SIDEBARS_VERSION, 'all' );
60
+
61
+ wp_register_style( 'interface-builder', trailingslashit( CHERRY_SIDEBARS_URI ) . 'admin/assets/css/interface-builder.css', array(), CHERRY_SIDEBARS_VERSION, 'all' );
62
+
63
+ $cherry_framework_object = array( 'ajax_nonce_new_sidebar' => wp_create_nonce( 'new_custom_sidebar' ) , 'ajax_nonce_remove_sidebar' => wp_create_nonce( 'remove_custom_sidebar' ) );
64
+ wp_localize_script( 'cherry_admin_sidebars_js', 'cherryFramework', $cherry_framework_object );
65
+
66
+ wp_enqueue_script( 'cherry_admin_sidebars_js' );
67
+ wp_enqueue_style( 'cherry_admin_sidebars_css' );
68
+ wp_enqueue_style( 'interface-builder' );
69
+
70
+ } elseif ( false !== strpos( $hook_suffix, 'post' ) ) {
71
+ wp_register_style( 'cherry-sidebars-post-page', trailingslashit( CHERRY_SIDEBARS_URI ) . 'admin/assets/css/cherry-sidebars-post-page.css', array(), CHERRY_SIDEBARS_VERSION, 'all' );
72
+ wp_enqueue_style( 'cherry-sidebars-post-page' );
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Returns the instance.
78
+ *
79
+ * @since 1.0.0
80
+ */
81
+ public function widgets_page() {
82
+ cherry_sidebars()->init_modules();
83
+ require_once( trailingslashit( CHERRY_SIDEBARS_DIR ) . 'admin/views/cherry-widgets-page.php' );
84
+ }
85
+
86
+ /**
87
+ * Registration new custom sidebars.
88
+ *
89
+ * @since 1.0.0
90
+ * @return void
91
+ */
92
+ public function registrates_custom_sidebar() {
93
+ global $wp_registered_sidebars;
94
+
95
+ $instance = new Cherry_Sidebar_Utils();
96
+ $sidebars_array = $instance->get_custom_sidebar_array();
97
+ unset( $sidebars_array['cherry-sidebars-counter'] );
98
+
99
+ $wp_registered_sidebars = array_merge( $wp_registered_sidebars, $sidebars_array );
100
+ }
101
+
102
+ /**
103
+ * Editing registered sidebars.
104
+ *
105
+ * @since 1.0.0
106
+ * @return void
107
+ */
108
+ public function edit_wp_registered_sidebars() {
109
+ global $wp_registered_sidebars;
110
+
111
+ $instance = new Cherry_Sidebar_Utils();
112
+ $sidebars_array = $instance->get_custom_sidebar_array();
113
+ unset( $sidebars_array['cherry-sidebars-counter'] );
114
+ $sidebars_array_lengh = count( $sidebars_array );
115
+
116
+ foreach ( $sidebars_array as $sidebar => $custom_sidebar ) {
117
+ unset( $wp_registered_sidebars[ $sidebar ] );
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Returns the instance.
123
+ *
124
+ * @since 1.0.0
125
+ */
126
+ public function widgets_ajax_page() {
127
+ require_once( trailingslashit( CHERRY_SIDEBARS_DIR ) . 'admin/views/cherry-new-sidebar.php' );
128
+ }
129
+
130
+ /**
131
+ * Returns the instance.
132
+ *
133
+ * @since 1.0.0
134
+ * @return object
135
+ */
136
+ public static function get_instance() {
137
+
138
+ // If the single instance hasn't been set, set it now.
139
+ if ( null == self::$instance ) {
140
+ self::$instance = new self;
141
+ }
142
+
143
+ return self::$instance;
144
+ }
145
+ }
146
+
147
+ Cherry_Sidebars_Admin::get_instance();
cherry-sidebars.php CHANGED
@@ -1,245 +1,255 @@
1
- <?php
2
- /**
3
- * Plugin Name: Cherry Sidebars
4
- * Plugin URI:
5
- * Description: Plugin for creating and managing sidebars in WordPress.
6
- * Version: 1.0.0
7
- * Author: Template Monster
8
- * Author URI: http://www.templatemonster.com/
9
- * Text Domain: cherry-sidebars
10
- * License: GPL-3.0+
11
- * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
12
- * Domain Path: /languages
13
- *
14
- * @package Cherry_Sidebars
15
- * @author Template Monster
16
- * @license GPL-3.0+
17
- * @copyright 2002-2016, Template Monster
18
- */
19
-
20
- // If this file is called directly, abort.
21
- if ( ! defined( 'WPINC' ) ) {
22
- die;
23
- }
24
-
25
- // If class 'Cherry_Sidebars' not exists.
26
- if ( ! class_exists( 'Cherry_Sidebars' ) ) {
27
-
28
- /**
29
- * Sets up and initializes the Cherry Sidebars plugin.
30
- *
31
- * @since 1.0.0
32
- */
33
- class Cherry_Sidebars {
34
-
35
- /**
36
- * A reference to an instance of this class.
37
- *
38
- * @since 1.0.0
39
- * @var object
40
- */
41
- private static $instance = null;
42
-
43
- /**
44
- * A reference to an instance of cherry framework core class.
45
- *
46
- * @since 1.0.0
47
- * @var object
48
- */
49
- private $core = null;
50
-
51
- /**
52
- * Sets up needed actions/filters for the plugin to initialize.
53
- *
54
- * @since 1.0.0
55
- */
56
- public function __construct() {
57
-
58
- // Set the constants needed by the plugin.
59
- add_action( 'plugins_loaded', array( $this, 'constants' ), 0 );
60
-
61
- // Load the installer core.
62
- add_action( 'after_setup_theme', require( trailingslashit( __DIR__ ) . 'cherry-framework/setup.php' ), 0 );
63
-
64
- // Load the core functions/classes required by the rest of the theme.
65
- add_action( 'after_setup_theme', array( $this, 'get_core' ), 1 );
66
- add_action( 'after_setup_theme', array( 'Cherry_Core', 'load_all_modules' ), 2 );
67
- add_action( 'after_setup_theme', array( $this, 'init_modules' ), 3 );
68
-
69
- // Internationalize the text strings used.
70
- add_action( 'plugins_loaded', array( $this, 'lang' ), 3 );
71
-
72
- // Load the functions files.
73
- add_action( 'plugins_loaded', array( $this, 'includes' ), 4 );
74
-
75
- // Load the admin files.
76
- add_action( 'plugins_loaded', array( $this, 'admin' ), 5 );
77
-
78
- // Register activation and deactivation hook.
79
- register_activation_hook( __FILE__, array( $this, 'activation' ) );
80
- register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
81
- }
82
-
83
- /**
84
- * Defines constants for the plugin.
85
- *
86
- * @since 1.0.0
87
- */
88
- function constants() {
89
-
90
- if ( ! function_exists( 'get_plugin_data' ) ) {
91
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
92
- }
93
-
94
- $plugin_data = get_plugin_data( plugin_dir_path( __FILE__ ) . basename( __FILE__ ) );
95
-
96
- /**
97
- * Set constant name for the post type name.
98
- *
99
- * @since 1.0.0
100
- */
101
- define( 'CHERRY_SIDEBARS_SLUG', basename( dirname( __FILE__ ) ) );
102
-
103
- /**
104
- * Set the version number of the plugin.
105
- *
106
- * @since 1.0.0
107
- */
108
- define( 'CHERRY_SIDEBARS_VERSION', $plugin_data['Version'] );
109
-
110
- /**
111
- * Set constant path to the plugin directory.
112
- *
113
- * @since 1.0.0
114
- */
115
- define( 'CHERRY_SIDEBARS_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
116
-
117
- /**
118
- * Set constant path to the plugin URI.
119
- *
120
- * @since 1.0.0
121
- */
122
- define( 'CHERRY_SIDEBARS_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) );
123
- }
124
-
125
- /**
126
- * Loads files from the '/includes' folder.
127
- *
128
- * @since 1.0.0
129
- */
130
- function includes() {
131
- require_once( CHERRY_SIDEBARS_DIR . 'admin/includes/class-cherry-sidebar-utils.php' );
132
- require_once( CHERRY_SIDEBARS_DIR . 'admin/includes/class-cherry-sidebars-admin.php' );
133
- require_once( CHERRY_SIDEBARS_DIR . 'includes/class-cherry-include-sidebars.php' );
134
- }
135
-
136
- /**
137
- * Loads the translation files.
138
- *
139
- * @since 1.0.0
140
- */
141
- function lang() {
142
- load_plugin_textdomain( 'cherry-sidebars', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
143
- }
144
-
145
- /**
146
- * Loads admin files.
147
- *
148
- * @since 1.0.0
149
- */
150
- function admin() {
151
- if ( is_admin() ) {
152
- require_once( CHERRY_SIDEBARS_DIR . 'admin/includes/class-cherry-custom-sidebar.php' );
153
- }
154
- }
155
-
156
- /**
157
- * Loads the core functions. These files are needed before loading anything else in the
158
- * theme because they have required functions for use.
159
- *
160
- * @since 1.1.0
161
- */
162
- public function get_core() {
163
- /**
164
- * Fires before loads the core theme functions.
165
- *
166
- * @since 1.1.0
167
- */
168
- do_action( 'cherry_core_before' );
169
-
170
- if ( null !== $this->core ) {
171
- return $this->core;
172
- }
173
-
174
- if ( ! class_exists( 'Cherry_Core' ) ) {
175
- require_once( CHERRY_SIDEBARS_DIR . '/cherry-framework/cherry-core.php' );
176
- }
177
-
178
- $this->core = new Cherry_Core( array(
179
- 'base_dir' => CHERRY_SIDEBARS_DIR . 'cherry-framework',
180
- 'base_url' => CHERRY_SIDEBARS_URI . 'cherry-framework',
181
- 'modules' => array(
182
- 'cherry-js-core' => array(
183
- 'autoload' => false,
184
- ),
185
- 'cherry-ui-elements' => array(
186
- 'autoload' => false,
187
- ),
188
- ),
189
- ));
190
- }
191
-
192
- /**
193
- * Run initialization of modules.
194
- *
195
- * @since 1.2.0
196
- */
197
- public function init_modules() {
198
- if ( is_admin() ) {
199
- $this->get_core()->init_module( 'cherry-js-core' );
200
- $this->get_core()->init_module( 'cherry-ui-elements', array(
201
- 'ui_elements' => array(
202
- 'text',
203
- 'select',
204
- ),
205
- ) );
206
- }
207
- }
208
-
209
- /**
210
- * On plugin activation.
211
- *
212
- * @since 1.0.0
213
- */
214
- function activation() {
215
- flush_rewrite_rules();
216
- }
217
-
218
- /**
219
- * On plugin deactivation.
220
- *
221
- * @since 1.0.0
222
- */
223
- function deactivation() {
224
- flush_rewrite_rules();
225
- }
226
-
227
- /**
228
- * Returns the instance.
229
- *
230
- * @since 1.0.0
231
- * @return object
232
- */
233
- public static function get_instance() {
234
-
235
- // If the single instance hasn't been set, set it now.
236
- if ( null == self::$instance ) {
237
- self::$instance = new self;
238
- }
239
-
240
- return self::$instance;
241
- }
242
- }
243
-
244
- Cherry_Sidebars::get_instance();
245
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Cherry Sidebars
4
+ * Plugin URI: http://www.cherryframework.com/
5
+ * Description: Plugin for creating and managing sidebars in WordPress.
6
+ * Version: 1.0.2
7
+ * Author: Template Monster
8
+ * Author URI: http://www.templatemonster.com/
9
+ * Text Domain: cherry-sidebars
10
+ * License: GPL-3.0+
11
+ * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
12
+ * Domain Path: /languages
13
+ *
14
+ * @package Cherry_Sidebars
15
+ * @author Template Monster
16
+ * @license GPL-3.0+
17
+ * @copyright 2002-2016, Template Monster
18
+ */
19
+
20
+ // If this file is called directly, abort.
21
+ if ( ! defined( 'WPINC' ) ) {
22
+ die;
23
+ }
24
+
25
+ // If class 'Cherry_Sidebars' not exists.
26
+ if ( ! class_exists( 'Cherry_Sidebars' ) ) {
27
+
28
+ /**
29
+ * Sets up and initializes the Cherry Sidebars plugin.
30
+ *
31
+ * @since 1.0.0
32
+ */
33
+ class Cherry_Sidebars {
34
+
35
+ /**
36
+ * A reference to an instance of this class.
37
+ *
38
+ * @since 1.0.0
39
+ * @var object
40
+ */
41
+ private static $instance = null;
42
+
43
+ /**
44
+ * A reference to an instance of cherry framework core class.
45
+ *
46
+ * @since 1.0.0
47
+ * @var object
48
+ */
49
+ private $core = null;
50
+
51
+ /**
52
+ * Sets up needed actions/filters for the plugin to initialize.
53
+ *
54
+ * @since 1.0.0
55
+ */
56
+ public function __construct() {
57
+
58
+ // Set the constants needed by the plugin.
59
+ add_action( 'plugins_loaded', array( $this, 'constants' ), 0 );
60
+
61
+ // Load the installer core.
62
+ add_action( 'after_setup_theme', require( trailingslashit( __DIR__ ) . 'cherry-framework/setup.php' ), 0 );
63
+
64
+ // Load the core functions/classes required by the rest of the theme.
65
+ add_action( 'after_setup_theme', array( $this, 'get_core' ), 1 );
66
+ add_action( 'after_setup_theme', array( 'Cherry_Core', 'load_all_modules' ), 2 );
67
+
68
+ // Internationalize the text strings used.
69
+ add_action( 'plugins_loaded', array( $this, 'lang' ), 3 );
70
+
71
+ // Load the functions files.
72
+ add_action( 'plugins_loaded', array( $this, 'includes' ), 4 );
73
+
74
+ // Load the admin files.
75
+ add_action( 'plugins_loaded', array( $this, 'admin' ), 5 );
76
+
77
+ // Register activation and deactivation hook.
78
+ register_activation_hook( __FILE__, array( $this, 'activation' ) );
79
+ register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
80
+ }
81
+
82
+ /**
83
+ * Defines constants for the plugin.
84
+ *
85
+ * @since 1.0.0
86
+ */
87
+ function constants() {
88
+
89
+ if ( ! function_exists( 'get_plugin_data' ) ) {
90
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
91
+ }
92
+
93
+ $plugin_data = get_plugin_data( plugin_dir_path( __FILE__ ) . basename( __FILE__ ) );
94
+
95
+ /**
96
+ * Set constant name for the post type name.
97
+ *
98
+ * @since 1.0.0
99
+ */
100
+ define( 'CHERRY_SIDEBARS_SLUG', basename( dirname( __FILE__ ) ) );
101
+
102
+ /**
103
+ * Set the version number of the plugin.
104
+ *
105
+ * @since 1.0.0
106
+ */
107
+ define( 'CHERRY_SIDEBARS_VERSION', $plugin_data['Version'] );
108
+
109
+ /**
110
+ * Set constant path to the plugin directory.
111
+ *
112
+ * @since 1.0.0
113
+ */
114
+ define( 'CHERRY_SIDEBARS_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
115
+
116
+ /**
117
+ * Set constant path to the plugin URI.
118
+ *
119
+ * @since 1.0.0
120
+ */
121
+ define( 'CHERRY_SIDEBARS_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) );
122
+ }
123
+
124
+ /**
125
+ * Loads files from the '/includes' folder.
126
+ *
127
+ * @since 1.0.0
128
+ */
129
+ function includes() {
130
+ require_once( CHERRY_SIDEBARS_DIR . 'admin/includes/class-cherry-sidebar-utils.php' );
131
+ require_once( CHERRY_SIDEBARS_DIR . 'admin/includes/class-cherry-sidebars-admin.php' );
132
+ require_once( CHERRY_SIDEBARS_DIR . 'includes/class-cherry-include-sidebars.php' );
133
+ }
134
+
135
+ /**
136
+ * Loads the translation files.
137
+ *
138
+ * @since 1.0.0
139
+ */
140
+ function lang() {
141
+ load_plugin_textdomain( 'cherry-sidebars', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
142
+ }
143
+
144
+ /**
145
+ * Loads admin files.
146
+ *
147
+ * @since 1.0.0
148
+ */
149
+ function admin() {
150
+ if ( is_admin() ) {
151
+ require_once( CHERRY_SIDEBARS_DIR . 'admin/includes/class-cherry-custom-sidebar.php' );
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Loads the core functions. These files are needed before loading anything else in the
157
+ * theme because they have required functions for use.
158
+ *
159
+ * @since 1.1.0
160
+ */
161
+ public function get_core() {
162
+ /**
163
+ * Fires before loads the core theme functions.
164
+ *
165
+ * @since 1.1.0
166
+ */
167
+ do_action( 'cherry_core_before' );
168
+
169
+ if ( null !== $this->core ) {
170
+ return $this->core;
171
+ }
172
+
173
+ if ( ! class_exists( 'Cherry_Core' ) ) {
174
+ require_once( CHERRY_SIDEBARS_DIR . '/cherry-framework/cherry-core.php' );
175
+ }
176
+
177
+ $this->core = new Cherry_Core( array(
178
+ 'base_dir' => CHERRY_SIDEBARS_DIR . 'cherry-framework',
179
+ 'base_url' => CHERRY_SIDEBARS_URI . 'cherry-framework',
180
+ 'modules' => array(
181
+ 'cherry-js-core' => array(
182
+ 'autoload' => false,
183
+ ),
184
+ 'cherry-ui-elements' => array(
185
+ 'autoload' => false,
186
+ ),
187
+ ),
188
+ ));
189
+ }
190
+
191
+ /**
192
+ * Init modules.
193
+ *
194
+ * @since 1.0.0
195
+ */
196
+ function init_modules() {
197
+ cherry_sidebars()->get_core()->init_module( 'cherry-js-core' );
198
+ cherry_sidebars()->get_core()->init_module( 'cherry-ui-elements', array(
199
+ 'ui_elements' => array(
200
+ 'text',
201
+ 'select',
202
+ ),
203
+ ) );
204
+ }
205
+
206
+ /**
207
+ * On plugin activation.
208
+ *
209
+ * @since 1.0.0
210
+ */
211
+ function activation() {
212
+ flush_rewrite_rules();
213
+ }
214
+
215
+ /**
216
+ * On plugin deactivation.
217
+ *
218
+ * @since 1.0.0
219
+ */
220
+ function deactivation() {
221
+ flush_rewrite_rules();
222
+ }
223
+
224
+ /**
225
+ * Returns the instance.
226
+ *
227
+ * @since 1.0.0
228
+ * @return object
229
+ */
230
+ public static function get_instance() {
231
+
232
+ // If the single instance hasn't been set, set it now.
233
+ if ( null == self::$instance ) {
234
+ self::$instance = new self;
235
+ }
236
+
237
+ return self::$instance;
238
+ }
239
+ }
240
+ }
241
+
242
+ if ( ! function_exists( 'cherry_sidebars' ) ) {
243
+
244
+ /**
245
+ * Returns instanse of the plugin class.
246
+ *
247
+ * @since 1.0.0
248
+ * @return object
249
+ */
250
+ function cherry_sidebars() {
251
+ return Cherry_Sidebars::get_instance();
252
+ }
253
+ }
254
+
255
+ cherry_sidebars();
includes/class-cherry-include-sidebars.php CHANGED
@@ -1,93 +1,97 @@
1
- <?php
2
- /**
3
- * Class for including custom sidebars.
4
- *
5
- * @package Cherry_Sidebars
6
- * @author Template Monster
7
- * @license GPL-3.0+
8
- * @copyright 2002-2016, Template Monster
9
- */
10
-
11
- if ( ! class_exists( 'Cherry_Include_Sidebars' ) ) {
12
-
13
- /**
14
- * Class for including custom sidebars.
15
- *
16
- * @since 1.0.0
17
- */
18
- class Cherry_Include_Sidebars {
19
-
20
- /**
21
- * Holds the instances of this class.
22
- *
23
- * @since 1.0.0
24
- * @var object
25
- */
26
- private static $instance = null;
27
-
28
- /**
29
- * Sets up our actions/filters.
30
- *
31
- * @since 1.0.0
32
- * @return void
33
- */
34
- public function __construct() {
35
- add_filter( 'sidebars_widgets', array( $this, 'set_custom_sidebar' ), 10, 1 );
36
- }
37
-
38
- /**
39
- * Set custom sidebar in global array $wp_registered_sidebars.
40
- *
41
- * @since 1.0.0
42
- * @param array $widgets Sidebar widgets.
43
- * @return array
44
- */
45
- public function set_custom_sidebar( $widgets ) {
46
- global $wp_registered_sidebars;
47
-
48
- $object_id = get_queried_object_id();
49
-
50
- if ( function_exists( 'is_shop' ) ) {
51
- if ( is_shop() || is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
52
- $object_id = wc_get_page_id( 'shop' );
53
- }
54
- }
55
-
56
- $post_sidebars = get_post_meta( apply_filters( 'cherry_sidebar_manager_object_id', $object_id ), 'post_sidebar', true );
57
-
58
- if ( $post_sidebars && ! empty( $post_sidebars ) ) {
59
-
60
- $instance = new Cherry_Sidebar_Utils();
61
- $custom_sidebar = $instance->get_custom_sidebar_array();
62
-
63
- foreach ( $post_sidebars as $sidebar => $sidebar_value ) {
64
- if ( ! empty( $sidebar_value ) &&
65
- ( array_key_exists( $sidebar_value, $wp_registered_sidebars ) || array_key_exists( $sidebar_value, $custom_sidebar ) ) &&
66
- isset( $widgets[ $sidebar ] ) ) {
67
- $widgets[ $sidebar ] = $widgets[ $sidebar_value ];
68
- }
69
- }
70
- }
71
-
72
- return $widgets;
73
- }
74
-
75
- /**
76
- * Returns the instance.
77
- *
78
- * @since 1.0.0
79
- * @return object
80
- */
81
- public static function get_instance() {
82
-
83
- // If the single instance hasn't been set, set it now.
84
- if ( null == self::$instance ) {
85
- self::$instance = new self;
86
- }
87
-
88
- return self::$instance;
89
- }
90
- }
91
-
92
- Cherry_Include_Sidebars::get_instance();
93
- }
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class for including custom sidebars.
4
+ *
5
+ * @package Cherry_Sidebars
6
+ * @author Template Monster
7
+ * @license GPL-3.0+
8
+ * @copyright 2002-2016, Template Monster
9
+ */
10
+
11
+ if ( ! class_exists( 'Cherry_Include_Sidebars' ) ) {
12
+
13
+ /**
14
+ * Class for including custom sidebars.
15
+ *
16
+ * @since 1.0.0
17
+ */
18
+ class Cherry_Include_Sidebars {
19
+
20
+ /**
21
+ * Holds the instances of this class.
22
+ *
23
+ * @since 1.0.0
24
+ * @var object
25
+ */
26
+ private static $instance = null;
27
+
28
+ /**
29
+ * Sets up our actions/filters.
30
+ *
31
+ * @since 1.0.0
32
+ * @return void
33
+ */
34
+ public function __construct() {
35
+ add_filter( 'sidebars_widgets', array( $this, 'set_custom_sidebar' ), 10, 1 );
36
+ }
37
+
38
+ /**
39
+ * Set custom sidebar in global array $wp_registered_sidebars.
40
+ *
41
+ * @since 1.0.0
42
+ * @param array $widgets Sidebar widgets.
43
+ * @return array
44
+ */
45
+ public function set_custom_sidebar( $widgets ) {
46
+ global $wp_registered_sidebars, $wp_query;
47
+
48
+ if ( ! is_object( $wp_query ) ) {
49
+ return $widgets;
50
+ }
51
+
52
+ $object_id = get_queried_object_id();
53
+
54
+ if ( function_exists( 'is_shop' ) ) {
55
+ if ( is_shop() || is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
56
+ $object_id = wc_get_page_id( 'shop' );
57
+ }
58
+ }
59
+
60
+ $post_sidebars = get_post_meta( apply_filters( 'cherry_sidebar_manager_object_id', $object_id ), 'post_sidebar', true );
61
+
62
+ if ( $post_sidebars && ! empty( $post_sidebars ) ) {
63
+
64
+ $instance = new Cherry_Sidebar_Utils();
65
+ $custom_sidebar = $instance->get_custom_sidebar_array();
66
+
67
+ foreach ( $post_sidebars as $sidebar => $sidebar_value ) {
68
+ if ( ! empty( $sidebar_value ) &&
69
+ ( array_key_exists( $sidebar_value, $wp_registered_sidebars ) || array_key_exists( $sidebar_value, $custom_sidebar ) ) &&
70
+ isset( $widgets[ $sidebar ] ) ) {
71
+ $widgets[ $sidebar ] = $widgets[ $sidebar_value ];
72
+ }
73
+ }
74
+ }
75
+
76
+ return $widgets;
77
+ }
78
+
79
+ /**
80
+ * Returns the instance.
81
+ *
82
+ * @since 1.0.0
83
+ * @return object
84
+ */
85
+ public static function get_instance() {
86
+
87
+ // If the single instance hasn't been set, set it now.
88
+ if ( null == self::$instance ) {
89
+ self::$instance = new self;
90
+ }
91
+
92
+ return self::$instance;
93
+ }
94
+ }
95
+
96
+ Cherry_Include_Sidebars::get_instance();
97
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: TemplateMonster 2002
4
  Tags: sidebar, sidebar manager, cherry framework, custom sidebars, widget area, group widgets, page custom sidebar, post custom sidebar
5
  Requires at least: 4.4
6
  Tested up to: 4.5.3
7
- Stable tag: 1.0
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -42,6 +42,10 @@ The plugin can be useful for certain posts or pages, where you want your content
42
 
43
  == Changelog ==
44
 
 
 
 
 
45
  = 1.0.0 =
46
 
47
- * Initial release
4
  Tags: sidebar, sidebar manager, cherry framework, custom sidebars, widget area, group widgets, page custom sidebar, post custom sidebar
5
  Requires at least: 4.4
6
  Tested up to: 4.5.3
7
+ Stable tag: 1.0.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
42
 
43
  == Changelog ==
44
 
45
+ = 1.0.2 =
46
+ * FIX: custom sidebars option name
47
+ * FIX: WooCommerce Ajax Navigation: sidebars_widgets filter should check WP_Query
48
+
49
  = 1.0.0 =
50
 
51
+ * Initial release