Content Aware Sidebars – Unlimited Widget Areas - Version 3.15

Version Description

  • [new] toolbar menu to view conditions, theme areas, and sidebars for a given page
  • [new] better compatibility with retired custom sidebars plugin
  • [updated] ui improvements
  • [updated] wp-content-aware-engine library
Download this release

Release Info

Developer intoxstudio
Plugin Icon 128x128 Content Aware Sidebars – Unlimited Widget Areas
Version 3.15
Comparing to
See all releases

Code changes from version 3.14.1 to 3.15

admin/admin.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -18,6 +18,11 @@ abstract class CAS_Admin
18
  */
19
  protected $_screen;
20
 
 
 
 
 
 
21
  public function __construct()
22
  {
23
  if (is_admin()) {
@@ -121,11 +126,11 @@ abstract class CAS_Admin
121
  */
122
  public function add_general_scripts_styles()
123
  {
124
- $this->enqueue_script('cas/admin/general', 'general', array('jquery'), '', true);
125
- wp_localize_script('cas/admin/general', 'CAS', array(
126
  'showPopups' => !cas_fs()->can_use_premium_code(),
127
  'enableConfirm' => __('This sidebar is already scheduled to be activated. Do you want to activate it now?', 'content-aware-sidebars')
128
- ));
129
  $this->enqueue_style('cas/admin/style', 'style');
130
  $this->add_scripts_styles();
131
  }
@@ -148,10 +153,11 @@ abstract class CAS_Admin
148
  $tour_manager = new WP_Pointer_Tour(CAS_App::META_PREFIX.'cas_tour');
149
  $tour_taken = (int) $tour_manager->get_user_option();
150
  if ($tour_taken && (time() - $tour_taken) >= WEEK_IN_SECONDS) {
 
151
  $path = plugin_dir_path(dirname(__FILE__)).'view/';
152
- $view = WPCAView::make($path.'notice_review.php', array(
153
  'current_user' => wp_get_current_user()
154
- ))->render();
155
  }
156
  }
157
 
@@ -182,7 +188,7 @@ abstract class CAS_Admin
182
  {
183
  __('Enhance your sidebars and widget areas with: %s and more.', 'content-aware-sidebars');
184
  __('Sync widgets across themes', 'content-aware-sidebars');
185
- $features = array(
186
  __('Extra Display Conditions', 'content-aware-sidebars'),
187
  __('Insert Widget Areas in Theme Hooks', 'content-aware-sidebars'),
188
  __('Widget Area Designer', 'content-aware-sidebars'),
@@ -191,7 +197,7 @@ abstract class CAS_Admin
191
  __('Time & Weekday Schedule', 'content-aware-sidebars'),
192
  __('Widget Cleaner', 'content-aware-sidebars'),
193
  __('and so much more...', 'content-aware-sidebars')
194
- );
195
  echo '<a style="display:none;" class="thickbox js-cas-pro-popup" href="#TB_inline?width=600&amp;height=350&amp;inlineId=pro-popup-notice" title="'.__('Content Aware Sidebars Pro', 'content-aware-sidebars').'"></a>';
196
  echo '<div id="pro-popup-notice" style="display:none;">';
197
  echo '<img style="margin-top:15px;" class="alignright" src="'.plugins_url('assets/img/icon.png', dirname(__FILE__)).'" width="128" height="128" />';
@@ -204,7 +210,7 @@ abstract class CAS_Admin
204
  echo '</ul>';
205
  echo '<p>'.__('You can upgrade without leaving the admin panel by clicking below.', 'content-aware-sidebars');
206
  echo '<br />'.__('Free updates and email support included.', 'content-aware-sidebars').'</p>';
207
- echo '<p><a class="button-primary" target="_blank" href="'.esc_url(cas_fs()->get_upgrade_url()).'">'.__('Upgrade Now', 'content-aware-sidebars').'</a> <a href="" class="button-secondary js-cas-pro-read-more" target="_blank" href="">'.__('Read More', 'content-aware-sidebars').'</a></p>';
208
  echo '</div>';
209
  }
210
 
@@ -220,7 +226,7 @@ abstract class CAS_Admin
220
  protected function add_action($tag, $callback, $priority = 10, $accepted_args = 1)
221
  {
222
  if (is_string($callback)) {
223
- $callback = array($this, $callback);
224
  }
225
  add_action($tag, $callback, $priority, $accepted_args);
226
  }
@@ -237,7 +243,7 @@ abstract class CAS_Admin
237
  protected function add_filter($tag, $callback, $priority = 10, $accepted_args = 1)
238
  {
239
  if (is_string($callback)) {
240
- $callback = array($this, $callback);
241
  }
242
  add_filter($tag, $callback, $priority, $accepted_args);
243
  }
@@ -252,7 +258,7 @@ abstract class CAS_Admin
252
  *
253
  * @return void
254
  */
255
- protected function enqueue_script($handle, $filename, $deps = array(), $ver = '', $in_footer = false)
256
  {
257
  $this->register_script($handle, $filename, $deps, $ver, $in_footer);
258
  wp_enqueue_script($handle);
@@ -268,7 +274,7 @@ abstract class CAS_Admin
268
  *
269
  * @return void
270
  */
271
- protected function register_script($handle, $filename, $deps = array(), $ver = '', $in_footer = false)
272
  {
273
  $suffix = '.min.js';
274
  if ($ver === '') {
@@ -286,7 +292,7 @@ abstract class CAS_Admin
286
  *
287
  * @return void
288
  */
289
- protected function enqueue_style($handle, $filename, $deps = array(), $ver = '')
290
  {
291
  $this->register_style($handle, $filename, $deps, $ver);
292
  wp_enqueue_style($handle);
@@ -301,7 +307,7 @@ abstract class CAS_Admin
301
  *
302
  * @return void
303
  */
304
- protected function register_style($handle, $filename, $deps = array(), $ver = '')
305
  {
306
  $suffix = '.css';
307
  if ($ver === '') {
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
18
  */
19
  protected $_screen;
20
 
21
+ /**
22
+ * @var int
23
+ */
24
+ protected $notification_count = 0;
25
+
26
  public function __construct()
27
  {
28
  if (is_admin()) {
126
  */
127
  public function add_general_scripts_styles()
128
  {
129
+ $this->enqueue_script('cas/admin/general', 'general', ['jquery'], '', true);
130
+ wp_localize_script('cas/admin/general', 'CAS', [
131
  'showPopups' => !cas_fs()->can_use_premium_code(),
132
  'enableConfirm' => __('This sidebar is already scheduled to be activated. Do you want to activate it now?', 'content-aware-sidebars')
133
+ ]);
134
  $this->enqueue_style('cas/admin/style', 'style');
135
  $this->add_scripts_styles();
136
  }
153
  $tour_manager = new WP_Pointer_Tour(CAS_App::META_PREFIX.'cas_tour');
154
  $tour_taken = (int) $tour_manager->get_user_option();
155
  if ($tour_taken && (time() - $tour_taken) >= WEEK_IN_SECONDS) {
156
+ $this->notification_count++;
157
  $path = plugin_dir_path(dirname(__FILE__)).'view/';
158
+ $view = WPCAView::make($path.'notice_review.php', [
159
  'current_user' => wp_get_current_user()
160
+ ])->render();
161
  }
162
  }
163
 
188
  {
189
  __('Enhance your sidebars and widget areas with: %s and more.', 'content-aware-sidebars');
190
  __('Sync widgets across themes', 'content-aware-sidebars');
191
+ $features = [
192
  __('Extra Display Conditions', 'content-aware-sidebars'),
193
  __('Insert Widget Areas in Theme Hooks', 'content-aware-sidebars'),
194
  __('Widget Area Designer', 'content-aware-sidebars'),
197
  __('Time & Weekday Schedule', 'content-aware-sidebars'),
198
  __('Widget Cleaner', 'content-aware-sidebars'),
199
  __('and so much more...', 'content-aware-sidebars')
200
+ ];
201
  echo '<a style="display:none;" class="thickbox js-cas-pro-popup" href="#TB_inline?width=600&amp;height=350&amp;inlineId=pro-popup-notice" title="'.__('Content Aware Sidebars Pro', 'content-aware-sidebars').'"></a>';
202
  echo '<div id="pro-popup-notice" style="display:none;">';
203
  echo '<img style="margin-top:15px;" class="alignright" src="'.plugins_url('assets/img/icon.png', dirname(__FILE__)).'" width="128" height="128" />';
210
  echo '</ul>';
211
  echo '<p>'.__('You can upgrade without leaving the admin panel by clicking below.', 'content-aware-sidebars');
212
  echo '<br />'.__('Free updates and email support included.', 'content-aware-sidebars').'</p>';
213
+ echo '<p><a class="button-primary" target="_blank" href="'.esc_url(cas_fs()->get_upgrade_url()).'">'.__('Upgrade Now', 'content-aware-sidebars').'</a> <a href="" class="button-secondary js-cas-pro-read-more" target="_blank" rel="noopener" href="">'.__('Read More', 'content-aware-sidebars').'</a></p>';
214
  echo '</div>';
215
  }
216
 
226
  protected function add_action($tag, $callback, $priority = 10, $accepted_args = 1)
227
  {
228
  if (is_string($callback)) {
229
+ $callback = [$this, $callback];
230
  }
231
  add_action($tag, $callback, $priority, $accepted_args);
232
  }
243
  protected function add_filter($tag, $callback, $priority = 10, $accepted_args = 1)
244
  {
245
  if (is_string($callback)) {
246
+ $callback = [$this, $callback];
247
  }
248
  add_filter($tag, $callback, $priority, $accepted_args);
249
  }
258
  *
259
  * @return void
260
  */
261
+ protected function enqueue_script($handle, $filename, $deps = [], $ver = '', $in_footer = false)
262
  {
263
  $this->register_script($handle, $filename, $deps, $ver, $in_footer);
264
  wp_enqueue_script($handle);
274
  *
275
  * @return void
276
  */
277
+ protected function register_script($handle, $filename, $deps = [], $ver = '', $in_footer = false)
278
  {
279
  $suffix = '.min.js';
280
  if ($ver === '') {
292
  *
293
  * @return void
294
  */
295
+ protected function enqueue_style($handle, $filename, $deps = [], $ver = '')
296
  {
297
  $this->register_style($handle, $filename, $deps, $ver);
298
  wp_enqueue_style($handle);
307
  *
308
  * @return void
309
  */
310
+ protected function register_style($handle, $filename, $deps = [], $ver = '')
311
  {
312
  $suffix = '.css';
313
  if ($ver === '') {
admin/admin_bar.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Content Aware Sidebars
4
+ * @author Joachim Jensen <joachim@dev.institute>
5
+ * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
+ */
8
+
9
+ defined('ABSPATH') || exit;
10
+
11
+ class CAS_Admin_Bar
12
+ {
13
+ const NODE_ROOT = 'wpcas-tool';
14
+ const NODE_THEME_AREAS = 'theme-areas';
15
+ const NODE_CONDITION_TYPES = 'condition-types';
16
+ const NODE_CUSTOM_SIDEBARS = 'custom-sidebars';
17
+
18
+ const DOCS_MAP = [
19
+ 'author' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/authors/',
20
+ 'bb_profile' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/bbpress-user-profiles/',
21
+ 'bp_member' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/buddypress-profiles/',
22
+ 'bp_group' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/buddypress-groups/',
23
+ 'date' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/dates/',
24
+ 'language' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/languages/',
25
+ 'page_template' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/page-templates/',
26
+ 'taxonomy' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/taxonomies/',
27
+ 'pods' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/pods-pages/',
28
+ 'post_type' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/post-types/',
29
+ 'url' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/urls/',
30
+ 'referrer' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/urls/',
31
+ 'static' => 'https://dev.institute/docs/content-aware-sidebars/sidebar-conditions/static-pages/',
32
+ ];
33
+
34
+ /**
35
+ * @var array
36
+ */
37
+ private $theme_sidebars = [];
38
+
39
+ /**
40
+ * @var array
41
+ */
42
+ private $custom_sidebars = [];
43
+
44
+ public function __construct()
45
+ {
46
+ add_action('admin_bar_init', [$this,'initiate']);
47
+ }
48
+
49
+ public function initiate()
50
+ {
51
+ $post_type_object = get_post_type_object(CAS_App::TYPE_SIDEBAR);
52
+ if (is_admin() || !current_user_can($post_type_object->cap->create_posts)) {
53
+ return;
54
+ }
55
+
56
+ add_filter('is_active_sidebar', [$this,'detect_sidebars_via_active'], 10, 2);
57
+ add_action('dynamic_sidebar_before', [$this,'detect_sidebars_via_render'], 10, 2);
58
+ add_action('admin_bar_menu', [$this,'add_menu'], 99);
59
+ add_action('wp_head', [$this,'print_styles']);
60
+ }
61
+
62
+ public function print_styles()
63
+ {
64
+ echo '<style type="text/css" media="screen">'."\n"; ?>
65
+ #wp-admin-bar-wpcas-tool #wp-admin-bar-wpcas-tool-custom-sidebars {
66
+ border-top:4px solid #75d7ef;
67
+ }
68
+ #wp-admin-bar-wpcas-tool .dashicons-welcome-widgets-menus {
69
+ top:2px;
70
+ margin:0!important;
71
+ }
72
+ #wp-admin-bar-wpcas-tool #wp-admin-bar-wpcas-tool-condition-types .ab-icon {
73
+ float:right!important;
74
+ margin-right:0!important;
75
+ font-size:14px!important;
76
+ }
77
+ <?php
78
+ echo '</style>';
79
+ }
80
+
81
+ /**
82
+ * @param WP_Admin_Bar $admin_bar
83
+ * @param array $args
84
+ * @param string $parent
85
+ * @return self
86
+ */
87
+ private function add_node($admin_bar, $args, $parent = null)
88
+ {
89
+ if ($args['id'] !== self::NODE_ROOT) {
90
+ $args['parent'] = self::NODE_ROOT . (!is_null($parent) ? '-'.$parent : '');
91
+ $args['id'] = $args['parent'].'-'.$args['id'];
92
+ }
93
+ $admin_bar->add_node($args);
94
+
95
+ return $this;
96
+ }
97
+
98
+ /**
99
+ * @param WP_Admin_Bar $admin_bar
100
+ * @return void
101
+ */
102
+ public function add_menu($admin_bar)
103
+ {
104
+ global $wp_registered_sidebars;
105
+
106
+ $post_type_object = get_post_type_object(CAS_App::TYPE_SIDEBAR);
107
+
108
+ $this
109
+ ->add_node($admin_bar, [
110
+ 'id' => self::NODE_ROOT,
111
+ 'title' => '<span class="ab-icon dashicons '.$post_type_object->menu_icon.'"></span>',
112
+ 'href' => admin_url('admin.php?page=wpcas'),
113
+ 'meta' => [
114
+ 'title' => __('Content Aware Sidebars', 'content-aware-sidebars')
115
+ ]
116
+ ])
117
+ ->add_node($admin_bar, [
118
+ 'id' => 'add_new',
119
+ 'title' => $post_type_object->labels->add_new,
120
+ 'href' => admin_url('admin.php?page=wpcas-edit'),
121
+ ])
122
+ ->add_node($admin_bar, [
123
+ 'id' => self::NODE_CONDITION_TYPES,
124
+ 'title' => __('Condition Types', 'content-aware-sidebars'),
125
+ ])
126
+ ->add_node($admin_bar, [
127
+ 'id' => self::NODE_THEME_AREAS,
128
+ 'title' => __('Theme Areas', 'content-aware-sidebars')
129
+ ]);
130
+
131
+ $args = [];
132
+ foreach (WPCACore::get_conditional_modules('sidebar') as $module) {
133
+ $title = $module->get_name();
134
+ $link = '';
135
+ if (isset(self::DOCS_MAP[$module->get_id()])) {
136
+ $title .= ' <span class="ab-icon dashicons dashicons-external"></span>';
137
+ $link = self::DOCS_MAP[$module->get_id()].'?utm_source=plugin&amp;utm_medium=admin_bar&amp;utm_campaign=cas';
138
+ }
139
+ $args[] = [
140
+ 'id' => $module->get_id(),
141
+ 'title' => $title,
142
+ 'href' => $link,
143
+ 'meta' => [
144
+ 'target' => '_blank',
145
+ 'rel' => 'noopener'
146
+ ]
147
+ ];
148
+ }
149
+ $this->add_nodes($admin_bar, $args, self::NODE_CONDITION_TYPES);
150
+
151
+ $args = [];
152
+ foreach ($this->theme_sidebars as $index => $has_widgets) {
153
+ $args[] = [
154
+ 'id' => $index,
155
+ 'title' => $wp_registered_sidebars[$index]['name'] . ($has_widgets ? '' : ' ('.__('Hidden').')'),
156
+ ];
157
+ }
158
+ $this->add_nodes($admin_bar, $args, self::NODE_THEME_AREAS);
159
+
160
+ $admin_bar->add_group([
161
+ 'id' => self::NODE_ROOT.'-'.self::NODE_CUSTOM_SIDEBARS,
162
+ 'parent' => self::NODE_ROOT,
163
+ 'meta' => [
164
+ 'class' => 'ab-sub-secondary'
165
+ ]
166
+ ]);
167
+
168
+ $args = [];
169
+ foreach ($this->custom_sidebars as $id => $has_widgets) {
170
+ $sidebar = CAS_App::instance()->_manager->sidebars[$id];
171
+ $args[] = [
172
+ 'id' => $sidebar->ID,
173
+ 'title' => $sidebar->post_title,
174
+ 'href' => get_edit_post_link($sidebar->ID)
175
+ ];
176
+ }
177
+ $this->add_nodes($admin_bar, $args, self::NODE_CUSTOM_SIDEBARS);
178
+
179
+ if (empty($this->custom_sidebars)) {
180
+ $args = [
181
+ 'id' => 'no_custom_sidebars',
182
+ 'title' => $post_type_object->labels->not_found
183
+ ];
184
+ $this->add_node($admin_bar, $args, self::NODE_CUSTOM_SIDEBARS);
185
+ }
186
+
187
+ //@todo: show custom sidebars that were not displayed on page
188
+ }
189
+
190
+ /**
191
+ * @param bool $has_widgets
192
+ * @param string $index
193
+ * @return bool
194
+ */
195
+ public function detect_sidebars_via_active($has_widgets, $index)
196
+ {
197
+ $this->detect_sidebar($has_widgets, $index);
198
+ return $has_widgets;
199
+ }
200
+
201
+ /**
202
+ * @param string $index
203
+ * @param bool $has_widgets
204
+ * @return void
205
+ */
206
+ public function detect_sidebars_via_render($index, $has_widgets)
207
+ {
208
+ $this->detect_sidebar($has_widgets, $index);
209
+ }
210
+
211
+ /**
212
+ * @param WP_Admin_Bar $admin_bar
213
+ * @param array $nodes
214
+ * @param string|null $parent
215
+ * @return void
216
+ */
217
+ private function add_nodes($admin_bar, $nodes, $parent = null)
218
+ {
219
+ usort($nodes, [$this,'sort_nodes']);
220
+ foreach ($nodes as $node_args) {
221
+ $this->add_node($admin_bar, $node_args, $parent);
222
+ }
223
+ }
224
+
225
+ /**
226
+ * @param string $a
227
+ * @param string $b
228
+ * @return int
229
+ */
230
+ private function sort_nodes($a, $b)
231
+ {
232
+ return strcasecmp($a['title'], $b['title']);
233
+ }
234
+
235
+ /**
236
+ * @param bool $has_widgets
237
+ * @param string $index
238
+ * @return void
239
+ */
240
+ private function detect_sidebar($has_widgets, $index)
241
+ {
242
+ if (str_replace(CAS_App::SIDEBAR_PREFIX, '', $index) === $index) {
243
+ $this->theme_sidebars[$index] = $has_widgets;
244
+ } else {
245
+ $this->custom_sidebars[$index] = $has_widgets;
246
+ }
247
+ }
248
+ }
admin/db-updates.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -16,26 +16,26 @@ $cas_db_updater->register_version_update('3.1', 'cas_update_to_31');
16
  $cas_db_updater->register_version_update('3.4', 'cas_update_to_34');
17
  $cas_db_updater->register_version_update('3.5.1', 'cas_update_to_351');
18
  $cas_db_updater->register_version_update('3.8', 'cas_update_to_38');
19
- $cas_db_updater->register_version_update('3.14', 'cas_update_to_314');
20
 
21
  /**
22
  * Enable legacy date module and
23
  * negated conditions if in use
24
  *
25
- * @since 3.14
26
  *
27
  * @return bool
28
  */
29
- function cas_update_to_314()
30
  {
31
  global $wpdb;
32
 
33
  $types = WPCACore::types()->get_all();
34
 
35
- $options = array(
36
- 'legacy.date_module' => array(),
37
- 'legacy.negated_conditions' => array()
38
- );
39
 
40
  $options['legacy.date_module'] = array_flip((array)$wpdb->get_col("
41
  SELECT p.post_type FROM $wpdb->posts p
@@ -182,11 +182,11 @@ function cas_update_to_30()
182
  global $wpdb;
183
 
184
  // Get all sidebars
185
- $posts = get_posts(array(
186
  'numberposts' => -1,
187
  'post_type' => 'sidebar',
188
  'post_status' => 'publish,pending,draft,future,private,trash'
189
- ));
190
 
191
  if (!empty($posts)) {
192
  $wpdb->query("
@@ -195,7 +195,7 @@ function cas_update_to_30()
195
  WHERE post_type = 'sidebar_group'
196
  ");
197
 
198
- $metadata = array(
199
  'post_types' => 'post_type',
200
  'taxonomies' => 'taxonomy',
201
  'authors' => 'author',
@@ -209,7 +209,7 @@ function cas_update_to_30()
209
  'handle' => 'handle',
210
  'host' => 'host',
211
  'merge-pos' => 'merge_pos'
212
- );
213
 
214
  foreach ($metadata as $old_key => $new_key) {
215
  $wpdb->query("
@@ -258,7 +258,7 @@ function cas_update_to_20()
258
  {
259
  global $wpdb;
260
 
261
- $module_keys = array(
262
  'static',
263
  'post_types',
264
  'authors',
@@ -267,24 +267,24 @@ function cas_update_to_20()
267
  'language',
268
  'bb_profile',
269
  'bp_member'
270
- );
271
 
272
  // Get all sidebars
273
- $posts = get_posts(array(
274
  'numberposts' => -1,
275
  'post_type' => 'sidebar',
276
  'post_status' => 'publish,pending,draft,future,private,trash'
277
- ));
278
  if (!empty($posts)) {
279
  foreach ($posts as $post) {
280
 
281
  //Create new condition group
282
- $group_id = wp_insert_post(array(
283
  'post_status' => $post->post_status,
284
  'post_type' => 'sidebar_group',
285
  'post_author' => $post->post_author,
286
  'post_parent' => $post->ID,
287
- ));
288
 
289
  if ($group_id) {
290
 
@@ -317,21 +317,21 @@ function cas_update_to_20()
317
  */
318
  function cas_update_to_11()
319
  {
320
- $moduledata = array(
321
  'static',
322
  'post_types',
323
  'authors',
324
  'page_templates',
325
  'taxonomies',
326
  'language'
327
- );
328
 
329
  // Get all sidebars
330
- $posts = get_posts(array(
331
  'numberposts' => -1,
332
  'post_type' => 'sidebar',
333
  'post_status' => 'publish,pending,draft,future,private,trash'
334
- ));
335
 
336
  if (!empty($posts)) {
337
  foreach ($posts as $post) {
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
16
  $cas_db_updater->register_version_update('3.4', 'cas_update_to_34');
17
  $cas_db_updater->register_version_update('3.5.1', 'cas_update_to_351');
18
  $cas_db_updater->register_version_update('3.8', 'cas_update_to_38');
19
+ $cas_db_updater->register_version_update('3.15', 'cas_update_to_315');
20
 
21
  /**
22
  * Enable legacy date module and
23
  * negated conditions if in use
24
  *
25
+ * @since 3.15
26
  *
27
  * @return bool
28
  */
29
+ function cas_update_to_315()
30
  {
31
  global $wpdb;
32
 
33
  $types = WPCACore::types()->get_all();
34
 
35
+ $options = [
36
+ 'legacy.date_module' => [],
37
+ 'legacy.negated_conditions' => []
38
+ ];
39
 
40
  $options['legacy.date_module'] = array_flip((array)$wpdb->get_col("
41
  SELECT p.post_type FROM $wpdb->posts p
182
  global $wpdb;
183
 
184
  // Get all sidebars
185
+ $posts = get_posts([
186
  'numberposts' => -1,
187
  'post_type' => 'sidebar',
188
  'post_status' => 'publish,pending,draft,future,private,trash'
189
+ ]);
190
 
191
  if (!empty($posts)) {
192
  $wpdb->query("
195
  WHERE post_type = 'sidebar_group'
196
  ");
197
 
198
+ $metadata = [
199
  'post_types' => 'post_type',
200
  'taxonomies' => 'taxonomy',
201
  'authors' => 'author',
209
  'handle' => 'handle',
210
  'host' => 'host',
211
  'merge-pos' => 'merge_pos'
212
+ ];
213
 
214
  foreach ($metadata as $old_key => $new_key) {
215
  $wpdb->query("
258
  {
259
  global $wpdb;
260
 
261
+ $module_keys = [
262
  'static',
263
  'post_types',
264
  'authors',
267
  'language',
268
  'bb_profile',
269
  'bp_member'
270
+ ];
271
 
272
  // Get all sidebars
273
+ $posts = get_posts([
274
  'numberposts' => -1,
275
  'post_type' => 'sidebar',
276
  'post_status' => 'publish,pending,draft,future,private,trash'
277
+ ]);
278
  if (!empty($posts)) {
279
  foreach ($posts as $post) {
280
 
281
  //Create new condition group
282
+ $group_id = wp_insert_post([
283
  'post_status' => $post->post_status,
284
  'post_type' => 'sidebar_group',
285
  'post_author' => $post->post_author,
286
  'post_parent' => $post->ID,
287
+ ]);
288
 
289
  if ($group_id) {
290
 
317
  */
318
  function cas_update_to_11()
319
  {
320
+ $moduledata = [
321
  'static',
322
  'post_types',
323
  'authors',
324
  'page_templates',
325
  'taxonomies',
326
  'language'
327
+ ];
328
 
329
  // Get all sidebars
330
+ $posts = get_posts([
331
  'numberposts' => -1,
332
  'post_type' => 'sidebar',
333
  'post_status' => 'publish,pending,draft,future,private,trash'
334
+ ]);
335
 
336
  if (!empty($posts)) {
337
  foreach ($posts as $post) {
admin/quick_select.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -13,14 +13,14 @@ class CAS_Quick_Select
13
  const MODULE_NAME = 'post_type';
14
  const NONCE = '_cas_nonce';
15
 
16
- protected static $_theme_sidebars = array();
17
 
18
  public function __construct()
19
  {
20
  new CAS_Post_Type_Sidebar();
21
  add_action(
22
  'current_screen',
23
- array(__CLASS__,'load_screen')
24
  );
25
  }
26
 
@@ -40,7 +40,7 @@ class CAS_Quick_Select
40
  return;
41
  }
42
 
43
- $legacy_removal = !has_action('admin_init', array('CAS_Post_Type_Sidebar','initiate'));
44
 
45
  if ($legacy_removal) {
46
  _deprecated_hook(
@@ -65,22 +65,22 @@ class CAS_Quick_Select
65
  if (isset($post_types[$screen->post_type]) && self::$_theme_sidebars) {
66
  add_action(
67
  'add_meta_boxes_'.$screen->post_type,
68
- array(__CLASS__,'create_meta_boxes')
69
  );
70
  add_action(
71
  'save_post_'.$screen->post_type,
72
- array(__CLASS__,'save_post_sidebars'),
73
  10,
74
  2
75
  );
76
  add_action(
77
  'admin_enqueue_scripts',
78
- array(__CLASS__,'register_scripts'),
79
  8
80
  );
81
  add_action(
82
  'admin_enqueue_scripts',
83
- array(__CLASS__,'enqueue_scripts'),
84
  11
85
  );
86
  }
@@ -101,10 +101,10 @@ class CAS_Quick_Select
101
 
102
  foreach ($wp_registered_sidebars as $sidebar) {
103
  if (!isset($cas_sidebars[$sidebar['id']])) {
104
- self::$_theme_sidebars[$sidebar['id']] = array(
105
  'label' => $sidebar['name'],
106
- 'options' => array()
107
- );
108
  }
109
  }
110
  }
@@ -143,7 +143,7 @@ class CAS_Quick_Select
143
  }
144
 
145
  $meta_key = WPCACore::PREFIX . self::MODULE_NAME;
146
- $new = isset($_POST['cas_sidebars']) ? $_POST['cas_sidebars'] : array();
147
 
148
  $relations = self::_get_content_sidebars($post);
149
  $user_can_create_sidebar = current_user_can(CAS_App::CAPABILITY);
@@ -161,11 +161,11 @@ class CAS_Quick_Select
161
  //check permissions here
162
  if ($sidebar_id[0] == '_') {
163
  if ($user_can_create_sidebar) {
164
- $id = wp_insert_post(array(
165
  'post_title' => str_replace('__', ',', substr($sidebar_id, 1)),
166
  'post_status' => CAS_App::STATUS_INACTIVE,
167
  'post_type' => CAS_App::TYPE_SIDEBAR
168
- ));
169
  if ($id) {
170
  //wp_insert_post does not handle meta before WP4.4
171
  add_post_meta($id, WPCACore::PREFIX.'host', $host);
@@ -175,7 +175,7 @@ class CAS_Quick_Select
175
  } else {
176
  //Add post to group with other posts
177
  $id = intval($sidebar_id);
178
- $condition_groups = get_posts(array(
179
  'posts_per_page' => 1,
180
  'meta_key' => $meta_key,
181
  'meta_value' => $post->post_type,
@@ -183,7 +183,7 @@ class CAS_Quick_Select
183
  'post_parent' => $id,
184
  'post_type' => WPCACore::TYPE_CONDITION_GROUP,
185
  'post_status' => WPCACore::STATUS_PUBLISHED
186
- ));
187
  if ($condition_groups) {
188
  $condition_group_id = $condition_groups[0]->ID;
189
  } else {
@@ -245,10 +245,10 @@ class CAS_Quick_Select
245
  $host_ids = $host_meta->get_data($sidebar->ID, false, false);
246
  foreach ($host_ids as $host_id) {
247
  if (isset(self::$_theme_sidebars[$host_id])) {
248
- self::$_theme_sidebars[$host_id]['options'][$sidebar->ID] = array(
249
  'id' => $sidebar->ID,
250
  'text' => $sidebar->post_title.self::sidebar_states($sidebar)
251
- );
252
  if (isset($post_sidebars[$sidebar->ID])) {
253
  self::$_theme_sidebars[$host_id]['options'][$sidebar->ID]['select'] = 1;
254
  }
@@ -257,9 +257,9 @@ class CAS_Quick_Select
257
  }
258
 
259
  $post_type = get_post_type_object($post->post_type);
260
- $content = array(
261
  __('Author')
262
- );
263
  if ($post_type->hierarchical) {
264
  $content[] = __('Child Page', 'content-aware-sidebars');
265
  }
@@ -275,19 +275,19 @@ class CAS_Quick_Select
275
  $content[] = __('Archive Page', 'content-aware-sidebars');
276
 
277
  $path = plugin_dir_path(dirname(__FILE__)).'view/';
278
- $view = WPCAView::make($path.'sidebars_quick_select.php', array(
279
  'post' => $post,
280
  'sidebars' => self::$_theme_sidebars,
281
  'limit' => 3,
282
  'content' => $content,
283
  'singular' => $post_type->labels->singular_name,
284
  'nonce' => wp_nonce_field(self::NONCE.$post->ID, self::NONCE, false, false)
285
- ));
286
 
287
  add_meta_box(
288
  'cas-content-sidebars',
289
  __('Sidebars - Quick Select', 'content-aware-sidebars'),
290
- array($view, 'render'),
291
  $post->post_type,
292
  'side',
293
  'default'
@@ -330,11 +330,11 @@ class CAS_Quick_Select
330
  wp_register_script(
331
  'select2',
332
  plugins_url('lib/wp-content-aware-engine/assets/js/select2.min.js', dirname(__FILE__)),
333
- array('jquery'),
334
  '4.0.3',
335
  false
336
  );
337
- wp_register_script('cas/sidebars/suggest', plugins_url('assets/js/suggest-sidebars.min.js', dirname(__FILE__)), array('select2'), CAS_App::PLUGIN_VERSION, true);
338
  }
339
 
340
  /**
@@ -350,10 +350,10 @@ class CAS_Quick_Select
350
  wp_enqueue_style(CAS_App::META_PREFIX.'condition-groups');
351
  wp_enqueue_script('cas/sidebars/suggest');
352
 
353
- $labels = array(
354
  'createNew' => __('Create New', 'content-aware-sidebars'),
355
  'labelNew' => __('New', 'content-aware-sidebars')
356
- );
357
  if (current_user_can(CAS_App::CAPABILITY)) {
358
  $labels['notFound'] = __('Type to Add New Sidebar', 'content-aware-sidebars');
359
  } else {
@@ -369,10 +369,10 @@ class CAS_Quick_Select
369
  */
370
  protected static function get_special_post_ids()
371
  {
372
- $special_post_ids = array(
373
  get_option('page_on_front'),
374
  get_option('page_for_posts'),
375
- );
376
 
377
  if (defined('WC_VERSION')) {
378
  $special_post_ids[] = get_option('woocommerce_shop_page_id');
@@ -390,7 +390,7 @@ class CAS_Quick_Select
390
  */
391
  protected static function _get_content_sidebars($post)
392
  {
393
- $sidebars = array();
394
  if ($post) {
395
  global $wpdb;
396
  $query = $wpdb->get_results($wpdb->prepare(
@@ -426,7 +426,7 @@ class CAS_Post_Type_Sidebar
426
  {
427
  public function __construct()
428
  {
429
- add_action('admin_init', array(__CLASS__,'initiate'));
430
  }
431
 
432
  public static function initiate()
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
13
  const MODULE_NAME = 'post_type';
14
  const NONCE = '_cas_nonce';
15
 
16
+ protected static $_theme_sidebars = [];
17
 
18
  public function __construct()
19
  {
20
  new CAS_Post_Type_Sidebar();
21
  add_action(
22
  'current_screen',
23
+ [__CLASS__,'load_screen']
24
  );
25
  }
26
 
40
  return;
41
  }
42
 
43
+ $legacy_removal = !has_action('admin_init', ['CAS_Post_Type_Sidebar','initiate']);
44
 
45
  if ($legacy_removal) {
46
  _deprecated_hook(
65
  if (isset($post_types[$screen->post_type]) && self::$_theme_sidebars) {
66
  add_action(
67
  'add_meta_boxes_'.$screen->post_type,
68
+ [__CLASS__,'create_meta_boxes']
69
  );
70
  add_action(
71
  'save_post_'.$screen->post_type,
72
+ [__CLASS__,'save_post_sidebars'],
73
  10,
74
  2
75
  );
76
  add_action(
77
  'admin_enqueue_scripts',
78
+ [__CLASS__,'register_scripts'],
79
  8
80
  );
81
  add_action(
82
  'admin_enqueue_scripts',
83
+ [__CLASS__,'enqueue_scripts'],
84
  11
85
  );
86
  }
101
 
102
  foreach ($wp_registered_sidebars as $sidebar) {
103
  if (!isset($cas_sidebars[$sidebar['id']])) {
104
+ self::$_theme_sidebars[$sidebar['id']] = [
105
  'label' => $sidebar['name'],
106
+ 'options' => []
107
+ ];
108
  }
109
  }
110
  }
143
  }
144
 
145
  $meta_key = WPCACore::PREFIX . self::MODULE_NAME;
146
+ $new = isset($_POST['cas_sidebars']) ? $_POST['cas_sidebars'] : [];
147
 
148
  $relations = self::_get_content_sidebars($post);
149
  $user_can_create_sidebar = current_user_can(CAS_App::CAPABILITY);
161
  //check permissions here
162
  if ($sidebar_id[0] == '_') {
163
  if ($user_can_create_sidebar) {
164
+ $id = wp_insert_post([
165
  'post_title' => str_replace('__', ',', substr($sidebar_id, 1)),
166
  'post_status' => CAS_App::STATUS_INACTIVE,
167
  'post_type' => CAS_App::TYPE_SIDEBAR
168
+ ]);
169
  if ($id) {
170
  //wp_insert_post does not handle meta before WP4.4
171
  add_post_meta($id, WPCACore::PREFIX.'host', $host);
175
  } else {
176
  //Add post to group with other posts
177
  $id = intval($sidebar_id);
178
+ $condition_groups = get_posts([
179
  'posts_per_page' => 1,
180
  'meta_key' => $meta_key,
181
  'meta_value' => $post->post_type,
183
  'post_parent' => $id,
184
  'post_type' => WPCACore::TYPE_CONDITION_GROUP,
185
  'post_status' => WPCACore::STATUS_PUBLISHED
186
+ ]);
187
  if ($condition_groups) {
188
  $condition_group_id = $condition_groups[0]->ID;
189
  } else {
245
  $host_ids = $host_meta->get_data($sidebar->ID, false, false);
246
  foreach ($host_ids as $host_id) {
247
  if (isset(self::$_theme_sidebars[$host_id])) {
248
+ self::$_theme_sidebars[$host_id]['options'][$sidebar->ID] = [
249
  'id' => $sidebar->ID,
250
  'text' => $sidebar->post_title.self::sidebar_states($sidebar)
251
+ ];
252
  if (isset($post_sidebars[$sidebar->ID])) {
253
  self::$_theme_sidebars[$host_id]['options'][$sidebar->ID]['select'] = 1;
254
  }
257
  }
258
 
259
  $post_type = get_post_type_object($post->post_type);
260
+ $content = [
261
  __('Author')
262
+ ];
263
  if ($post_type->hierarchical) {
264
  $content[] = __('Child Page', 'content-aware-sidebars');
265
  }
275
  $content[] = __('Archive Page', 'content-aware-sidebars');
276
 
277
  $path = plugin_dir_path(dirname(__FILE__)).'view/';
278
+ $view = WPCAView::make($path.'sidebars_quick_select.php', [
279
  'post' => $post,
280
  'sidebars' => self::$_theme_sidebars,
281
  'limit' => 3,
282
  'content' => $content,
283
  'singular' => $post_type->labels->singular_name,
284
  'nonce' => wp_nonce_field(self::NONCE.$post->ID, self::NONCE, false, false)
285
+ ]);
286
 
287
  add_meta_box(
288
  'cas-content-sidebars',
289
  __('Sidebars - Quick Select', 'content-aware-sidebars'),
290
+ [$view, 'render'],
291
  $post->post_type,
292
  'side',
293
  'default'
330
  wp_register_script(
331
  'select2',
332
  plugins_url('lib/wp-content-aware-engine/assets/js/select2.min.js', dirname(__FILE__)),
333
+ ['jquery'],
334
  '4.0.3',
335
  false
336
  );
337
+ wp_register_script('cas/sidebars/suggest', plugins_url('assets/js/suggest-sidebars.min.js', dirname(__FILE__)), ['select2'], CAS_App::PLUGIN_VERSION, true);
338
  }
339
 
340
  /**
350
  wp_enqueue_style(CAS_App::META_PREFIX.'condition-groups');
351
  wp_enqueue_script('cas/sidebars/suggest');
352
 
353
+ $labels = [
354
  'createNew' => __('Create New', 'content-aware-sidebars'),
355
  'labelNew' => __('New', 'content-aware-sidebars')
356
+ ];
357
  if (current_user_can(CAS_App::CAPABILITY)) {
358
  $labels['notFound'] = __('Type to Add New Sidebar', 'content-aware-sidebars');
359
  } else {
369
  */
370
  protected static function get_special_post_ids()
371
  {
372
+ $special_post_ids = [
373
  get_option('page_on_front'),
374
  get_option('page_for_posts'),
375
+ ];
376
 
377
  if (defined('WC_VERSION')) {
378
  $special_post_ids[] = get_option('woocommerce_shop_page_id');
390
  */
391
  protected static function _get_content_sidebars($post)
392
  {
393
+ $sidebars = [];
394
  if ($post) {
395
  global $wpdb;
396
  $query = $wpdb->get_results($wpdb->prepare(
426
  {
427
  public function __construct()
428
  {
429
+ add_action('admin_init', [__CLASS__,'initiate']);
430
  }
431
 
432
  public static function initiate()
admin/screen_widgets.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -49,12 +49,12 @@ class CAS_Admin_Screen_Widgets extends CAS_Admin
49
  $manager = CAS_App::instance()->manager();
50
  $manager->populate_metadata();
51
 
52
- $has_host = array(0 => 1,1 => 1,3 => 1);
53
 
54
  foreach ($manager->sidebars as $id => $post) {
55
  $handle_meta = $manager->metadata()->get('handle');
56
 
57
- $args = array();
58
  $args['description'] = $handle_meta->get_list_data($post->ID, true);
59
 
60
  if (isset($has_host[$handle_meta->get_data($post->ID)])) {
@@ -111,20 +111,20 @@ class CAS_Admin_Screen_Widgets extends CAS_Admin
111
  wp_send_json_error('401 Unauthorized');
112
  }
113
 
114
- $data = array();
115
  $status = filter_var($_POST['status'], FILTER_VALIDATE_BOOLEAN);
116
  if ($status) {
117
- $data = array(
118
  'ID' => $sidebar_id,
119
  'post_status' => CAS_App::STATUS_ACTIVE,
120
  'post_date' => current_time('mysql'),
121
  'post_date_gmt' => current_time('mysql', true)
122
- );
123
  } else {
124
- $data = array(
125
  'ID' => $sidebar_id,
126
  'post_status' => CAS_App::STATUS_INACTIVE
127
- );
128
  }
129
 
130
  if (!wp_update_post($data)) {
@@ -206,13 +206,13 @@ class CAS_Admin_Screen_Widgets extends CAS_Admin
206
  */
207
  public function add_scripts_styles()
208
  {
209
- $this->enqueue_script('cas/admin/widgets', 'widgets', array('jquery'), '', true);
210
- wp_localize_script('cas/admin/widgets', 'CASAdmin', array(
211
  'addNew' => $this->get_sidebar_type()->labels->add_new_item,
212
  'collapse' => __('Collapse', 'content-aware-sidebars'),
213
  'expand' => __('Expand', 'content-aware-sidebars'),
214
  'filterSidebars' => __('Search Sidebars', 'content-aware-sidebars'),
215
  'filterWidgets' => __('Search Widgets', 'content-aware-sidebars')
216
- ));
217
  }
218
  }
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
49
  $manager = CAS_App::instance()->manager();
50
  $manager->populate_metadata();
51
 
52
+ $has_host = [0 => 1,1 => 1,3 => 1];
53
 
54
  foreach ($manager->sidebars as $id => $post) {
55
  $handle_meta = $manager->metadata()->get('handle');
56
 
57
+ $args = [];
58
  $args['description'] = $handle_meta->get_list_data($post->ID, true);
59
 
60
  if (isset($has_host[$handle_meta->get_data($post->ID)])) {
111
  wp_send_json_error('401 Unauthorized');
112
  }
113
 
114
+ $data = [];
115
  $status = filter_var($_POST['status'], FILTER_VALIDATE_BOOLEAN);
116
  if ($status) {
117
+ $data = [
118
  'ID' => $sidebar_id,
119
  'post_status' => CAS_App::STATUS_ACTIVE,
120
  'post_date' => current_time('mysql'),
121
  'post_date_gmt' => current_time('mysql', true)
122
+ ];
123
  } else {
124
+ $data = [
125
  'ID' => $sidebar_id,
126
  'post_status' => CAS_App::STATUS_INACTIVE
127
+ ];
128
  }
129
 
130
  if (!wp_update_post($data)) {
206
  */
207
  public function add_scripts_styles()
208
  {
209
+ $this->enqueue_script('cas/admin/widgets', 'widgets', ['jquery'], '', true);
210
+ wp_localize_script('cas/admin/widgets', 'CASAdmin', [
211
  'addNew' => $this->get_sidebar_type()->labels->add_new_item,
212
  'collapse' => __('Collapse', 'content-aware-sidebars'),
213
  'expand' => __('Expand', 'content-aware-sidebars'),
214
  'filterSidebars' => __('Search Sidebars', 'content-aware-sidebars'),
215
  'filterWidgets' => __('Search Widgets', 'content-aware-sidebars')
216
+ ]);
217
  }
218
  }
admin/sidebar-edit.php CHANGED
@@ -1,1068 +1,1017 @@
1
- <?php
2
- /**
3
- * @package Content Aware Sidebars
4
- * @author Joachim Jensen <joachim@dev.institute>
5
- * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
- */
8
-
9
- defined('ABSPATH') || exit;
10
-
11
- final class CAS_Sidebar_Edit extends CAS_Admin
12
- {
13
-
14
- /**
15
- * Intro tour manager
16
- * @var WP_Pointer_Tour
17
- */
18
- private $_tour_manager;
19
-
20
- /**
21
- * Add filters and actions for admin dashboard
22
- * e.g. AJAX calls
23
- *
24
- * @since 3.5
25
- * @return void
26
- */
27
- public function admin_hooks()
28
- {
29
- $this->_tour_manager = new WP_Pointer_Tour(CAS_App::META_PREFIX.'cas_tour');
30
-
31
- $this->add_action('delete_post', 'remove_sidebar_widgets');
32
- $this->add_action('save_post_'.CAS_App::TYPE_SIDEBAR, 'save_post', 10, 2);
33
-
34
- $this->add_filter('wp_insert_post_data', 'add_duplicate_title_suffix', 99, 2);
35
- $this->add_filter('get_edit_post_link', 'get_edit_post_link', 10, 3);
36
- $this->add_filter('get_delete_post_link', 'get_delete_post_link', 10, 3);
37
-
38
- if (!cas_fs()->can_use_premium_code()) {
39
- $this->add_action('wpca/modules/init', 'add_modules');
40
- }
41
- }
42
-
43
- /**
44
- * Set up admin menu and get current screen
45
- *
46
- * @since 3.4
47
- * @return string
48
- */
49
- public function get_screen()
50
- {
51
- $post_type_object = $this->get_sidebar_type();
52
- return add_submenu_page(
53
- CAS_App::BASE_SCREEN,
54
- $post_type_object->labels->add_new_item,
55
- $post_type_object->labels->add_new,
56
- $post_type_object->cap->edit_posts,
57
- CAS_App::BASE_SCREEN.'-edit',
58
- array($this,'render_screen')
59
- );
60
- }
61
-
62
- /**
63
- * @since 3.5
64
- *
65
- * @return bool
66
- */
67
- public function authorize_user()
68
- {
69
- return true;
70
- }
71
-
72
- /**
73
- * @since 3.4
74
- *
75
- * @return void
76
- */
77
- public function prepare_screen()
78
- {
79
- $this->add_action('cas/admin/add_meta_boxes', 'create_meta_boxes');
80
-
81
- global $post, $title, $active_post_lock;
82
-
83
- $post_type = CAS_App::TYPE_SIDEBAR;
84
- $post_type_object = $this->get_sidebar_type();
85
- $post_id = isset($_REQUEST['sidebar_id']) ? $_REQUEST['sidebar_id'] : 0;
86
-
87
- /**
88
- * Edit mode
89
- */
90
- if ($post_id) {
91
- $this->process_actions($post_id);
92
-
93
- $post = get_post($post_id, OBJECT, 'edit');
94
-
95
- if (! $post) {
96
- wp_die(__('The sidebar no longer exists.'));
97
- }
98
- if (! current_user_can($post_type_object->cap->edit_post, $post_id)) {
99
- wp_die(__('You are not allowed to edit this sidebar.'));
100
- }
101
- if ('trash' == $post->post_status) {
102
- wp_die(__('You cannot edit this sidebar because it is in the Trash. Please restore it and try again.'));
103
- }
104
-
105
- if (! empty($_GET['get-post-lock'])) {
106
- check_admin_referer('lock-post_' . $post_id);
107
- wp_set_post_lock($post_id);
108
- wp_redirect(get_edit_post_link($post_id, 'url'));
109
- exit();
110
- }
111
-
112
- if (! wp_check_post_lock($post->ID)) {
113
- $active_post_lock = wp_set_post_lock($post->ID);
114
- }
115
-
116
- $title = $post_type_object->labels->edit_item;
117
-
118
- /**
119
- * New Mode
120
- */
121
- } else {
122
- if (! (current_user_can($post_type_object->cap->edit_posts) || current_user_can($post_type_object->cap->create_posts))) {
123
- wp_die(
124
- '<p>' . __('You are not allowed to create sidebars.', 'content-aware-sidebars') . '</p>',
125
- 403
126
- );
127
- }
128
-
129
- $post = get_default_post_to_edit($post_type, true);
130
-
131
- $title = $post_type_object->labels->add_new_item;
132
- }
133
-
134
- do_action('cas/admin/add_meta_boxes', $post);
135
- }
136
-
137
- /**
138
- * @since 3.9
139
- * @param WPCATypeManager $types
140
- *
141
- * @return void
142
- */
143
- public function add_modules($types)
144
- {
145
- if (!$types->has(CAS_App::TYPE_SIDEBAR)) {
146
- return;
147
- }
148
-
149
- $pro_label = '(Pro)';
150
- $type = $types->get(CAS_App::TYPE_SIDEBAR);
151
- $path = plugin_dir_path(dirname(__FILE__));
152
-
153
- require($path.'conditions/placeholder.php');
154
-
155
- $module = new CASConditionPlaceholder('cas_url', __('URLs', 'content-aware-sidebars').' '.$pro_label);
156
- $type->add($module, 'cas_url');
157
-
158
- if (function_exists('bp_is_active')) {
159
- $module = new CASConditionPlaceholder('cas_bbp', __('BuddyPress Groups', 'content-aware-sidebars').' '.$pro_label, '', '', 'plugins');
160
- $type->add($module, 'cas_bbp');
161
- }
162
-
163
- if (defined('ACF')) {
164
- $module = new CASConditionPlaceholder('cas_acf', __('Advanced Custom Fields', 'content-aware-sidebars').' '.$pro_label, '', '', 'plugins');
165
- $type->add($module, 'cas_acf');
166
- }
167
- }
168
-
169
- /**
170
- * Process actions
171
- *
172
- * @since 3.4
173
- * @param int $post_id
174
- * @return void
175
- */
176
- public function process_actions($post_id)
177
- {
178
- $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
179
- if (isset($_POST['deletepost'])) {
180
- $action = 'delete';
181
- }
182
-
183
- if ($action && $post_id) {
184
- //wp_reset_vars( array( 'action' ) );
185
- $sendback = wp_get_referer();
186
- $sendback = remove_query_arg(
187
- array('action','trashed', 'untrashed', 'deleted', 'ids'),
188
- $sendback
189
- );
190
- if (isset($_REQUEST['_cas_section']) && $_REQUEST['_cas_section']) {
191
- $sendback .= $_REQUEST['_cas_section'];
192
- }
193
-
194
- $post = get_post($post_id);
195
- if (! $post) {
196
- wp_die(__('The sidebar no longer exists.', 'content-aware-sidebars'));
197
- }
198
-
199
- check_admin_referer($action . '-post_' . $post_id);
200
-
201
- switch ($action) {
202
- case 'update':
203
-
204
- $post_id = $this->update_sidebar_type();
205
-
206
- // Session cookie flag that the post was saved
207
- if (isset($_COOKIE['wp-saving-post']) && $_COOKIE['wp-saving-post'] === $post_id . '-check') {
208
- setcookie('wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl());
209
- }
210
-
211
- $status = get_post_status($post_id);
212
- if (isset($_POST['original_post_status']) && $_POST['original_post_status'] == $status) {
213
- $message = 1;
214
- } else {
215
- switch ($status) {
216
- case CAS_App::STATUS_SCHEDULED:
217
- //gets scheduled
218
- $message = 9;
219
- break;
220
- case CAS_App::STATUS_INACTIVE:
221
- //gets deactivated
222
- $message = 10;
223
- break;
224
- case CAS_App::STATUS_ACTIVE:
225
- //gets activated
226
- $message = 6;
227
- break;
228
- default:
229
- $message = 1;
230
- }
231
- }
232
-
233
- $sendback = add_query_arg(array(
234
- 'sidebar_id' => $post_id,
235
- 'message' => $message,
236
- 'page' => 'wpcas-edit'
237
- ), $sendback);
238
- wp_safe_redirect($sendback);
239
- exit();
240
- case 'trash':
241
-
242
- if (! current_user_can('delete_post', $post_id)) {
243
- wp_die(__('You are not allowed to move this sidebar to the Trash.', 'content-aware-sidebars'));
244
- }
245
-
246
- if ($user_id = wp_check_post_lock($post_id)) {
247
- $user = get_userdata($user_id);
248
- wp_die(sprintf(__('You cannot move this sidebar to the Trash. %s is currently editing.', 'content-aware-sidebars'), $user->display_name));
249
- }
250
-
251
- if (! wp_trash_post($post_id)) {
252
- wp_die(__('Error in moving to Trash.'));
253
- }
254
-
255
- $sendback = remove_query_arg('sidebar_id', $sendback);
256
-
257
- wp_safe_redirect(add_query_arg(
258
- array(
259
- 'page' => 'wpcas',
260
- 'trashed' => 1,
261
- 'ids' => $post_id
262
- ),
263
- $sendback
264
- ));
265
- exit();
266
- case 'untrash':
267
-
268
- if (! current_user_can('delete_post', $post_id)) {
269
- wp_die(__('You are not allowed to restore this sidebar from the Trash.', 'content-aware-sidebars'));
270
- }
271
-
272
- if (! wp_untrash_post($post_id)) {
273
- wp_die(__('Error in restoring from Trash.'));
274
- }
275
-
276
- wp_safe_redirect(add_query_arg('untrashed', 1, $sendback));
277
- exit();
278
- case 'delete':
279
-
280
- if (! current_user_can('delete_post', $post_id)) {
281
- wp_die(__('You are not allowed to delete this sidebar.', 'content-aware-sidebars'));
282
- }
283
-
284
- if (! wp_delete_post($post_id, true)) {
285
- wp_die(__('Error in deleting.'));
286
- }
287
-
288
- $sendback = remove_query_arg('sidebar_id', $sendback);
289
- wp_safe_redirect(add_query_arg(array(
290
- 'page' => 'wpcas',
291
- 'deleted' => 1
292
- ), $sendback));
293
- exit();
294
- default:
295
- do_action('cas/admin/action', $action, $post);
296
- break;
297
- }
298
- }
299
- }
300
-
301
- /**
302
- * Render screen
303
- *
304
- * @since 3.4
305
- * @return void
306
- */
307
- public function render_screen()
308
- {
309
- global $post, $active_post_lock;
310
-
311
- $post_type_object = get_post_type_object($post->post_type);
312
-
313
- $post_id = isset($_REQUEST['sidebar_id']) ? $_REQUEST['sidebar_id'] : 0;
314
-
315
- $notice = false;
316
- $form_extra = '';
317
- if ('auto-draft' == $post->post_status) {
318
- if (isset($_REQUEST['sidebar_id'])) {
319
- $post->post_title = '';
320
- }
321
- $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
322
- }
323
-
324
- if ($post_id) {
325
- $title = __('Edit');
326
- } else {
327
- $title = $post_type_object->labels->new_item;
328
- }
329
-
330
- echo '<div class="wrap">';
331
- echo '<h1>';
332
- echo '<a href="'.admin_url('admin.php?page=wpcas').'">'.$post_type_object->labels->all_items.'</a> &raquo; ';
333
- echo esc_html($title);
334
- if (isset($_REQUEST['sidebar_id'])) {
335
- if (current_user_can('edit_theme_options')) {
336
- echo ' <a href="' . esc_url(admin_url('widgets.php#'.CAS_App::SIDEBAR_PREFIX.$post->ID)) . '" class="page-title-action add-new-h2">' . __('Manage Widgets', 'content-aware-sidebars') . '</a>';
337
- }
338
- }
339
-
340
- echo '</h1>';
341
-
342
- $this->sidebar_updated_messages($post);
343
-
344
- echo '<form name="post" action="admin.php?page=wpcas-edit" method="post" id="post">';
345
- $referer = wp_get_referer();
346
- wp_nonce_field('update-post_' . $post->ID);
347
- echo '<input type="hidden" id="user-id" name="user_ID" value="'.(int)get_current_user_id().'" />';
348
- echo '<input type="hidden" id="_cas_section" name="_cas_section" value="" />';
349
- echo '<input type="hidden" id="hiddenaction" name="action" value="update" />';
350
- echo '<input type="hidden" id="post_author" name="post_author" value="'.esc_attr($post->post_author).'" />';
351
- echo '<input type="hidden" id="original_post_status" name="original_post_status" value="'.esc_attr($post->post_status).'" />';
352
- echo '<input type="hidden" id="referredby" name="referredby" value="'.($referer ? esc_url($referer) : '').'" />';
353
- echo '<input type="hidden" id="post_ID" name="sidebar_id" value="'.esc_attr($post->ID).'" />';
354
- if (! empty($active_post_lock)) {
355
- echo '<input type="hidden" id="active_post_lock" value="'.esc_attr(implode(':', $active_post_lock)).'" />';
356
- }
357
- if (get_post_status($post) != CAS_App::STATUS_INACTIVE) {
358
- wp_original_referer_field(true, 'previous');
359
- }
360
- echo $form_extra;
361
-
362
- $nav_tabs = array(
363
- 'conditions' => __('Conditions', 'content-aware-sidebars'),
364
- 'action' => __('Action', 'content-aware-sidebars'),
365
- 'design' => __('Design', 'content-aware-sidebars'),
366
- 'schedule' => __('Schedule', 'content-aware-sidebars'),
367
- 'advanced' => __('Options', 'content-aware-sidebars')
368
- );
369
- $nav_tabs = apply_filters('cas/admin/nav-tabs', $nav_tabs);
370
-
371
- echo '<div id="poststuff">';
372
- echo '<div id="post-body" class="cas-metabox-holder metabox-holder columns-2">';
373
- echo '<div id="post-body-content">';
374
- echo '<div id="titlediv">';
375
- echo '<div id="titlewrap">';
376
- echo '<label class="screen-reader-text" id="title-prompt-text" for="title">'.__('Enter title here').'</label>';
377
- echo '<input type="text" name="post_title" size="30" value="'.esc_attr($post->post_title).'" id="title" spellcheck="true" autocomplete="off" />';
378
- echo '</div></div>';
379
- $this->render_section_nav($nav_tabs);
380
- echo '</div>';
381
- $this->render_sections($nav_tabs, $post, $post->post_type);
382
- echo '</div>';
383
- echo '<br class="clear" />';
384
- echo '</div></form></div>';
385
- }
386
-
387
- /**
388
- * Render tab navigation
389
- *
390
- * @since 3.4
391
- * @param array $tabs
392
- * @return void
393
- */
394
- public function render_section_nav($tabs)
395
- {
396
- echo '<h2 class="nav-tab-wrapper js-cas-tabs hide-if-no-js " style="padding-bottom:0;">';
397
- foreach ($tabs as $id => $label) {
398
- echo '<a class="js-nav-link nav-tab nav-tab-section-'.$id.'" href="#top#section-'.$id.'">'.$label.'</a>';
399
- }
400
- echo '</h2>';
401
- }
402
-
403
- /**
404
- * Render meta box sections
405
- *
406
- * @since 3.4
407
- * @param array $tabs
408
- * @param WP_Post $post
409
- * @param string $post_type
410
- * @return void
411
- */
412
- public function render_sections($tabs, $post, $post_type)
413
- {
414
- echo '<div id="postbox-container-1" class="postbox-container">';
415
- do_meta_boxes(CAS_App::BASE_SCREEN.'-edit', 'side', $post);
416
- echo '</div>';
417
- echo '<div id="postbox-container-2" class="postbox-container">';
418
- foreach ($tabs as $id => $label) {
419
- $name = 'section-'.$id;
420
- echo '<div id="'.$name.'" class="cas-section">';
421
- do_meta_boxes(CAS_App::BASE_SCREEN.'-edit', $name, $post);
422
- echo '</div>';
423
- }
424
- //boxes across sections
425
- do_meta_boxes(CAS_App::BASE_SCREEN.'-edit', 'normal', $post);
426
- echo '</div>';
427
- }
428
-
429
- /**
430
- * Update sidebar post type
431
- *
432
- * @since 3.4
433
- * @return int
434
- */
435
- public function update_sidebar_type()
436
- {
437
- global $wpdb;
438
-
439
- $post_ID = (int) $_POST['sidebar_id'];
440
- $post = get_post($post_ID);
441
- $post_data['post_type'] = CAS_App::TYPE_SIDEBAR;
442
- $post_data['ID'] = (int) $post_ID;
443
- $post_data['post_title'] = $_POST['post_title'];
444
- $post_data['comment_status'] = 'closed';
445
- $post_data['ping_status'] = 'closed';
446
- $post_data['post_author'] = get_current_user_id();
447
- $post_data['menu_order'] = intval($_POST['menu_order']);
448
-
449
- $ptype = get_post_type_object($post_data['post_type']);
450
-
451
- if (!current_user_can('edit_post', $post_ID)) {
452
- wp_die(__('You are not allowed to edit this sidebar.', 'content-aware-sidebars'));
453
- } elseif (! current_user_can($ptype->cap->create_posts)) {
454
- return new WP_Error('edit_others_posts', __('You are not allowed to create sidebars.', 'content-aware-sidebars'));
455
- } elseif ($post_data['post_author'] != $_POST['post_author']
456
- && ! current_user_can($ptype->cap->edit_others_posts)) {
457
- return new WP_Error('edit_others_posts', __('You are not allowed to edit this sidebar.', 'content-aware-sidebars'));
458
- }
459
-
460
- if (isset($_POST['post_status'])) {
461
- $post_data['post_status'] = CAS_App::STATUS_ACTIVE;
462
- //if sidebar has been future before, we need to reset date
463
- if ($_POST['post_status'] != $_POST['original_post_status']) {
464
- $post_data['post_date'] = current_time('mysql');
465
- }
466
- } elseif ($_POST['sidebar_activate']) {
467
- $_POST['post_status'] = CAS_App::STATUS_SCHEDULED; //yoast seo expects this
468
- $post_data['post_status'] = CAS_App::STATUS_SCHEDULED;
469
- $post_data['post_date'] = $_POST['sidebar_activate'];
470
- } else {
471
- $_POST['post_status'] = CAS_App::STATUS_INACTIVE;
472
- $post_data['post_status'] = CAS_App::STATUS_INACTIVE;
473
- }
474
-
475
- if ($post_data['post_status'] != CAS_App::STATUS_INACTIVE
476
- && $_POST['sidebar_deactivate']) {
477
- $this->reschedule_deactivation($post_ID, $_POST['sidebar_deactivate']);
478
- } else {
479
- $this->reschedule_deactivation($post_ID);
480
- }
481
-
482
- if (isset($post_data['post_date'])) {
483
- $post_data['post_date_gmt'] = get_gmt_from_date($post_data['post_date']);
484
- }
485
-
486
- if (post_type_supports(CAS_App::TYPE_SIDEBAR, 'revisions')) {
487
- $revisions = wp_get_post_revisions($post_ID, array(
488
- 'order' => 'ASC',
489
- 'posts_per_page' => 1
490
- ));
491
- $revision = current($revisions);
492
- // Check if the revisions have been upgraded
493
- if ($revisions && _wp_get_post_revision_version($revision) < 1) {
494
- _wp_upgrade_revisions_of_post($post, wp_get_post_revisions($post_ID));
495
- }
496
- }
497
-
498
- update_post_meta($post_ID, '_edit_last', $post_data['post_author']);
499
- $success = wp_update_post($post_data);
500
- wp_set_post_lock($post_ID);
501
-
502
- return $post_ID;
503
- }
504
-
505
- /**
506
- * Handle schedule for deactivation
507
- *
508
- * @since 3.4
509
- * @param int $post_id
510
- * @param string $time
511
- * @return void
512
- */
513
- public function reschedule_deactivation($post_id, $time = false)
514
- {
515
- $name = 'cas/event/deactivate';
516
- if (wp_next_scheduled($name, array($post_id)) !== false) {
517
- wp_clear_scheduled_hook($name, array($post_id));
518
- }
519
-
520
- if ($time) {
521
- //Requires to be in GMT
522
- $utime = get_gmt_from_date($time, 'U');
523
- wp_schedule_single_event($utime, $name, array($post_id));
524
- update_post_meta($post_id, CAS_App::META_PREFIX.'deactivate_time', $time);
525
- } else {
526
- delete_post_meta($post_id, CAS_App::META_PREFIX.'deactivate_time');
527
- }
528
- }
529
-
530
- /**
531
- * Create update messages
532
- *
533
- * @param WP_Post $post
534
- *
535
- * @return void
536
- */
537
- public function sidebar_updated_messages($post)
538
- {
539
- $message_number = isset($_GET['message']) ? absint($_GET['message']) : null;
540
-
541
- if (is_null($message_number)) {
542
- return;
543
- }
544
-
545
- $manage_widgets = sprintf(' <a href="%1$s">%2$s</a>', esc_url(admin_url('widgets.php#'.CAS_App::SIDEBAR_PREFIX.$post->ID)), __('Manage widgets', 'content-aware-sidebars'));
546
- $messages = array(
547
- 1 => __('Sidebar updated.', 'content-aware-sidebars').$manage_widgets,
548
- 6 => __('Sidebar activated.', 'content-aware-sidebars').$manage_widgets,
549
- 9 => sprintf(
550
- __('Sidebar scheduled for: <strong>%1$s</strong>.', 'content-aware-sidebars'),
551
- // translators: Publish box date format, see http://php.net/date
552
- date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date))
553
- ).$manage_widgets,
554
- 10 => __('Sidebar deactivated.', 'content-aware-sidebars').$manage_widgets,
555
- );
556
- $messages = apply_filters('cas/admin/messages', $messages, $post);
557
-
558
- if (isset($messages[$message_number])) {
559
- echo '<div id="message" class="updated notice notice-success is-dismissible"><p>'.$messages[$message_number].'</p></div>';
560
- }
561
- }
562
-
563
- /**
564
- * Set pointers for tour and enqueue script
565
- *
566
- * @since 3.3
567
- * @return void
568
- */
569
- private function create_pointers()
570
- {
571
- if ($this->_tour_manager->user_has_finished_tour()) {
572
- return;
573
- }
574
-
575
- $this->_tour_manager->set_pointers(array(
576
- array(
577
- 'content' => sprintf(
578
- '<h3>%s</h3>%s',
579
- __('Get Started in 60 Seconds', 'content-aware-sidebars'),
580
- '<p>'.__('Welcome to Content Aware Sidebars!', 'content-aware-sidebars').'</p>'.
581
- '<p>'.__('This interactive guide will show you just how easy it is to create a widget area and control where, how, and when to display it.', 'content-aware-sidebars').'</p>'
582
- ),
583
- 'ref_id' => '#titlediv',
584
- 'position' => array(
585
- 'edge' => 'top',
586
- 'align' => 'center'
587
- ),
588
- 'pointerWidth' => 400,
589
- 'next' => __('Start Quick Tour', 'content-aware-sidebars'),
590
- 'dismiss' => __('Skip - I know what to do', 'content-aware-sidebars')
591
- ),
592
- array(
593
- 'content' => sprintf(
594
- '<h3>%s</h3>%s',
595
- '1/5 '.__('Where to display', 'content-aware-sidebars'),
596
- '<p>'.__('Choose from the extensive Display Conditions with built-in support for other plugins. You will never be asked to enter widget logic PHP code!', 'content-aware-sidebars').'</p>'.
597
- '<p>'.__('Select anything to continue the tour. You can change it later.', 'content-aware-sidebars').'</p>'
598
- ),
599
- 'ref_id' => '.cas-group-new',
600
- 'position' => array(
601
- 'edge' => 'top',
602
- 'align' => 'center'
603
- ),
604
- 'prev' => false,
605
- 'next' => '.js-wpca-add-or, .js-wpca-add-quick',
606
- 'nextEvent' => 'select2:select click',
607
- 'dismiss' => false
608
- ),
609
- array(
610
- 'content' => sprintf(
611
- '<h3>%s</h3>%s',
612
- '2/5 '.__('Where to display', 'content-aware-sidebars'),
613
- '<p>'.__('Click on the input field and select the content you want - just type to search. Changes are saved automatically!', 'content-aware-sidebars').'</p>'.
614
- '<p>'.__('You can add multiple content types to the same group. Try e.g. "All Posts" and an Author to display on all posts written by that author.', 'content-aware-sidebars').'</p>'.
615
- '<p>'.sprintf(__('<a href="%s" target="_blank">Learn more about AND vs OR conditions</a>', 'content-aware-sidebars'), 'https://dev.institute/docs/content-aware-sidebars/getting-started/display-sidebar-advanced/').'</p>'
616
- ),
617
- 'ref_id' => '#cas-groups > ul',
618
- 'position' => array(
619
- 'edge' => 'top',
620
- 'align' => 'center'
621
- ),
622
- 'dismiss' => __('Close Tour', 'content-aware-sidebars')
623
- ),
624
- array(
625
- 'content' => sprintf(
626
- '<h3>%s</h3>%s',
627
- '3/5 '.__('How to display', 'content-aware-sidebars'),
628
- '<p>'.__('Replace any sidebar or widget area in your theme, or add widgets by merging with them.', 'content-aware-sidebars').'</p>'.
629
- '<p>'.__('You can also use the shortcode to display widgets inside a page or post.', 'content-aware-sidebars').'</p>'
630
- ),
631
- 'ref_id' => '.nav-tab-wrapper.js-cas-tabs .nav-tab-section-action',
632
- 'position' => array(
633
- 'edge' => 'left',
634
- 'align' => 'left'
635
- ),
636
- 'dismiss' => __('Close Tour', 'content-aware-sidebars')
637
- ),
638
- array(
639
- 'content' => sprintf(
640
- '<h3>%s</h3>%s',
641
- '4/5 '.__('When to activate', 'content-aware-sidebars'),
642
- '<p>'.__('Create a widget area and manage its widgets today, then publish it when you are ready.', 'content-aware-sidebars').'</p>'.
643
- '<p>'.__('To schedule automatic activation or deactivation, just pick a date and time!', 'content-aware-sidebars').'</p>'.
644
- '<p>'.__('By default, new widget areas will be activated when created.', 'content-aware-sidebars').'</p>'
645
- ),
646
- 'ref_id' => '.nav-tab-wrapper.js-cas-tabs .nav-tab-section-schedule',
647
- 'position' => array(
648
- 'edge' => 'left',
649
- 'align' => 'left'
650
- ),
651
- 'dismiss' => __('Close Tour', 'content-aware-sidebars')
652
- ),
653
- array(
654
- 'content' => sprintf(
655
- '<h3>%s</h3>%s',
656
- '5/5 '.__('How to look', 'content-aware-sidebars'),
657
- '<p>'.__('Personalize the styling without writing any code!', 'content-aware-sidebars').'</p>'.
658
- '<p>'.__('You can modify the HTML and CSS classes of the widget area itself, each widget, as well as widget titles.', 'content-aware-sidebars').'</p>'
659
- ),
660
- 'ref_id' => '.nav-tab-wrapper.js-cas-tabs .nav-tab-section-design',
661
- 'position' => array(
662
- 'edge' => 'left',
663
- 'align' => 'left'
664
- ),
665
- 'next' => __('Finish Tour', 'content-aware-sidebars')
666
- ),
667
- array(
668
- 'content' => sprintf(
669
- '<h3>%s</h3>%s',
670
- __("That's it", 'content-aware-sidebars'),
671
- '<p>'.__('Hit the Create button to save your first custom widget area.', 'content-aware-sidebars').'</p>'.
672
- '<p>'.__('If you need more help, check out the links below.', 'content-aware-sidebars').'</p>'
673
- ),
674
- 'ref_id' => '#submitdiv',
675
- 'position' => array(
676
- 'edge' => 'right',
677
- 'align' => 'top'
678
- ),
679
- 'dismiss' => __('Close', 'content-aware-sidebars')
680
- )
681
- ));
682
- $this->_tour_manager->enqueue_scripts();
683
- }
684
-
685
- /**
686
- * Meta boxes for sidebar edit
687
- * @global object $post
688
- * @return void
689
- */
690
- public function create_meta_boxes($post)
691
- {
692
- $this->create_pointers();
693
- CAS_App::instance()->manager()->populate_metadata();
694
- $path = plugin_dir_path(dirname(__FILE__)).'view/';
695
-
696
- $cas_fs = cas_fs();
697
-
698
- $boxes = array();
699
- $boxes[] = array(
700
- 'id' => 'submitdiv',
701
- 'title' => __('Publish'),
702
- 'view' => 'submit',
703
- 'context' => 'side',
704
- 'priority' => 'high'
705
- );
706
- $boxes[] = array(
707
- 'id' => 'cas-options',
708
- 'title' => __('How to display', 'content-aware-sidebars'),
709
- 'view' => 'action',
710
- 'context' => 'section-action',
711
- );
712
- $boxes[] = array(
713
- 'id' => 'cas-status',
714
- 'title' => __('Status', 'content-aware-sidebars'),
715
- 'view' => 'status',
716
- 'context' => 'section-schedule',
717
- );
718
- $boxes[] = array(
719
- 'id' => 'cas-widget-html',
720
- 'title' => __('Styles', 'content-aware-sidebars'),
721
- 'view' => 'html',
722
- 'context' => 'section-design',
723
- );
724
- $boxes[] = array(
725
- 'id' => 'cas-advanced',
726
- 'title' => __('Options', 'content-aware-sidebars'),
727
- 'view' => 'advanced',
728
- 'context' => 'section-advanced',
729
- );
730
- $boxes[] = array(
731
- 'id' => 'cas-plugin-links',
732
- 'title' => __('Recommendations', 'content-aware-sidebars'),
733
- 'view' => 'support',
734
- 'context' => 'side',
735
- );
736
- $boxes[] = array(
737
- 'id' => 'cas-schedule',
738
- 'title' => __('Time Schedule', 'content-aware-sidebars').' <span class="cas-pro-label">'.__('Pro', 'content-aware-sidebars').'</span>',
739
- 'view' => 'schedule',
740
- 'context' => 'section-schedule',
741
- );
742
- $boxes[] = array(
743
- 'id' => 'cas-design',
744
- 'title' => __('Design', 'content-aware-sidebars').' <span class="cas-pro-label">'.__('Pro', 'content-aware-sidebars').'</span>',
745
- 'view' => 'design',
746
- 'context' => 'section-design',
747
- );
748
-
749
- foreach ($boxes as $box) {
750
- $view = WPCAView::make($path.'meta_box_'.$box['view'].'.php', array(
751
- 'post' => $post
752
- ));
753
-
754
- add_meta_box(
755
- $box['id'],
756
- $box['title'],
757
- array($view,'render'),
758
- CAS_App::BASE_SCREEN.'-edit',
759
- $box['context'],
760
- isset($box['priority']) ? $box['priority'] : 'default'
761
- );
762
- }
763
-
764
- //todo: refactor add of meta box
765
- //with new bootstrapper, legacy core might be loaded
766
- if (method_exists('WPCACore', 'render_group_meta_box')) {
767
- WPCACore::render_group_meta_box($post, CAS_App::BASE_SCREEN.'-edit', 'section-conditions', 'default');
768
- }
769
- }
770
-
771
- /**
772
- * Create form field for metadata
773
- * @global object $post
774
- * @param array $setting
775
- * @return void
776
- */
777
- public static function form_field($id, $class = '', $icon = '')
778
- {
779
- $setting = CAS_App::instance()->manager()->metadata()->get($id);
780
- $current = $setting->get_data(get_the_ID(), true, $setting->get_input_type() != 'multi');
781
- $icon = $icon ? '<span class="'.$icon.'"></span> ' : '';
782
-
783
- echo '<div class="'.$class.'">'.$icon.'<strong>' . $setting->get_title() . '</strong>';
784
- echo '<p>';
785
- switch ($setting->get_input_type()) {
786
- case 'select':
787
- echo '<select style="width:250px;" name="' . $id . '" class="js-cas-'.$id.'">' . "\n";
788
- foreach ($setting->get_input_list() as $key => $value) {
789
- $disabled = '';
790
- if (is_string($key) && strpos($key, '__') === 0) {
791
- $disabled = ' disabled="disabled"';
792
- }
793
- echo '<option value="' . $key . '"' . selected($current, $key, false) . $disabled . '>' . $value . '</option>' . "\n";
794
- }
795
- echo '</select>' . "\n";
796
- break;
797
- case 'checkbox':
798
- echo '<ul>' . "\n";
799
- foreach ($setting->get_input_list() as $key => $value) {
800
- echo '<li><label><input type="checkbox" name="' . $id . '[]" class="js-cas-'.$id.'" value="' . $key . '"' . (in_array($key, $current) ? ' checked="checked"' : '') . ' /> ' . $value . '</label></li>' . "\n";
801
- }
802
- echo '</ul>' . "\n";
803
- break;
804
- case 'multi':
805
- echo '<div><select style="width:100%;" class="js-cas-'.$id.'" multiple="multiple" name="' . $id . '[]" data-value="'.implode(',', $current).'"></select></div>';
806
- break;
807
- case 'text':
808
- default:
809
- echo '<input style="width:200px;" type="text" name="' . $id . '" value="' . $current . '" />' . "\n";
810
- break;
811
- }
812
- echo '</p></div>';
813
- }
814
-
815
- /**
816
- * Save meta values for post
817
- * @param int $post_id
818
- * @return void
819
- */
820
- public function save_post($post_id, $post)
821
- {
822
-
823
- //Verify nonce, check_admin_referer dies on false
824
- //TODO: check other nonce instead
825
- if (!(isset($_POST[WPCACore::NONCE])
826
- && wp_verify_nonce($_POST[WPCACore::NONCE], WPCACore::PREFIX.$post_id))) {
827
- return;
828
- }
829
-
830
- // Check permissions
831
- if (!current_user_can(CAS_App::CAPABILITY, $post_id)) {
832
- return;
833
- }
834
-
835
- // Check autosave
836
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
837
- return;
838
- }
839
-
840
- // Save metadata
841
- // todo: wrap this in metadata manager?
842
- foreach (CAS_App::instance()->manager()->metadata() as $field) {
843
- $field->save($post_id);
844
- }
845
- }
846
-
847
- /**
848
- * Add suffix when creating sidebar with existing name
849
- * Does not stop duplicate titles on update
850
- *
851
- * @since 3.4.3
852
- * @param array $insert_data
853
- * @param array $data
854
- * @return array
855
- */
856
- public function add_duplicate_title_suffix($insert_data, $data)
857
- {
858
- if ($data['post_type'] == CAS_App::TYPE_SIDEBAR && !$data['ID']) {
859
- $sidebars = CAS_App::instance()->manager()->sidebars;
860
- $sidebar_titles = array();
861
- foreach ($sidebars as $sidebar) {
862
- $sidebar_titles[$sidebar->post_title] = 1;
863
- }
864
- //if title exists, add a suffix
865
- $i = 0;
866
- $title = wp_unslash($insert_data['post_title']);
867
- $new_title = $title;
868
- while (isset($sidebar_titles[$new_title])) {
869
- $new_title = $title.' ('.++$i.')';
870
- }
871
- if ($i) {
872
- $insert_data['post_title'] = wp_slash($new_title);
873
- }
874
- }
875
- return $insert_data;
876
- }
877
-
878
- /**
879
- * Remove widget when its sidebar is removed
880
- * @param int $post_id
881
- * @return void
882
- */
883
- public function remove_sidebar_widgets($post_id)
884
- {
885
-
886
- // Authenticate and only continue on sidebar post type
887
- if (!current_user_can(CAS_App::CAPABILITY) || get_post_type($post_id) != CAS_App::TYPE_SIDEBAR) {
888
- return;
889
- }
890
-
891
- $id = CAS_App::SIDEBAR_PREFIX . $post_id;
892
-
893
- //Get widgets
894
- $sidebars_widgets = wp_get_sidebars_widgets();
895
-
896
- // Check if sidebar exists in database
897
- if (!isset($sidebars_widgets[$id])) {
898
- return;
899
- }
900
-
901
- // Remove widgets settings from sidebar
902
- foreach ($sidebars_widgets[$id] as $widget_id) {
903
- $widget_type = preg_replace('/-[0-9]+$/', '', $widget_id);
904
- $widget_settings = get_option('widget_' . $widget_type);
905
- $widget_id = substr($widget_id, strpos($widget_id, '-') + 1);
906
- if ($widget_settings && isset($widget_settings[$widget_id])) {
907
- unset($widget_settings[$widget_id]);
908
- update_option('widget_' . $widget_type, $widget_settings);
909
- }
910
- }
911
-
912
- // Remove sidebar
913
- unset($sidebars_widgets[$id]);
914
- wp_set_sidebars_widgets($sidebars_widgets);
915
- }
916
-
917
- /**
918
- * Get sidebar edit link
919
- * TODO: Consider changing post type _edit_link instead
920
- *
921
- * @since 3.4
922
- * @param string $link
923
- * @param int $post_id
924
- * @param string $context
925
- * @return string
926
- */
927
- public function get_edit_post_link($link, $post_id, $context)
928
- {
929
- $post = get_post($post_id);
930
- if ($post->post_type == CAS_App::TYPE_SIDEBAR) {
931
- $sep = '&';
932
- if ($context == 'display') {
933
- $sep = '&amp;';
934
- }
935
- $link = admin_url('admin.php?page=wpcas-edit'.$sep.'sidebar_id='.$post_id);
936
-
937
- //load page in all languages for wpml, polylang,
938
- //ensures post type conditions are not filtered
939
- if (defined('ICL_SITEPRESS_VERSION') || defined('POLYLANG_VERSION')) {
940
- $link .= $sep.'lang=all';
941
- }
942
- }
943
- return $link;
944
- }
945
-
946
- /**
947
- * Get sidebar delete link
948
- * TODO: Consider changing post type _edit_link instead
949
- *
950
- * @since 3.4
951
- * @param string $link
952
- * @param int $post_id
953
- * @param boolean $force_delete
954
- * @return string
955
- */
956
- public function get_delete_post_link($link, $post_id, $force_delete)
957
- {
958
- $post = get_post($post_id);
959
- if ($post->post_type == CAS_App::TYPE_SIDEBAR) {
960
- $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
961
-
962
- $link = add_query_arg(
963
- 'action',
964
- $action,
965
- admin_url('admin.php?page=wpcas-edit&sidebar_id='.$post_id)
966
- );
967
- $link = wp_nonce_url($link, "$action-post_{$post_id}");
968
- }
969
- return $link;
970
- }
971
-
972
- /**
973
- * Register and enqueue scripts styles
974
- * for screen
975
- *
976
- * @since 3.4
977
- */
978
- public function add_scripts_styles()
979
- {
980
- if (is_multisite()) {
981
- add_action('admin_footer', '_admin_notice_post_locked');
982
- } else {
983
- $check_users = get_users(array( 'fields' => 'ID', 'number' => 2 ));
984
- if (count($check_users) > 1) {
985
- add_action('admin_footer', '_admin_notice_post_locked');
986
- }
987
- }
988
-
989
- wp_enqueue_script('wp-a11y');
990
-
991
- if (wp_is_mobile()) {
992
- wp_enqueue_script('jquery-touch-punch');
993
- }
994
-
995
- WPCACore::enqueue_scripts_styles('');
996
-
997
- $this->register_script('flatpickr', 'flatpickr', array(), '3.0.6');
998
- $this->register_script('cas/admin/edit', 'cas_admin', array('jquery','flatpickr','wp-color-picker'));
999
-
1000
- $this->enqueue_style('flatpickr', 'flatpickr.dark.min', array(), '3.0.6');
1001
- wp_enqueue_style('wp-color-picker');
1002
-
1003
- $metadata = CAS_App::instance()->_manager->metadata();
1004
- $visibility = array();
1005
- $target = array();
1006
- foreach ($metadata->get('visibility')->get_input_list() as $category_key => $category) {
1007
-
1008
- //legacy format
1009
- if (!is_array($category)) {
1010
- $visibility[] = array(
1011
- 'id' => $category_key,
1012
- 'text' => $category
1013
- );
1014
- continue;
1015
- }
1016
-
1017
- $data = array(
1018
- 'text' => $category['label'],
1019
- 'children' => array()
1020
- );
1021
- foreach ($category['options'] as $key => $value) {
1022
- $data['children'][] = array(
1023
- 'id' => $key,
1024
- 'text' => $value
1025
- );
1026
- }
1027
- $visibility[] = $data;
1028
- }
1029
- foreach ($metadata->get('host')->get_input_list() as $value => $label) {
1030
- $target[] = array(
1031
- 'id' => $value,
1032
- 'text' => $label
1033
- );
1034
- }
1035
-
1036
- if (!cas_fs()->can_use_premium_code()) {
1037
- $visibility[] = array(
1038
- 'text' => __('Upgrade to Pro for more options', 'content-aware-sidebars'),
1039
- 'children' => array()
1040
- );
1041
- }
1042
-
1043
- global $wp_locale;
1044
-
1045
- wp_enqueue_script('cas/admin/edit');
1046
- wp_localize_script('cas/admin/edit', 'CASAdmin', array(
1047
- 'allVisibility' => __('All Users', 'content-aware-sidebars'),
1048
- 'visibility' => $visibility,
1049
- 'target' => $target,
1050
- 'weekdays' => array(
1051
- 'shorthand' => array_values($wp_locale->weekday_abbrev),
1052
- 'longhand' => array_values($wp_locale->weekday)
1053
- ),
1054
- 'months' => array(
1055
- 'shorthand' => array_values($wp_locale->month_abbrev),
1056
- 'longhand' => array_values($wp_locale->month)
1057
- ),
1058
- 'weekStart' => get_option('start_of_week', 0),
1059
- 'timeFormat' => get_option('time_format'),
1060
- 'dateFormat' => __('F j, Y') //default long date
1061
- ));
1062
-
1063
- //badgeos compat
1064
- //todo: check that developers respond with a fix soon
1065
- wp_register_script('badgeos-select2', '');
1066
- wp_register_style('badgeos-select2-css', '');
1067
- }
1068
- }
1
+ <?php
2
+ /**
3
+ * @package Content Aware Sidebars
4
+ * @author Joachim Jensen <joachim@dev.institute>
5
+ * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
+ */
8
+
9
+ defined('ABSPATH') || exit;
10
+
11
+ final class CAS_Sidebar_Edit extends CAS_Admin
12
+ {
13
+
14
+ /**
15
+ * Intro tour manager
16
+ * @var WP_Pointer_Tour
17
+ */
18
+ private $_tour_manager;
19
+
20
+ /**
21
+ * Add filters and actions for admin dashboard
22
+ * e.g. AJAX calls
23
+ *
24
+ * @since 3.5
25
+ * @return void
26
+ */
27
+ public function admin_hooks()
28
+ {
29
+ $this->_tour_manager = new WP_Pointer_Tour(CAS_App::META_PREFIX.'cas_tour');
30
+
31
+ $this->add_action('delete_post', 'remove_sidebar_widgets');
32
+ $this->add_action('save_post_'.CAS_App::TYPE_SIDEBAR, 'save_post', 10, 2);
33
+
34
+ $this->add_filter('wp_insert_post_data', 'add_duplicate_title_suffix', 99, 2);
35
+
36
+ if (!cas_fs()->can_use_premium_code()) {
37
+ $this->add_action('wpca/modules/init', 'add_modules');
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Set up admin menu and get current screen
43
+ *
44
+ * @since 3.4
45
+ * @return string
46
+ */
47
+ public function get_screen()
48
+ {
49
+ $post_type_object = $this->get_sidebar_type();
50
+ return add_submenu_page(
51
+ CAS_App::BASE_SCREEN,
52
+ $post_type_object->labels->add_new_item,
53
+ $post_type_object->labels->add_new,
54
+ $post_type_object->cap->edit_posts,
55
+ CAS_App::BASE_SCREEN.'-edit',
56
+ [$this,'render_screen']
57
+ );
58
+ }
59
+
60
+ /**
61
+ * @since 3.5
62
+ *
63
+ * @return bool
64
+ */
65
+ public function authorize_user()
66
+ {
67
+ return true;
68
+ }
69
+
70
+ /**
71
+ * @since 3.4
72
+ *
73
+ * @return void
74
+ */
75
+ public function prepare_screen()
76
+ {
77
+ $this->add_action('cas/admin/add_meta_boxes', 'create_meta_boxes');
78
+
79
+ global $post, $title, $active_post_lock;
80
+
81
+ $post_type = CAS_App::TYPE_SIDEBAR;
82
+ $post_type_object = $this->get_sidebar_type();
83
+ $post_id = isset($_REQUEST['sidebar_id']) ? $_REQUEST['sidebar_id'] : 0;
84
+
85
+ /**
86
+ * Edit mode
87
+ */
88
+ if ($post_id) {
89
+ $this->process_actions($post_id);
90
+
91
+ $post = get_post($post_id, OBJECT, 'edit');
92
+
93
+ if (! $post) {
94
+ wp_die(__('The sidebar no longer exists.'));
95
+ }
96
+ if (! current_user_can($post_type_object->cap->edit_post, $post_id)) {
97
+ wp_die(__('You are not allowed to edit this sidebar.'));
98
+ }
99
+ if ('trash' == $post->post_status) {
100
+ wp_die(__('You cannot edit this sidebar because it is in the Trash. Please restore it and try again.'));
101
+ }
102
+
103
+ if (! empty($_GET['get-post-lock'])) {
104
+ check_admin_referer('lock-post_' . $post_id);
105
+ wp_set_post_lock($post_id);
106
+ wp_redirect(get_edit_post_link($post_id, 'url'));
107
+ exit();
108
+ }
109
+
110
+ if (! wp_check_post_lock($post->ID)) {
111
+ $active_post_lock = wp_set_post_lock($post->ID);
112
+ }
113
+
114
+ $title = $post_type_object->labels->edit_item;
115
+
116
+ /**
117
+ * New Mode
118
+ */
119
+ } else {
120
+ if (! (current_user_can($post_type_object->cap->edit_posts) || current_user_can($post_type_object->cap->create_posts))) {
121
+ wp_die(
122
+ '<p>' . __('You are not allowed to create sidebars.', 'content-aware-sidebars') . '</p>',
123
+ 403
124
+ );
125
+ }
126
+
127
+ $post = get_default_post_to_edit($post_type, true);
128
+
129
+ $title = $post_type_object->labels->add_new_item;
130
+ }
131
+
132
+ do_action('cas/admin/add_meta_boxes', $post);
133
+ }
134
+
135
+ /**
136
+ * @since 3.9
137
+ * @param WPCATypeManager $types
138
+ *
139
+ * @return void
140
+ */
141
+ public function add_modules($types)
142
+ {
143
+ if (!$types->has(CAS_App::TYPE_SIDEBAR)) {
144
+ return;
145
+ }
146
+
147
+ $pro_label = '(Pro)';
148
+ $type = $types->get(CAS_App::TYPE_SIDEBAR);
149
+ $path = plugin_dir_path(dirname(__FILE__));
150
+
151
+ require($path.'conditions/placeholder.php');
152
+
153
+ if (!WPCACore::get_option(CAS_App::TYPE_SIDEBAR, 'legacy.date_module', false)) {
154
+ $module = new CASConditionPlaceholder('cas_date', __('Dates', 'content-aware-sidebars').' '.$pro_label);
155
+ $type->add($module, 'cas_date');
156
+ }
157
+
158
+ $module = new CASConditionPlaceholder('cas_url', __('URLs', 'content-aware-sidebars').' '.$pro_label);
159
+ $type->add($module, 'cas_url');
160
+ $module = new CASConditionPlaceholder('cas_ref_url', __('Referrer URLs', 'content-aware-sidebars').' '.$pro_label);
161
+ $type->add($module, 'cas_ref_url');
162
+
163
+ if (function_exists('bp_is_active')) {
164
+ $module = new CASConditionPlaceholder('cas_bbp', __('BuddyPress Groups', 'content-aware-sidebars').' '.$pro_label, '', '', 'plugins');
165
+ $type->add($module, 'cas_bbp');
166
+ }
167
+
168
+ if (defined('ACF')) {
169
+ $module = new CASConditionPlaceholder('cas_acf', __('Advanced Custom Fields', 'content-aware-sidebars').' '.$pro_label, '', '', 'plugins');
170
+ $type->add($module, 'cas_acf');
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Process actions
176
+ *
177
+ * @since 3.4
178
+ * @param int $post_id
179
+ * @return void
180
+ */
181
+ public function process_actions($post_id)
182
+ {
183
+ $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
184
+ if (isset($_POST['deletepost'])) {
185
+ $action = 'delete';
186
+ }
187
+
188
+ if ($action && $post_id) {
189
+ //wp_reset_vars( array( 'action' ) );
190
+ $sendback = wp_get_referer();
191
+ $sendback = remove_query_arg(
192
+ ['action','trashed', 'untrashed', 'deleted', 'ids'],
193
+ $sendback
194
+ );
195
+ if (isset($_REQUEST['_cas_section']) && $_REQUEST['_cas_section']) {
196
+ $sendback .= $_REQUEST['_cas_section'];
197
+ }
198
+
199
+ $post = get_post($post_id);
200
+ if (! $post) {
201
+ wp_die(__('The sidebar no longer exists.', 'content-aware-sidebars'));
202
+ }
203
+
204
+ check_admin_referer($action . '-post_' . $post_id);
205
+
206
+ switch ($action) {
207
+ case 'update':
208
+
209
+ $post_id = $this->update_sidebar_type();
210
+
211
+ // Session cookie flag that the post was saved
212
+ if (isset($_COOKIE['wp-saving-post']) && $_COOKIE['wp-saving-post'] === $post_id . '-check') {
213
+ setcookie('wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl());
214
+ }
215
+
216
+ $status = get_post_status($post_id);
217
+ if (isset($_POST['original_post_status']) && $_POST['original_post_status'] == $status) {
218
+ $message = 1;
219
+ } else {
220
+ switch ($status) {
221
+ case CAS_App::STATUS_SCHEDULED:
222
+ //gets scheduled
223
+ $message = 9;
224
+ break;
225
+ case CAS_App::STATUS_INACTIVE:
226
+ //gets deactivated
227
+ $message = 10;
228
+ break;
229
+ case CAS_App::STATUS_ACTIVE:
230
+ //gets activated
231
+ $message = 6;
232
+ break;
233
+ default:
234
+ $message = 1;
235
+ }
236
+ }
237
+
238
+ $sendback = add_query_arg([
239
+ 'sidebar_id' => $post_id,
240
+ 'message' => $message,
241
+ 'page' => 'wpcas-edit'
242
+ ], $sendback);
243
+ wp_safe_redirect($sendback);
244
+ exit();
245
+ case 'trash':
246
+
247
+ if (! current_user_can('delete_post', $post_id)) {
248
+ wp_die(__('You are not allowed to move this sidebar to the Trash.', 'content-aware-sidebars'));
249
+ }
250
+
251
+ if ($user_id = wp_check_post_lock($post_id)) {
252
+ $user = get_userdata($user_id);
253
+ wp_die(sprintf(__('You cannot move this sidebar to the Trash. %s is currently editing.', 'content-aware-sidebars'), $user->display_name));
254
+ }
255
+
256
+ if (! wp_trash_post($post_id)) {
257
+ wp_die(__('Error in moving to Trash.'));
258
+ }
259
+
260
+ $sendback = remove_query_arg('sidebar_id', $sendback);
261
+
262
+ wp_safe_redirect(add_query_arg(
263
+ [
264
+ 'page' => 'wpcas',
265
+ 'trashed' => 1,
266
+ 'ids' => $post_id
267
+ ],
268
+ $sendback
269
+ ));
270
+ exit();
271
+ case 'untrash':
272
+
273
+ if (! current_user_can('delete_post', $post_id)) {
274
+ wp_die(__('You are not allowed to restore this sidebar from the Trash.', 'content-aware-sidebars'));
275
+ }
276
+
277
+ if (! wp_untrash_post($post_id)) {
278
+ wp_die(__('Error in restoring from Trash.'));
279
+ }
280
+
281
+ wp_safe_redirect(add_query_arg('untrashed', 1, $sendback));
282
+ exit();
283
+ case 'delete':
284
+
285
+ if (! current_user_can('delete_post', $post_id)) {
286
+ wp_die(__('You are not allowed to delete this sidebar.', 'content-aware-sidebars'));
287
+ }
288
+
289
+ if (! wp_delete_post($post_id, true)) {
290
+ wp_die(__('Error in deleting.'));
291
+ }
292
+
293
+ $sendback = remove_query_arg('sidebar_id', $sendback);
294
+ wp_safe_redirect(add_query_arg([
295
+ 'page' => 'wpcas',
296
+ 'deleted' => 1
297
+ ], $sendback));
298
+ exit();
299
+ default:
300
+ do_action('cas/admin/action', $action, $post);
301
+ break;
302
+ }
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Render screen
308
+ *
309
+ * @since 3.4
310
+ * @return void
311
+ */
312
+ public function render_screen()
313
+ {
314
+ global $post, $active_post_lock;
315
+
316
+ $post_type_object = get_post_type_object($post->post_type);
317
+
318
+ $post_id = isset($_REQUEST['sidebar_id']) ? $_REQUEST['sidebar_id'] : 0;
319
+
320
+ $notice = false;
321
+ $form_extra = '';
322
+ if ('auto-draft' == $post->post_status) {
323
+ if (isset($_REQUEST['sidebar_id'])) {
324
+ $post->post_title = '';
325
+ }
326
+ $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
327
+ }
328
+
329
+ if ($post_id) {
330
+ $title = __('Edit');
331
+ } else {
332
+ $title = $post_type_object->labels->new_item;
333
+ }
334
+
335
+ echo '<div class="wrap">';
336
+ echo '<h1>';
337
+ echo '<a href="'.admin_url('admin.php?page=wpcas').'">'.$post_type_object->labels->all_items.'</a> &raquo; ';
338
+ echo esc_html($title);
339
+ if (isset($_REQUEST['sidebar_id'])) {
340
+ if (current_user_can('edit_theme_options')) {
341
+ echo ' <a href="' . esc_url(admin_url('widgets.php#'.CAS_App::SIDEBAR_PREFIX.$post->ID)) . '" class="page-title-action add-new-h2">' . __('Manage Widgets', 'content-aware-sidebars') . '</a>';
342
+ }
343
+ }
344
+
345
+ echo '</h1>';
346
+
347
+ $this->sidebar_updated_messages($post);
348
+
349
+ echo '<form name="post" action="admin.php?page=wpcas-edit" method="post" id="post">';
350
+ $referer = wp_get_referer();
351
+ wp_nonce_field('update-post_' . $post->ID);
352
+ echo '<input type="hidden" id="user-id" name="user_ID" value="'.(int)get_current_user_id().'" />';
353
+ echo '<input type="hidden" id="_cas_section" name="_cas_section" value="" />';
354
+ echo '<input type="hidden" id="hiddenaction" name="action" value="update" />';
355
+ echo '<input type="hidden" id="post_author" name="post_author" value="'.esc_attr($post->post_author).'" />';
356
+ echo '<input type="hidden" id="original_post_status" name="original_post_status" value="'.esc_attr($post->post_status).'" />';
357
+ echo '<input type="hidden" id="referredby" name="referredby" value="'.($referer ? esc_url($referer) : '').'" />';
358
+ echo '<input type="hidden" id="post_ID" name="sidebar_id" value="'.esc_attr($post->ID).'" />';
359
+ if (! empty($active_post_lock)) {
360
+ echo '<input type="hidden" id="active_post_lock" value="'.esc_attr(implode(':', $active_post_lock)).'" />';
361
+ }
362
+ if (get_post_status($post) != CAS_App::STATUS_INACTIVE) {
363
+ wp_original_referer_field(true, 'previous');
364
+ }
365
+ echo $form_extra;
366
+
367
+ $nav_tabs = [
368
+ 'conditions' => __('Conditions', 'content-aware-sidebars'),
369
+ 'action' => __('Action', 'content-aware-sidebars'),
370
+ 'design' => __('Design', 'content-aware-sidebars'),
371
+ 'schedule' => __('Schedule', 'content-aware-sidebars'),
372
+ 'advanced' => __('Options', 'content-aware-sidebars')
373
+ ];
374
+ $nav_tabs = apply_filters('cas/admin/nav-tabs', $nav_tabs);
375
+
376
+ echo '<div id="poststuff">';
377
+ echo '<div id="post-body" class="cas-metabox-holder metabox-holder columns-2">';
378
+ echo '<div id="post-body-content">';
379
+ echo '<div id="titlediv">';
380
+ echo '<div id="titlewrap">';
381
+ echo '<label class="screen-reader-text" id="title-prompt-text" for="title">'.__('Enter title here').'</label>';
382
+ echo '<input type="text" name="post_title" size="30" value="'.esc_attr($post->post_title).'" id="title" spellcheck="true" autocomplete="off" />';
383
+ echo '</div></div>';
384
+ $this->render_section_nav($nav_tabs);
385
+ echo '</div>';
386
+ $this->render_sections($nav_tabs, $post, $post->post_type);
387
+ echo '</div>';
388
+ echo '<br class="clear" />';
389
+ echo '</div></form></div>';
390
+ }
391
+
392
+ /**
393
+ * Render tab navigation
394
+ *
395
+ * @since 3.4
396
+ * @param array $tabs
397
+ * @return void
398
+ */
399
+ public function render_section_nav($tabs)
400
+ {
401
+ echo '<h2 class="nav-tab-wrapper js-cas-tabs hide-if-no-js " style="padding-bottom:0;">';
402
+ foreach ($tabs as $id => $label) {
403
+ echo '<a class="js-nav-link nav-tab nav-tab-section-'.$id.'" href="#top#section-'.$id.'">'.$label.'</a>';
404
+ }
405
+ echo '</h2>';
406
+ }
407
+
408
+ /**
409
+ * Render meta box sections
410
+ *
411
+ * @since 3.4
412
+ * @param array $tabs
413
+ * @param WP_Post $post
414
+ * @param string $post_type
415
+ * @return void
416
+ */
417
+ public function render_sections($tabs, $post, $post_type)
418
+ {
419
+ echo '<div id="postbox-container-1" class="postbox-container">';
420
+ do_meta_boxes(CAS_App::BASE_SCREEN.'-edit', 'side', $post);
421
+ echo '</div>';
422
+ echo '<div id="postbox-container-2" class="postbox-container">';
423
+ foreach ($tabs as $id => $label) {
424
+ $name = 'section-'.$id;
425
+ echo '<div id="'.$name.'" class="cas-section">';
426
+ do_meta_boxes(CAS_App::BASE_SCREEN.'-edit', $name, $post);
427
+ echo '</div>';
428
+ }
429
+ //boxes across sections
430
+ do_meta_boxes(CAS_App::BASE_SCREEN.'-edit', 'normal', $post);
431
+ echo '</div>';
432
+ }
433
+
434
+ /**
435
+ * Update sidebar post type
436
+ *
437
+ * @since 3.4
438
+ * @return int
439
+ */
440
+ public function update_sidebar_type()
441
+ {
442
+ global $wpdb;
443
+
444
+ $post_ID = (int) $_POST['sidebar_id'];
445
+ $post = get_post($post_ID);
446
+ $post_data['post_type'] = CAS_App::TYPE_SIDEBAR;
447
+ $post_data['ID'] = (int) $post_ID;
448
+ $post_data['post_title'] = $_POST['post_title'];
449
+ $post_data['comment_status'] = 'closed';
450
+ $post_data['ping_status'] = 'closed';
451
+ $post_data['post_author'] = get_current_user_id();
452
+ $post_data['menu_order'] = intval($_POST['menu_order']);
453
+
454
+ $ptype = get_post_type_object($post_data['post_type']);
455
+
456
+ if (!current_user_can('edit_post', $post_ID)) {
457
+ wp_die(__('You are not allowed to edit this sidebar.', 'content-aware-sidebars'));
458
+ } elseif (! current_user_can($ptype->cap->create_posts)) {
459
+ return new WP_Error('edit_others_posts', __('You are not allowed to create sidebars.', 'content-aware-sidebars'));
460
+ } elseif ($post_data['post_author'] != $_POST['post_author']
461
+ && ! current_user_can($ptype->cap->edit_others_posts)) {
462
+ return new WP_Error('edit_others_posts', __('You are not allowed to edit this sidebar.', 'content-aware-sidebars'));
463
+ }
464
+
465
+ if (isset($_POST['post_status'])) {
466
+ $post_data['post_status'] = CAS_App::STATUS_ACTIVE;
467
+ //if sidebar has been future before, we need to reset date
468
+ if ($_POST['post_status'] != $_POST['original_post_status']) {
469
+ $post_data['post_date'] = current_time('mysql');
470
+ }
471
+ } elseif ($_POST['sidebar_activate']) {
472
+ $_POST['post_status'] = CAS_App::STATUS_SCHEDULED; //yoast seo expects this
473
+ $post_data['post_status'] = CAS_App::STATUS_SCHEDULED;
474
+ $post_data['post_date'] = $_POST['sidebar_activate'];
475
+ } else {
476
+ $_POST['post_status'] = CAS_App::STATUS_INACTIVE;
477
+ $post_data['post_status'] = CAS_App::STATUS_INACTIVE;
478
+ }
479
+
480
+ if ($post_data['post_status'] != CAS_App::STATUS_INACTIVE
481
+ && $_POST['sidebar_deactivate']) {
482
+ $this->reschedule_deactivation($post_ID, $_POST['sidebar_deactivate']);
483
+ } else {
484
+ $this->reschedule_deactivation($post_ID);
485
+ }
486
+
487
+ if (isset($post_data['post_date'])) {
488
+ $post_data['post_date_gmt'] = get_gmt_from_date($post_data['post_date']);
489
+ }
490
+
491
+ if (post_type_supports(CAS_App::TYPE_SIDEBAR, 'revisions')) {
492
+ $revisions = wp_get_post_revisions($post_ID, [
493
+ 'order' => 'ASC',
494
+ 'posts_per_page' => 1
495
+ ]);
496
+ $revision = current($revisions);
497
+ // Check if the revisions have been upgraded
498
+ if ($revisions && _wp_get_post_revision_version($revision) < 1) {
499
+ _wp_upgrade_revisions_of_post($post, wp_get_post_revisions($post_ID));
500
+ }
501
+ }
502
+
503
+ update_post_meta($post_ID, '_edit_last', $post_data['post_author']);
504
+ $success = wp_update_post($post_data);
505
+ wp_set_post_lock($post_ID);
506
+
507
+ return $post_ID;
508
+ }
509
+
510
+ /**
511
+ * Handle schedule for deactivation
512
+ *
513
+ * @since 3.4
514
+ * @param int $post_id
515
+ * @param string $time
516
+ * @return void
517
+ */
518
+ public function reschedule_deactivation($post_id, $time = false)
519
+ {
520
+ $name = 'cas/event/deactivate';
521
+ if (wp_next_scheduled($name, [$post_id]) !== false) {
522
+ wp_clear_scheduled_hook($name, [$post_id]);
523
+ }
524
+
525
+ if ($time) {
526
+ //Requires to be in GMT
527
+ $utime = get_gmt_from_date($time, 'U');
528
+ wp_schedule_single_event($utime, $name, [$post_id]);
529
+ update_post_meta($post_id, CAS_App::META_PREFIX.'deactivate_time', $time);
530
+ } else {
531
+ delete_post_meta($post_id, CAS_App::META_PREFIX.'deactivate_time');
532
+ }
533
+ }
534
+
535
+ /**
536
+ * Create update messages
537
+ *
538
+ * @param WP_Post $post
539
+ *
540
+ * @return void
541
+ */
542
+ public function sidebar_updated_messages($post)
543
+ {
544
+ $message_number = isset($_GET['message']) ? absint($_GET['message']) : null;
545
+
546
+ if (is_null($message_number)) {
547
+ return;
548
+ }
549
+
550
+ $manage_widgets = sprintf(' <a href="%1$s">%2$s</a>', esc_url(admin_url('widgets.php#'.CAS_App::SIDEBAR_PREFIX.$post->ID)), __('Manage widgets', 'content-aware-sidebars'));
551
+ $messages = [
552
+ 1 => __('Sidebar updated.', 'content-aware-sidebars').$manage_widgets,
553
+ 6 => __('Sidebar activated.', 'content-aware-sidebars').$manage_widgets,
554
+ 9 => sprintf(
555
+ __('Sidebar scheduled for: <strong>%1$s</strong>.', 'content-aware-sidebars'),
556
+ // translators: Publish box date format, see http://php.net/date
557
+ date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date))
558
+ ).$manage_widgets,
559
+ 10 => __('Sidebar deactivated.', 'content-aware-sidebars').$manage_widgets,
560
+ ];
561
+ $messages = apply_filters('cas/admin/messages', $messages, $post);
562
+
563
+ if (isset($messages[$message_number])) {
564
+ echo '<div id="message" class="updated notice notice-success is-dismissible"><p>'.$messages[$message_number].'</p></div>';
565
+ }
566
+ }
567
+
568
+ /**
569
+ * Set pointers for tour and enqueue script
570
+ *
571
+ * @since 3.3
572
+ * @return void
573
+ */
574
+ private function create_pointers()
575
+ {
576
+ if ($this->_tour_manager->user_has_finished_tour()) {
577
+ return;
578
+ }
579
+
580
+ $this->_tour_manager->set_pointers([
581
+ [
582
+ 'content' => sprintf(
583
+ '<h3>%s</h3>%s',
584
+ __('Get Started in 60 Seconds', 'content-aware-sidebars'),
585
+ '<p>'.__('Welcome to Content Aware Sidebars!', 'content-aware-sidebars').'</p>'.
586
+ '<p>'.__('This interactive guide will show you just how easy it is to create a widget area and control where, how, and when to display it.', 'content-aware-sidebars').'</p>'
587
+ ),
588
+ 'ref_id' => '#titlediv',
589
+ 'position' => [
590
+ 'edge' => 'top',
591
+ 'align' => 'center'
592
+ ],
593
+ 'pointerWidth' => 400,
594
+ 'next' => __('Start Quick Tour', 'content-aware-sidebars'),
595
+ 'dismiss' => __('Skip - I know what to do', 'content-aware-sidebars')
596
+ ],
597
+ [
598
+ 'content' => sprintf(
599
+ '<h3>%s</h3>%s',
600
+ '1/5 '.__('Where to display', 'content-aware-sidebars'),
601
+ '<p>'.__('Choose from the extensive Display Conditions with built-in support for other plugins. You will never be asked to enter widget logic PHP code!', 'content-aware-sidebars').'</p>'.
602
+ '<p>'.__('Select anything to continue the tour. You can change it later.', 'content-aware-sidebars').'</p>'
603
+ ),
604
+ 'ref_id' => '.cas-group-new',
605
+ 'position' => [
606
+ 'edge' => 'top',
607
+ 'align' => 'center'
608
+ ],
609
+ 'prev' => false,
610
+ 'next' => '.js-wpca-add-or, .js-wpca-add-quick',
611
+ 'nextEvent' => 'select2:select click',
612
+ 'dismiss' => false
613
+ ],
614
+ [
615
+ 'content' => sprintf(
616
+ '<h3>%s</h3>%s',
617
+ '2/5 '.__('Where to display', 'content-aware-sidebars'),
618
+ '<p>'.__('Click on the input field and select the content you want - just type to search. Changes are saved automatically!', 'content-aware-sidebars').'</p>'.
619
+ '<p>'.__('You can add multiple content types to the same group. Try e.g. "All Posts" and an Author to display on all posts written by that author.', 'content-aware-sidebars').'</p>'.
620
+ '<p>'.sprintf(__('<a href="%s" target="_blank">Learn more about AND vs OR conditions</a>', 'content-aware-sidebars'), 'https://dev.institute/docs/content-aware-sidebars/getting-started/display-sidebar-advanced/').'</p>'
621
+ ),
622
+ 'ref_id' => '#cas-groups > ul',
623
+ 'position' => [
624
+ 'edge' => 'top',
625
+ 'align' => 'center'
626
+ ],
627
+ 'dismiss' => __('Close Tour', 'content-aware-sidebars')
628
+ ],
629
+ [
630
+ 'content' => sprintf(
631
+ '<h3>%s</h3>%s',
632
+ '3/5 '.__('How to display', 'content-aware-sidebars'),
633
+ '<p>'.__('Replace any sidebar or widget area in your theme, or add widgets by merging with them.', 'content-aware-sidebars').'</p>'.
634
+ '<p>'.__('You can also use the shortcode to display widgets inside a page or post.', 'content-aware-sidebars').'</p>'
635
+ ),
636
+ 'ref_id' => '.nav-tab-wrapper.js-cas-tabs .nav-tab-section-action',
637
+ 'position' => [
638
+ 'edge' => 'left',
639
+ 'align' => 'left'
640
+ ],
641
+ 'dismiss' => __('Close Tour', 'content-aware-sidebars')
642
+ ],
643
+ [
644
+ 'content' => sprintf(
645
+ '<h3>%s</h3>%s',
646
+ '4/5 '.__('When to activate', 'content-aware-sidebars'),
647
+ '<p>'.__('Create a widget area and manage its widgets today, then publish it when you are ready.', 'content-aware-sidebars').'</p>'.
648
+ '<p>'.__('To schedule automatic activation or deactivation, just pick a date and time!', 'content-aware-sidebars').'</p>'.
649
+ '<p>'.__('By default, new widget areas will be activated when created.', 'content-aware-sidebars').'</p>'
650
+ ),
651
+ 'ref_id' => '.nav-tab-wrapper.js-cas-tabs .nav-tab-section-schedule',
652
+ 'position' => [
653
+ 'edge' => 'left',
654
+ 'align' => 'left'
655
+ ],
656
+ 'dismiss' => __('Close Tour', 'content-aware-sidebars')
657
+ ],
658
+ [
659
+ 'content' => sprintf(
660
+ '<h3>%s</h3>%s',
661
+ '5/5 '.__('How to look', 'content-aware-sidebars'),
662
+ '<p>'.__('Personalize the styling without writing any code!', 'content-aware-sidebars').'</p>'.
663
+ '<p>'.__('You can modify the HTML and CSS classes of the widget area itself, each widget, as well as widget titles.', 'content-aware-sidebars').'</p>'
664
+ ),
665
+ 'ref_id' => '.nav-tab-wrapper.js-cas-tabs .nav-tab-section-design',
666
+ 'position' => [
667
+ 'edge' => 'left',
668
+ 'align' => 'left'
669
+ ],
670
+ 'next' => __('Finish Tour', 'content-aware-sidebars')
671
+ ],
672
+ [
673
+ 'content' => sprintf(
674
+ '<h3>%s</h3>%s',
675
+ __("That's it", 'content-aware-sidebars'),
676
+ '<p>'.__('Hit the Create button to save your first custom widget area.', 'content-aware-sidebars').'</p>'.
677
+ '<p>'.__('If you need more help, check out the links below.', 'content-aware-sidebars').'</p>'
678
+ ),
679
+ 'ref_id' => '#submitdiv',
680
+ 'position' => [
681
+ 'edge' => 'right',
682
+ 'align' => 'top'
683
+ ],
684
+ 'dismiss' => __('Close', 'content-aware-sidebars')
685
+ ]
686
+ ]);
687
+ $this->_tour_manager->enqueue_scripts();
688
+ }
689
+
690
+ /**
691
+ * Meta boxes for sidebar edit
692
+ * @global object $post
693
+ * @return void
694
+ */
695
+ public function create_meta_boxes($post)
696
+ {
697
+ $this->create_pointers();
698
+ CAS_App::instance()->manager()->populate_metadata();
699
+ $path = plugin_dir_path(dirname(__FILE__)).'view/';
700
+
701
+ $cas_fs = cas_fs();
702
+
703
+ $boxes = [];
704
+ $boxes[] = [
705
+ 'id' => 'submitdiv',
706
+ 'title' => __('Publish'),
707
+ 'view' => 'submit',
708
+ 'context' => 'side',
709
+ 'priority' => 'high'
710
+ ];
711
+ $boxes[] = [
712
+ 'id' => 'cas-options',
713
+ 'title' => __('How to display', 'content-aware-sidebars'),
714
+ 'view' => 'action',
715
+ 'context' => 'section-action',
716
+ ];
717
+ $boxes[] = [
718
+ 'id' => 'cas-status',
719
+ 'title' => __('Status', 'content-aware-sidebars'),
720
+ 'view' => 'status',
721
+ 'context' => 'section-schedule',
722
+ ];
723
+ $boxes[] = [
724
+ 'id' => 'cas-widget-html',
725
+ 'title' => __('Styles', 'content-aware-sidebars'),
726
+ 'view' => 'html',
727
+ 'context' => 'section-design',
728
+ ];
729
+ $boxes[] = [
730
+ 'id' => 'cas-advanced',
731
+ 'title' => __('Options', 'content-aware-sidebars'),
732
+ 'view' => 'advanced',
733
+ 'context' => 'section-advanced',
734
+ ];
735
+ $boxes[] = [
736
+ 'id' => 'cas-plugin-links',
737
+ 'title' => __('Recommendations', 'content-aware-sidebars'),
738
+ 'view' => 'support',
739
+ 'context' => 'side',
740
+ ];
741
+ $boxes[] = [
742
+ 'id' => 'cas-schedule',
743
+ 'title' => __('Time Schedule', 'content-aware-sidebars').' <span class="cas-pro-label">'.__('Pro', 'content-aware-sidebars').'</span>',
744
+ 'view' => 'schedule',
745
+ 'context' => 'section-schedule',
746
+ ];
747
+ $boxes[] = [
748
+ 'id' => 'cas-design',
749
+ 'title' => __('Design', 'content-aware-sidebars').' <span class="cas-pro-label">'.__('Pro', 'content-aware-sidebars').'</span>',
750
+ 'view' => 'design',
751
+ 'context' => 'section-design',
752
+ ];
753
+
754
+ foreach ($boxes as $box) {
755
+ $view = WPCAView::make($path.'meta_box_'.$box['view'].'.php', [
756
+ 'post' => $post
757
+ ]);
758
+
759
+ add_meta_box(
760
+ $box['id'],
761
+ $box['title'],
762
+ [$view,'render'],
763
+ CAS_App::BASE_SCREEN.'-edit',
764
+ $box['context'],
765
+ isset($box['priority']) ? $box['priority'] : 'default'
766
+ );
767
+ }
768
+
769
+ //todo: refactor add of meta box
770
+ //with new bootstrapper, legacy core might be loaded
771
+ if (method_exists('WPCACore', 'render_group_meta_box')) {
772
+ WPCACore::render_group_meta_box($post, CAS_App::BASE_SCREEN.'-edit', 'section-conditions', 'default');
773
+ }
774
+ }
775
+
776
+ /**
777
+ * Create form field for metadata
778
+ * @global object $post
779
+ * @param array $setting
780
+ * @return void
781
+ */
782
+ public static function form_field($id, $class = '', $icon = '')
783
+ {
784
+ $setting = CAS_App::instance()->manager()->metadata()->get($id);
785
+ $current = $setting->get_data(get_the_ID(), true, $setting->get_input_type() != 'multi');
786
+ $icon = $icon ? '<span class="'.$icon.'"></span> ' : '';
787
+
788
+ echo '<div class="'.$class.'">'.$icon.'<strong>' . $setting->get_title() . '</strong>';
789
+ echo '<p>';
790
+ switch ($setting->get_input_type()) {
791
+ case 'select':
792
+ echo '<select style="width:250px;" name="' . $id . '" class="js-cas-'.$id.'">' . "\n";
793
+ foreach ($setting->get_input_list() as $key => $value) {
794
+ $disabled = '';
795
+ if (is_string($key) && strpos($key, '__') === 0) {
796
+ $disabled = ' disabled="disabled"';
797
+ }
798
+ echo '<option value="' . $key . '"' . selected($current, $key, false) . $disabled . '>' . $value . '</option>' . "\n";
799
+ }
800
+ echo '</select>' . "\n";
801
+ break;
802
+ case 'checkbox':
803
+ echo '<ul>' . "\n";
804
+ foreach ($setting->get_input_list() as $key => $value) {
805
+ echo '<li><label><input type="checkbox" name="' . $id . '[]" class="js-cas-'.$id.'" value="' . $key . '"' . (in_array($key, $current) ? ' checked="checked"' : '') . ' /> ' . $value . '</label></li>' . "\n";
806
+ }
807
+ echo '</ul>' . "\n";
808
+ break;
809
+ case 'multi':
810
+ echo '<div><select style="width:100%;" class="js-cas-'.$id.'" multiple="multiple" name="' . $id . '[]" data-value="'.implode(',', $current).'"></select></div>';
811
+ break;
812
+ case 'text':
813
+ default:
814
+ echo '<input style="width:200px;" type="text" name="' . $id . '" value="' . $current . '" />' . "\n";
815
+ break;
816
+ }
817
+ echo '</p></div>';
818
+ }
819
+
820
+ /**
821
+ * Save meta values for post
822
+ * @param int $post_id
823
+ * @return void
824
+ */
825
+ public function save_post($post_id, $post)
826
+ {
827
+
828
+ //Verify nonce, check_admin_referer dies on false
829
+ if (!(isset($_POST[WPCACore::NONCE])
830
+ && wp_verify_nonce($_POST[WPCACore::NONCE], WPCACore::PREFIX.$post_id))) {
831
+ return;
832
+ }
833
+
834
+ // Check permissions
835
+ if (!current_user_can(CAS_App::CAPABILITY, $post_id)) {
836
+ return;
837
+ }
838
+
839
+ // Check autosave
840
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
841
+ return;
842
+ }
843
+
844
+ // Save metadata
845
+ // todo: wrap this in metadata manager?
846
+ foreach (CAS_App::instance()->manager()->metadata() as $field) {
847
+ $field->save($post_id);
848
+ }
849
+ }
850
+
851
+ /**
852
+ * Add suffix when creating sidebar with existing name
853
+ * Does not stop duplicate titles on update
854
+ *
855
+ * @since 3.4.3
856
+ * @param array $insert_data
857
+ * @param array $data
858
+ * @return array
859
+ */
860
+ public function add_duplicate_title_suffix($insert_data, $data)
861
+ {
862
+ if ($data['post_type'] == CAS_App::TYPE_SIDEBAR && !$data['ID']) {
863
+ $sidebars = CAS_App::instance()->manager()->sidebars;
864
+ $sidebar_titles = [];
865
+ foreach ($sidebars as $sidebar) {
866
+ $sidebar_titles[$sidebar->post_title] = 1;
867
+ }
868
+ //if title exists, add a suffix
869
+ $i = 0;
870
+ $title = wp_unslash($insert_data['post_title']);
871
+ $new_title = $title;
872
+ while (isset($sidebar_titles[$new_title])) {
873
+ $new_title = $title.' ('.++$i.')';
874
+ }
875
+ if ($i) {
876
+ $insert_data['post_title'] = wp_slash($new_title);
877
+ }
878
+ }
879
+ return $insert_data;
880
+ }
881
+
882
+ /**
883
+ * Remove widget when its sidebar is removed
884
+ * @param int $post_id
885
+ * @return void
886
+ */
887
+ public function remove_sidebar_widgets($post_id)
888
+ {
889
+
890
+ // Authenticate and only continue on sidebar post type
891
+ if (!current_user_can(CAS_App::CAPABILITY) || get_post_type($post_id) != CAS_App::TYPE_SIDEBAR) {
892
+ return;
893
+ }
894
+
895
+ $id = CAS_App::SIDEBAR_PREFIX . $post_id;
896
+
897
+ //Get widgets
898
+ $sidebars_widgets = wp_get_sidebars_widgets();
899
+
900
+ // Check if sidebar exists in database
901
+ if (!isset($sidebars_widgets[$id])) {
902
+ return;
903
+ }
904
+
905
+ // Remove widgets settings from sidebar
906
+ foreach ($sidebars_widgets[$id] as $widget_id) {
907
+ $widget_type = preg_replace('/-[0-9]+$/', '', $widget_id);
908
+ $widget_settings = get_option('widget_' . $widget_type);
909
+ $widget_id = substr($widget_id, strpos($widget_id, '-') + 1);
910
+ if ($widget_settings && isset($widget_settings[$widget_id])) {
911
+ unset($widget_settings[$widget_id]);
912
+ update_option('widget_' . $widget_type, $widget_settings);
913
+ }
914
+ }
915
+
916
+ // Remove sidebar
917
+ unset($sidebars_widgets[$id]);
918
+ wp_set_sidebars_widgets($sidebars_widgets);
919
+ }
920
+
921
+ /**
922
+ * Register and enqueue scripts styles
923
+ * for screen
924
+ *
925
+ * @since 3.4
926
+ */
927
+ public function add_scripts_styles()
928
+ {
929
+ if (is_multisite()) {
930
+ add_action('admin_footer', '_admin_notice_post_locked');
931
+ } else {
932
+ $check_users = get_users([ 'fields' => 'ID', 'number' => 2 ]);
933
+ if (count($check_users) > 1) {
934
+ add_action('admin_footer', '_admin_notice_post_locked');
935
+ }
936
+ }
937
+
938
+ wp_enqueue_script('wp-a11y');
939
+
940
+ if (wp_is_mobile()) {
941
+ wp_enqueue_script('jquery-touch-punch');
942
+ }
943
+
944
+ WPCACore::enqueue_scripts_styles('');
945
+
946
+ $this->register_script('flatpickr', 'flatpickr', [], '3.0.6');
947
+ $this->register_script('cas/admin/edit', 'cas_admin', ['jquery','flatpickr','wp-color-picker']);
948
+
949
+ $this->enqueue_style('flatpickr', 'flatpickr.dark.min', [], '3.0.6');
950
+ wp_enqueue_style('wp-color-picker');
951
+
952
+ $metadata = CAS_App::instance()->_manager->metadata();
953
+ $visibility = [];
954
+ $target = [];
955
+ foreach ($metadata->get('visibility')->get_input_list() as $category_key => $category) {
956
+
957
+ //legacy format
958
+ if (!is_array($category)) {
959
+ $visibility[] = [
960
+ 'id' => $category_key,
961
+ 'text' => $category
962
+ ];
963
+ continue;
964
+ }
965
+
966
+ $data = [
967
+ 'text' => $category['label'],
968
+ 'children' => []
969
+ ];
970
+ foreach ($category['options'] as $key => $value) {
971
+ $data['children'][] = [
972
+ 'id' => $key,
973
+ 'text' => $value
974
+ ];
975
+ }
976
+ $visibility[] = $data;
977
+ }
978
+ foreach ($metadata->get('host')->get_input_list() as $value => $label) {
979
+ $target[] = [
980
+ 'id' => $value,
981
+ 'text' => $label
982
+ ];
983
+ }
984
+
985
+ if (!cas_fs()->can_use_premium_code()) {
986
+ $visibility[] = [
987
+ 'text' => __('Upgrade to Pro for more options', 'content-aware-sidebars'),
988
+ 'children' => []
989
+ ];
990
+ }
991
+
992
+ global $wp_locale;
993
+
994
+ wp_enqueue_script('cas/admin/edit');
995
+ wp_localize_script('cas/admin/edit', 'CASAdmin', [
996
+ 'allVisibility' => __('All Users', 'content-aware-sidebars'),
997
+ 'visibility' => $visibility,
998
+ 'target' => $target,
999
+ 'weekdays' => [
1000
+ 'shorthand' => array_values($wp_locale->weekday_abbrev),
1001
+ 'longhand' => array_values($wp_locale->weekday)
1002
+ ],
1003
+ 'months' => [
1004
+ 'shorthand' => array_values($wp_locale->month_abbrev),
1005
+ 'longhand' => array_values($wp_locale->month)
1006
+ ],
1007
+ 'weekStart' => get_option('start_of_week', 0),
1008
+ 'timeFormat' => get_option('time_format'),
1009
+ 'dateFormat' => __('F j, Y') //default long date
1010
+ ]);
1011
+
1012
+ //badgeos compat
1013
+ //todo: check that developers respond with a fix soon
1014
+ wp_register_script('badgeos-select2', '');
1015
+ wp_register_style('badgeos-select2-css', '');
1016
+ }
1017
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/sidebar-list-table.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -21,16 +21,16 @@ class CAS_Sidebar_List_Table extends WP_List_Table
21
  */
22
  private $is_trash;
23
 
24
- private $visibility = array();
25
 
26
- public function __construct($args = array())
27
  {
28
- parent::__construct(array(
29
  'singular' => 'sidebar',
30
  'plural' => 'sidebars',
31
  'ajax' => false,
32
  'screen' => isset($args['screen']) ? $args['screen'] : null
33
- ));
34
  }
35
 
36
  /**
@@ -50,19 +50,19 @@ class CAS_Sidebar_List_Table extends WP_List_Table
50
  $per_page = $this->get_items_per_page('cas_sidebars_per_page', 20);
51
  $current_page = $this->get_pagenum();
52
 
53
- $args = array(
54
  'post_type' => CAS_App::TYPE_SIDEBAR,
55
- 'post_status' => array(
56
  CAS_App::STATUS_ACTIVE,
57
  CAS_App::STATUS_INACTIVE,
58
  CAS_App::STATUS_SCHEDULED
59
- ),
60
  'posts_per_page' => $per_page,
61
  'paged' => $current_page,
62
  'orderby' => 'title',
63
  'order' => 'asc',
64
  'update_post_term_cache' => false
65
- );
66
 
67
  if (isset($_REQUEST['s']) && strlen($_REQUEST['s'])) {
68
  $args['s'] = $_REQUEST['s'];
@@ -100,7 +100,7 @@ class CAS_Sidebar_List_Table extends WP_List_Table
100
  $total_items = array_sum($post_counts);
101
 
102
  // Subtract post types that are not included in the admin all list.
103
- foreach (get_post_stati(array( 'show_in_admin_all_list' => false )) as $state) {
104
  $total_items -= $post_counts[ $state ];
105
  }
106
  }
@@ -108,11 +108,11 @@ class CAS_Sidebar_List_Table extends WP_List_Table
108
 
109
  $this->items = $wp_query->posts;
110
  $this->is_trash = isset($_REQUEST['post_status']) && $_REQUEST['post_status'] == 'trash';
111
- $this->set_pagination_args(array(
112
  'total_items' => $total_items,
113
  'total_pages' => ceil($total_items / $per_page),
114
  'per_page' => $per_page
115
- ));
116
 
117
  //Make sure filter is run
118
  CAS_App::instance()->manager()->populate_metadata();
@@ -176,16 +176,16 @@ class CAS_Sidebar_List_Table extends WP_List_Table
176
  global $locked_post_status, $avail_post_stati;
177
 
178
  if (!empty($locked_post_status)) {
179
- return array();
180
  }
181
 
182
- $status_links = array();
183
  $num_posts = wp_count_posts(CAS_App::TYPE_SIDEBAR); //do not include private
184
  $total_posts = array_sum((array) $num_posts);
185
  $class = '';
186
 
187
  // Subtract post types that are not included in the admin all list.
188
- foreach (get_post_stati(array( 'show_in_admin_all_list' => false )) as $state) {
189
  $total_posts -= $num_posts->$state;
190
  }
191
 
@@ -204,15 +204,15 @@ class CAS_Sidebar_List_Table extends WP_List_Table
204
  number_format_i18n($total_posts)
205
  );
206
 
207
- $status_links['all'] = $this->get_view_link(array(), $all_inner_html, $class);
208
 
209
  //no way to change post status per post type, replace here instead
210
- $label_replacement = array(
211
  CAS_App::STATUS_ACTIVE => _n_noop('Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'content-aware-sidebars'),
212
  CAS_App::STATUS_INACTIVE => _n_noop('Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'content-aware-sidebars')
213
- );
214
 
215
- foreach (get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status) {
216
  $class = '';
217
 
218
  $status_name = $status->name;
@@ -225,9 +225,9 @@ class CAS_Sidebar_List_Table extends WP_List_Table
225
  $class = 'current';
226
  }
227
 
228
- $status_args = array(
229
  'post_status' => $status_name
230
- );
231
 
232
  $label_count = $status->label_count;
233
  if (isset($label_replacement[$status->name])) {
@@ -253,7 +253,7 @@ class CAS_Sidebar_List_Table extends WP_List_Table
253
  */
254
  public function get_bulk_actions()
255
  {
256
- $actions = array();
257
  $post_type_obj = get_post_type_object(CAS_App::TYPE_SIDEBAR);
258
 
259
  if (current_user_can($post_type_obj->cap->edit_posts)) {
@@ -316,7 +316,7 @@ class CAS_Sidebar_List_Table extends WP_List_Table
316
  */
317
  public function get_columns()
318
  {
319
- $posts_columns = array();
320
  $posts_columns['cb'] = '<input type="checkbox" />';
321
  $posts_columns['title'] = _x('Title', 'column name');
322
  $posts_columns['handler'] = _x('Action', 'option', 'content-aware-sidebars');
@@ -335,11 +335,11 @@ class CAS_Sidebar_List_Table extends WP_List_Table
335
  */
336
  public function get_sortable_columns()
337
  {
338
- $columns = array(
339
- 'title' => array('title', true),
340
  'status' => 'post_status',
341
  'handler' => 'meta_handle'
342
- );
343
  return $columns;
344
  }
345
 
@@ -363,7 +363,7 @@ class CAS_Sidebar_List_Table extends WP_List_Table
363
  */
364
  public function get_table_classes()
365
  {
366
- return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
367
  }
368
 
369
  /**
@@ -465,27 +465,29 @@ class CAS_Sidebar_List_Table extends WP_List_Table
465
  case 1:
466
  case 3:
467
  $return = $action->get_list_data($post->ID);
 
468
  $hosts = $metadata->get('host')->get_data($post->ID, false, false);
469
  if ($hosts) {
470
  $list = $metadata->get('host')->get_input_list();
471
- $data = [];
472
  foreach ($hosts as $host) {
473
- if (!isset($list[$host])) {
474
- $data[] = '<span style="color:red;">' . __('Target not found', 'content-aware-sidebars') . '</span>';
475
- } else {
476
  $data[] = $list[$host];
477
  }
478
  }
479
- $return .= ':<br> ' . implode(', ', $data);
480
  }
 
 
 
 
 
481
 
482
  if ($action->get_data($post->ID) == 1) {
483
  $pos = $metadata->get('merge_pos')->get_data($post->ID, true);
484
  $pos_icon = $pos ? 'up' : 'down';
485
- $pos_title = array(
486
  __('Add sidebar at the top during merge', 'content-aware-sidebars'),
487
  __('Add sidebar at the bottom during merge', 'content-aware-sidebars')
488
- );
489
  $return .= '<span title="'.$pos_title[$pos].'" class="dashicons dashicons-arrow-'.$pos_icon.'-alt"></span>';
490
  }
491
  echo $return;
@@ -652,7 +654,7 @@ class CAS_Sidebar_List_Table extends WP_List_Table
652
  }
653
 
654
  $post_type_object = get_post_type_object($post->post_type);
655
- $actions = array();
656
  $title = _draft_or_post_title();
657
  $cas_fs = cas_fs();
658
 
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
21
  */
22
  private $is_trash;
23
 
24
+ private $visibility = [];
25
 
26
+ public function __construct($args = [])
27
  {
28
+ parent::__construct([
29
  'singular' => 'sidebar',
30
  'plural' => 'sidebars',
31
  'ajax' => false,
32
  'screen' => isset($args['screen']) ? $args['screen'] : null
33
+ ]);
34
  }
35
 
36
  /**
50
  $per_page = $this->get_items_per_page('cas_sidebars_per_page', 20);
51
  $current_page = $this->get_pagenum();
52
 
53
+ $args = [
54
  'post_type' => CAS_App::TYPE_SIDEBAR,
55
+ 'post_status' => [
56
  CAS_App::STATUS_ACTIVE,
57
  CAS_App::STATUS_INACTIVE,
58
  CAS_App::STATUS_SCHEDULED
59
+ ],
60
  'posts_per_page' => $per_page,
61
  'paged' => $current_page,
62
  'orderby' => 'title',
63
  'order' => 'asc',
64
  'update_post_term_cache' => false
65
+ ];
66
 
67
  if (isset($_REQUEST['s']) && strlen($_REQUEST['s'])) {
68
  $args['s'] = $_REQUEST['s'];
100
  $total_items = array_sum($post_counts);
101
 
102
  // Subtract post types that are not included in the admin all list.
103
+ foreach (get_post_stati([ 'show_in_admin_all_list' => false ]) as $state) {
104
  $total_items -= $post_counts[ $state ];
105
  }
106
  }
108
 
109
  $this->items = $wp_query->posts;
110
  $this->is_trash = isset($_REQUEST['post_status']) && $_REQUEST['post_status'] == 'trash';
111
+ $this->set_pagination_args([
112
  'total_items' => $total_items,
113
  'total_pages' => ceil($total_items / $per_page),
114
  'per_page' => $per_page
115
+ ]);
116
 
117
  //Make sure filter is run
118
  CAS_App::instance()->manager()->populate_metadata();
176
  global $locked_post_status, $avail_post_stati;
177
 
178
  if (!empty($locked_post_status)) {
179
+ return [];
180
  }
181
 
182
+ $status_links = [];
183
  $num_posts = wp_count_posts(CAS_App::TYPE_SIDEBAR); //do not include private
184
  $total_posts = array_sum((array) $num_posts);
185
  $class = '';
186
 
187
  // Subtract post types that are not included in the admin all list.
188
+ foreach (get_post_stati([ 'show_in_admin_all_list' => false ]) as $state) {
189
  $total_posts -= $num_posts->$state;
190
  }
191
 
204
  number_format_i18n($total_posts)
205
  );
206
 
207
+ $status_links['all'] = $this->get_view_link([], $all_inner_html, $class);
208
 
209
  //no way to change post status per post type, replace here instead
210
+ $label_replacement = [
211
  CAS_App::STATUS_ACTIVE => _n_noop('Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'content-aware-sidebars'),
212
  CAS_App::STATUS_INACTIVE => _n_noop('Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'content-aware-sidebars')
213
+ ];
214
 
215
+ foreach (get_post_stati(['show_in_admin_status_list' => true], 'objects') as $status) {
216
  $class = '';
217
 
218
  $status_name = $status->name;
225
  $class = 'current';
226
  }
227
 
228
+ $status_args = [
229
  'post_status' => $status_name
230
+ ];
231
 
232
  $label_count = $status->label_count;
233
  if (isset($label_replacement[$status->name])) {
253
  */
254
  public function get_bulk_actions()
255
  {
256
+ $actions = [];
257
  $post_type_obj = get_post_type_object(CAS_App::TYPE_SIDEBAR);
258
 
259
  if (current_user_can($post_type_obj->cap->edit_posts)) {
316
  */
317
  public function get_columns()
318
  {
319
+ $posts_columns = [];
320
  $posts_columns['cb'] = '<input type="checkbox" />';
321
  $posts_columns['title'] = _x('Title', 'column name');
322
  $posts_columns['handler'] = _x('Action', 'option', 'content-aware-sidebars');
335
  */
336
  public function get_sortable_columns()
337
  {
338
+ $columns = [
339
+ 'title' => ['title', true],
340
  'status' => 'post_status',
341
  'handler' => 'meta_handle'
342
+ ];
343
  return $columns;
344
  }
345
 
363
  */
364
  public function get_table_classes()
365
  {
366
+ return [ 'widefat', 'fixed', 'striped', $this->_args['plural'] ];
367
  }
368
 
369
  /**
465
  case 1:
466
  case 3:
467
  $return = $action->get_list_data($post->ID);
468
+ $data = [];
469
  $hosts = $metadata->get('host')->get_data($post->ID, false, false);
470
  if ($hosts) {
471
  $list = $metadata->get('host')->get_input_list();
 
472
  foreach ($hosts as $host) {
473
+ if (isset($list[$host])) {
 
 
474
  $data[] = $list[$host];
475
  }
476
  }
 
477
  }
478
+
479
+ if (empty($data)) {
480
+ $data[] = '<span style="color:red;">' . __('Target not found', 'content-aware-sidebars') . '</span>';
481
+ }
482
+ $return .= ':<br> ' . implode(', ', $data);
483
 
484
  if ($action->get_data($post->ID) == 1) {
485
  $pos = $metadata->get('merge_pos')->get_data($post->ID, true);
486
  $pos_icon = $pos ? 'up' : 'down';
487
+ $pos_title = [
488
  __('Add sidebar at the top during merge', 'content-aware-sidebars'),
489
  __('Add sidebar at the bottom during merge', 'content-aware-sidebars')
490
+ ];
491
  $return .= '<span title="'.$pos_title[$pos].'" class="dashicons dashicons-arrow-'.$pos_icon.'-alt"></span>';
492
  }
493
  echo $return;
654
  }
655
 
656
  $post_type_object = get_post_type_object($post->post_type);
657
+ $actions = [];
658
  $title = _draft_or_post_title();
659
  $cas_fs = cas_fs();
660
 
admin/sidebar-overview.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -40,13 +40,15 @@ final class CAS_Sidebar_Overview extends CAS_Admin
40
  global $_wp_last_object_menu;
41
 
42
  $post_type_object = get_post_type_object(CAS_App::TYPE_SIDEBAR);
 
 
43
 
44
  add_menu_page(
45
  $post_type_object->labels->name,
46
- __('Content Aware', 'content-aware-sidebars'),
47
  $post_type_object->cap->edit_posts,
48
  CAS_App::BASE_SCREEN,
49
- array($this,'render_screen'),
50
  $post_type_object->menu_icon,
51
  ++$_wp_last_object_menu
52
  );
@@ -57,7 +59,7 @@ final class CAS_Sidebar_Overview extends CAS_Admin
57
  $post_type_object->labels->all_items,
58
  $post_type_object->cap->edit_posts,
59
  CAS_App::BASE_SCREEN,
60
- array($this,'render_screen')
61
  );
62
  }
63
 
@@ -78,10 +80,10 @@ final class CAS_Sidebar_Overview extends CAS_Admin
78
  */
79
  public function prepare_screen()
80
  {
81
- add_screen_option('per_page', array(
82
  'default' => 20,
83
  'option' => 'cas_sidebars_per_page'
84
- ));
85
 
86
  $this->table = new CAS_Sidebar_List_Table();
87
  $this->process_actions();//todo:add func to table to actions
@@ -117,7 +119,7 @@ final class CAS_Sidebar_Overview extends CAS_Admin
117
 
118
  $this->bulk_messages();
119
 
120
- $_SERVER['REQUEST_URI'] = remove_query_arg(array( 'locked', 'skipped', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI']);
121
 
122
  $this->table->views();
123
 
@@ -149,7 +151,7 @@ final class CAS_Sidebar_Overview extends CAS_Admin
149
 
150
  $pagenum = $this->table->get_pagenum();
151
 
152
- $sendback = remove_query_arg(array('activated','deactivated','trashed', 'untrashed', 'deleted', 'locked', 'ids'), wp_get_referer());
153
  $sendback = add_query_arg('paged', $pagenum, $sendback);
154
 
155
  if ('delete_all' == $doaction) {
@@ -187,17 +189,17 @@ final class CAS_Sidebar_Overview extends CAS_Admin
187
  }
188
 
189
  if ($doaction == 'activate') {
190
- $data = array(
191
  'ID' => $post_id,
192
  'post_status' => CAS_App::STATUS_ACTIVE,
193
  'post_date' => current_time('mysql'),
194
  'post_date_gmt' => current_time('mysql', true)
195
- );
196
  } else {
197
- $data = array(
198
  'ID' => $post_id,
199
  'post_status' => CAS_App::STATUS_INACTIVE
200
- );
201
  }
202
 
203
  if (!wp_update_post($data)) {
@@ -206,7 +208,7 @@ final class CAS_Sidebar_Overview extends CAS_Admin
206
 
207
  $handled++;
208
  }
209
- $sendback = add_query_arg(array($doaction.'d' => $handled, 'ids' => join(',', $post_ids), 'locked' => $locked ), $sendback);
210
  break;
211
  case 'trash':
212
  $locked = 0;
@@ -228,7 +230,7 @@ final class CAS_Sidebar_Overview extends CAS_Admin
228
  $handled++;
229
  }
230
 
231
- $sendback = add_query_arg(array('trashed' => $handled, 'ids' => join(',', $post_ids), 'locked' => $locked ), $sendback);
232
  break;
233
  case 'untrash':
234
  foreach ($post_ids as $post_id) {
@@ -261,13 +263,13 @@ final class CAS_Sidebar_Overview extends CAS_Admin
261
  break;
262
  }
263
 
264
- $sendback = remove_query_arg(array('action', 'action2', 'post_status', 'post', 'bulk_edit'), $sendback);
265
 
266
  wp_safe_redirect($sendback);
267
  exit;
268
  }
269
  if (! empty($_REQUEST['_wp_http_referer'])) {
270
- wp_safe_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI'])));
271
  exit;
272
  }
273
  }
@@ -291,7 +293,7 @@ final class CAS_Sidebar_Overview extends CAS_Admin
291
  public function bulk_messages()
292
  {
293
  $manage_widgets = sprintf(' <a href="%1$s">%2$s</a>', 'widgets.php', __('Manage widgets', 'content-aware-sidebars'));
294
- $bulk_messages = array(
295
  'updated' => _n_noop('%s sidebar updated.', '%s sidebars updated.', 'content-aware-sidebars'),
296
  'locked' => _n_noop('%s sidebar not updated, somebody is editing it.', '%s sidebars not updated, somebody is editing them.', 'content-aware-sidebars'),
297
  'activated' => _n_noop('%s sidebar activated.', '%s sidebars activated.', 'content-aware-sidebars'),
@@ -299,10 +301,10 @@ final class CAS_Sidebar_Overview extends CAS_Admin
299
  'deleted' => _n_noop('%s sidebar permanently deleted.', '%s sidebars permanently deleted.', 'content-aware-sidebars'),
300
  'trashed' => _n_noop('%s sidebar moved to the Trash.', '%s sidebars moved to the Trash.', 'content-aware-sidebars'),
301
  'untrashed' => _n_noop('%s sidebar restored from the Trash.', '%s sidebars restored from the Trash.', 'content-aware-sidebars'),
302
- );
303
  $bulk_messages = apply_filters('cas/admin/bulk_messages', $bulk_messages);
304
 
305
- $messages = array();
306
  foreach ($bulk_messages as $key => $message) {
307
  if (isset($_REQUEST[$key])) {
308
  $count = absint($_REQUEST[$key]);
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
40
  global $_wp_last_object_menu;
41
 
42
  $post_type_object = get_post_type_object(CAS_App::TYPE_SIDEBAR);
43
+
44
+ $notification_label = $this->notification_count ? sprintf(' <span class="awaiting-mod">%d</span>', $this->notification_count) : '';
45
 
46
  add_menu_page(
47
  $post_type_object->labels->name,
48
+ __('Content Aware', 'content-aware-sidebars') . $notification_label,
49
  $post_type_object->cap->edit_posts,
50
  CAS_App::BASE_SCREEN,
51
+ [$this,'render_screen'],
52
  $post_type_object->menu_icon,
53
  ++$_wp_last_object_menu
54
  );
59
  $post_type_object->labels->all_items,
60
  $post_type_object->cap->edit_posts,
61
  CAS_App::BASE_SCREEN,
62
+ [$this,'render_screen']
63
  );
64
  }
65
 
80
  */
81
  public function prepare_screen()
82
  {
83
+ add_screen_option('per_page', [
84
  'default' => 20,
85
  'option' => 'cas_sidebars_per_page'
86
+ ]);
87
 
88
  $this->table = new CAS_Sidebar_List_Table();
89
  $this->process_actions();//todo:add func to table to actions
119
 
120
  $this->bulk_messages();
121
 
122
+ $_SERVER['REQUEST_URI'] = remove_query_arg([ 'locked', 'skipped', 'deleted', 'trashed', 'untrashed' ], $_SERVER['REQUEST_URI']);
123
 
124
  $this->table->views();
125
 
151
 
152
  $pagenum = $this->table->get_pagenum();
153
 
154
+ $sendback = remove_query_arg(['activated','deactivated','trashed', 'untrashed', 'deleted', 'locked', 'ids'], wp_get_referer());
155
  $sendback = add_query_arg('paged', $pagenum, $sendback);
156
 
157
  if ('delete_all' == $doaction) {
189
  }
190
 
191
  if ($doaction == 'activate') {
192
+ $data = [
193
  'ID' => $post_id,
194
  'post_status' => CAS_App::STATUS_ACTIVE,
195
  'post_date' => current_time('mysql'),
196
  'post_date_gmt' => current_time('mysql', true)
197
+ ];
198
  } else {
199
+ $data = [
200
  'ID' => $post_id,
201
  'post_status' => CAS_App::STATUS_INACTIVE
202
+ ];
203
  }
204
 
205
  if (!wp_update_post($data)) {
208
 
209
  $handled++;
210
  }
211
+ $sendback = add_query_arg([$doaction.'d' => $handled, 'ids' => join(',', $post_ids), 'locked' => $locked ], $sendback);
212
  break;
213
  case 'trash':
214
  $locked = 0;
230
  $handled++;
231
  }
232
 
233
+ $sendback = add_query_arg(['trashed' => $handled, 'ids' => join(',', $post_ids), 'locked' => $locked ], $sendback);
234
  break;
235
  case 'untrash':
236
  foreach ($post_ids as $post_id) {
263
  break;
264
  }
265
 
266
+ $sendback = remove_query_arg(['action', 'action2', 'post_status', 'post', 'bulk_edit'], $sendback);
267
 
268
  wp_safe_redirect($sendback);
269
  exit;
270
  }
271
  if (! empty($_REQUEST['_wp_http_referer'])) {
272
+ wp_safe_redirect(remove_query_arg(['_wp_http_referer', '_wpnonce'], wp_unslash($_SERVER['REQUEST_URI'])));
273
  exit;
274
  }
275
  }
293
  public function bulk_messages()
294
  {
295
  $manage_widgets = sprintf(' <a href="%1$s">%2$s</a>', 'widgets.php', __('Manage widgets', 'content-aware-sidebars'));
296
+ $bulk_messages = [
297
  'updated' => _n_noop('%s sidebar updated.', '%s sidebars updated.', 'content-aware-sidebars'),
298
  'locked' => _n_noop('%s sidebar not updated, somebody is editing it.', '%s sidebars not updated, somebody is editing them.', 'content-aware-sidebars'),
299
  'activated' => _n_noop('%s sidebar activated.', '%s sidebars activated.', 'content-aware-sidebars'),
301
  'deleted' => _n_noop('%s sidebar permanently deleted.', '%s sidebars permanently deleted.', 'content-aware-sidebars'),
302
  'trashed' => _n_noop('%s sidebar moved to the Trash.', '%s sidebars moved to the Trash.', 'content-aware-sidebars'),
303
  'untrashed' => _n_noop('%s sidebar restored from the Trash.', '%s sidebars restored from the Trash.', 'content-aware-sidebars'),
304
+ ];
305
  $bulk_messages = apply_filters('cas/admin/bulk_messages', $bulk_messages);
306
 
307
+ $messages = [];
308
  foreach ($bulk_messages as $key => $message) {
309
  if (isset($_REQUEST[$key])) {
310
  $count = absint($_REQUEST[$key]);
app.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -11,7 +11,7 @@ defined('ABSPATH') || exit;
11
  final class CAS_App
12
  {
13
  const PLUGIN_VERSION_KEY = 'cas_db_version';
14
- const PLUGIN_VERSION = '3.14.1';
15
 
16
  /**
17
  * Prefix for sidebar id
@@ -82,6 +82,8 @@ final class CAS_App
82
  new CAS_Sidebar_Edit();
83
  new CAS_Quick_Select();
84
  new CAS_Admin_Screen_Widgets();
 
 
85
  }
86
 
87
  $this->add_actions();
@@ -112,26 +114,39 @@ final class CAS_App
112
  {
113
  add_action(
114
  'init',
115
- array($this,'load_textdomain')
116
- );
117
- add_action(
118
- 'admin_bar_menu',
119
- array($this,'admin_bar_menu'),
120
- 99
121
  );
122
  add_action(
123
  'cas/event/deactivate',
124
- array($this,'scheduled_deactivation')
125
  );
126
 
127
  if (is_admin()) {
128
  add_action(
129
  'plugins_loaded',
130
- array($this,'redirect_revision_link')
 
 
 
 
 
131
  );
132
  }
133
  }
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  /**
136
  * Add filters to queues
137
  *
@@ -144,7 +159,7 @@ final class CAS_App
144
  $file = plugin_basename(plugin_dir_path(__FILE__)).'/content-aware-sidebars.php';
145
  add_filter(
146
  'plugin_action_links_'.$file,
147
- array($this,'plugin_action_links'),
148
  99,
149
  4
150
  );
@@ -152,7 +167,7 @@ final class CAS_App
152
  * gutenberg disables widgets screen without user consent,
153
  * reenable by popular demand for now
154
  */
155
- add_filter('gutenberg_use_widgets_block_editor','__return_false');
156
  }
157
  }
158
 
@@ -167,26 +182,6 @@ final class CAS_App
167
  load_plugin_textdomain('content-aware-sidebars', false, dirname(plugin_basename(__FILE__)).'/lang/');
168
  }
169
 
170
- /**
171
- * Add admin bar link to create sidebars
172
- *
173
- * @since 3.4
174
- * @param [type] $wp_admin_bar
175
- * @return void
176
- */
177
- public function admin_bar_menu($wp_admin_bar)
178
- {
179
- $post_type = get_post_type_object(self::TYPE_SIDEBAR);
180
- if (current_user_can($post_type->cap->create_posts)) {
181
- $wp_admin_bar->add_menu(array(
182
- 'parent' => 'new-content',
183
- 'id' => self::BASE_SCREEN,
184
- 'title' => $post_type->labels->singular_name,
185
- 'href' => admin_url('admin.php?page=wpcas-edit')
186
- ));
187
- }
188
- }
189
-
190
  /**
191
  * Add actions to plugin in Plugins screen
192
  *
@@ -201,7 +196,7 @@ final class CAS_App
201
  {
202
  global $cas_fs;
203
 
204
- $new_actions = array();
205
 
206
  $new_actions['docs'] = '<a href="https://dev.institute/docs/content-aware-sidebars/?utm_source=plugin&utm_medium=referral&utm_content=plugin-list&utm_campaign=cas" target="_blank">'.__('Docs & FAQ', 'content-aware-sidebars').'</a>';
207
  $new_actions['support'] = '<a href="'.esc_url($cas_fs->contact_url()).'">'.__('Premium Support', 'content-aware-sidebars').'</a>';
@@ -224,10 +219,10 @@ final class CAS_App
224
  */
225
  public function scheduled_deactivation($post_id)
226
  {
227
- $success = wp_update_post(array(
228
  'ID' => $post_id,
229
  'post_status' => self::STATUS_INACTIVE
230
- ));
231
  if ($success) {
232
  delete_post_meta($post_id, self::META_PREFIX.'deactivate_time');
233
  }
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
11
  final class CAS_App
12
  {
13
  const PLUGIN_VERSION_KEY = 'cas_db_version';
14
+ const PLUGIN_VERSION = '3.15';
15
 
16
  /**
17
  * Prefix for sidebar id
82
  new CAS_Sidebar_Edit();
83
  new CAS_Quick_Select();
84
  new CAS_Admin_Screen_Widgets();
85
+ } else {
86
+ new CAS_Admin_Bar();
87
  }
88
 
89
  $this->add_actions();
114
  {
115
  add_action(
116
  'init',
117
+ [$this,'load_textdomain']
 
 
 
 
 
118
  );
119
  add_action(
120
  'cas/event/deactivate',
121
+ [$this,'scheduled_deactivation']
122
  );
123
 
124
  if (is_admin()) {
125
  add_action(
126
  'plugins_loaded',
127
+ [$this,'redirect_revision_link']
128
+ );
129
+ add_action(
130
+ 'admin_menu',
131
+ [$this, 'admin_menu_upsell'],
132
+ 999
133
  );
134
  }
135
  }
136
 
137
+ public function admin_menu_upsell()
138
+ {
139
+ $cas_fs = cas_fs();
140
+ if (!$cas_fs->can_use_premium_code()) {
141
+ global $submenu;
142
+ $submenu['wpcas'][] = [
143
+ __('Widget Cleaner', 'content-aware-sidebars'). ' (Pro)',
144
+ CAS_App::CAPABILITY,
145
+ $cas_fs->get_upgrade_url()
146
+ ];
147
+ }
148
+ }
149
+
150
  /**
151
  * Add filters to queues
152
  *
159
  $file = plugin_basename(plugin_dir_path(__FILE__)).'/content-aware-sidebars.php';
160
  add_filter(
161
  'plugin_action_links_'.$file,
162
+ [$this,'plugin_action_links'],
163
  99,
164
  4
165
  );
167
  * gutenberg disables widgets screen without user consent,
168
  * reenable by popular demand for now
169
  */
170
+ add_filter('gutenberg_use_widgets_block_editor', '__return_false');
171
  }
172
  }
173
 
182
  load_plugin_textdomain('content-aware-sidebars', false, dirname(plugin_basename(__FILE__)).'/lang/');
183
  }
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  /**
186
  * Add actions to plugin in Plugins screen
187
  *
196
  {
197
  global $cas_fs;
198
 
199
+ $new_actions = [];
200
 
201
  $new_actions['docs'] = '<a href="https://dev.institute/docs/content-aware-sidebars/?utm_source=plugin&utm_medium=referral&utm_content=plugin-list&utm_campaign=cas" target="_blank">'.__('Docs & FAQ', 'content-aware-sidebars').'</a>';
202
  $new_actions['support'] = '<a href="'.esc_url($cas_fs->contact_url()).'">'.__('Premium Support', 'content-aware-sidebars').'</a>';
219
  */
220
  public function scheduled_deactivation($post_id)
221
  {
222
+ $success = wp_update_post([
223
  'ID' => $post_id,
224
  'post_status' => self::STATUS_INACTIVE
225
+ ]);
226
  if ($success) {
227
  delete_post_meta($post_id, self::META_PREFIX.'deactivate_time');
228
  }
assets/css/style.css CHANGED
@@ -2,5 +2,5 @@
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
- * @copyright 2020 by Joachim Jensen
6
- */#cas-rules .cas-heart{color:#ac170a}body.js .js-cas-visibility{max-height:30px;overflow:hidden}.cas-section,.js-cas-action{display:none}.nav-tab-wrapper.js-cas-tabs .nav-tab{position:relative}.nav-tab-active:focus{box-shadow:none}.cas-input-inline{display:inline-block}.cas-input-sm{max-width:80px;font-size:.8em;vertical-align:middle}.cas-metabox-holder .hndle{cursor:auto!important}#submitdiv .handlediv,#submitdiv .hndle,#submitdiv .postbox-header,.cas-metabox-holder .handle-actions,.cas-metabox-holder .handlediv{display:none!important}#submitdiv .cas-save{background:#f5f5f5;border-bottom:1px solid #ddd;overflow:hidden;padding:7px 10px}#submitdiv .cas-overview-actions{padding:0 10px}#submitdiv .cas-overview-actions .dashicons{color:#82878c}#submitdiv .cas-overview-actions>li{margin:0}#submitdiv .cas-overview-actions>li:not(:last-of-type){padding:0 0 10px;margin:0 0 10px;border-bottom:1px solid #eee}.cas-pro-label{font-size:.8em;background-color:#31c455;border-radius:5px;color:#fff;padding:2px 6px;text-transform:uppercase;vertical-align:baseline;white-space:nowrap;font-weight:700}.button.button-cas-delete{color:#fff;text-decoration:none;background-color:#a00;border:1px solid #000}.button.button-cas-delete:hover{color:#fff;background-color:red}a.cas-delete{color:#a00;text-decoration:none}a.cas-delete:hover{color:red}.cas-schedule-slide.ui-slider{position:relative;margin:12px;border-radius:4px;background:#c5c5c5;color:#333}.cas-schedule-slide.ui-slider .ui-slider-handle{position:absolute;z-index:2;height:24px;width:24px;touch-action:none;text-align:center;border-radius:12px;transition:background .2s}.cas-schedule-slide.ui-slider .ui-slider-handle.ui-state-default{border:1px solid #c5c5c5;background:#fff;box-shadow:0 0 0 9px #fff inset,0 1px 2px rgba(0,0,0,.15)}.cas-schedule-slide.ui-slider .ui-slider-handle.ui-state-active{background:#7ad03a;border-color:#999}.cas-schedule-slide.ui-slider .ui-slider-handle.ui-state-focus:focus{outline:0}.cas-schedule-slide.ui-slider .ui-slider-range{position:absolute;z-index:1;font-size:.7em;display:block;border:0;background:#7ad03a}.cas-schedule-slide.ui-slider.ui-state-disabled{opacity:.35;cursor:default!important;pointer-events:none}.cas-schedule-slide.ui-slider.ui-slider-horizontal{height:4px}.cas-schedule-slide.ui-slider.ui-slider-horizontal .ui-slider-handle{margin-left:-12px;top:-12px}.cas-schedule-slide.ui-slider.ui-slider-horizontal .ui-slider-range{top:0;height:100%}.cas-schedule-slide.ui-slider.ui-slider-horizontal .ui-slider-range-min{left:0}.cas-schedule-slide.ui-slider.ui-slider-horizontal .ui-slider-range-max{right:0}.button.button-cas-upgrade{background:#dd1d0c;color:#fff;border-color:#ac170a;font-weight:700;box-shadow:0 0 0 1px rgba(255,255,255,.3) inset,0 1px 0 #ac170a}.button.button-cas-upgrade:hover{color:#fff;border-color:#ac170a;background:#eb5c50}.button.button-cas-upgrade:active,.button.button-cas-upgrade:focus{color:#fff;background:#dd1d0c;border-color:#ac170a;box-shadow:inset 0 2px 0 #ac170a;vertical-align:top}#cas-plugin-links.postbox{background-color:#ddecf4;border-color:#9fcadf;box-shadow:0 0 0 1px #fff inset,0 1px 1px rgba(0,0,0,.04)}#cas-plugin-links .postbox-header{border-bottom-color:#9fcadf;box-shadow:0 -1px #fff inset}#cas-plugin-links .handle-actions{display:none!important}.wp-list-table.fixed.striped>tbody>:nth-child(2n+1){background-color:#f9f9f9}.wp-list-table.fixed .column-handler,.wp-list-table.fixed .column-visibility{width:20%}.wp-list-table.fixed .column-status,.wp-list-table.fixed .column-widgets{width:80px}.wp-list-table.fixed .column-status .dashicons{color:#999}.wp-list-table.fixed .column-status .sidebar-status{display:inline-block;margin-right:6px}.sidebar-status{margin:2px 0 0;position:relative;width:28px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;box-sizing:border-box}.sidebar-status .sidebar-status-input{display:none}.sidebar-status .sidebar-status-label{display:block;overflow:hidden;cursor:pointer;height:16px;padding:0;line-height:16px;border-radius:16px;background-color:#dc3232;box-shadow:0 0 2px rgba(0,0,0,.2) inset;transition:background-color .2s ease-in}.sidebar-status .sidebar-status-label:before{content:"";display:block;width:12px;height:12px;margin:0;background:#fff;position:absolute;top:2px;bottom:0;right:14px;border-radius:16px;transition:right .2s ease-in;box-shadow:0 1px 2px rgba(0,0,0,.2)}.sidebar-status .sidebar-status-input:checked+.sidebar-status-label{background-color:#7ad03a}.sidebar-status .sidebar-status-input:checked+.sidebar-status-label:before{right:2px}.sidebar-status .sidebar-status-input.sidebar-status-future:not(:checked)+.sidebar-status-label{background-color:#ffb900}.sidebar-status .sidebar-status-input:disabled+.sidebar-status-label{cursor:auto}.widget-liquid-right .widgets-holder-wrap .sidebar-name h2,.widget-liquid-right .widgets-holder-wrap .sidebar-name h3{text-overflow:ellipsis}.widget-liquid-right .widgets-holder-wrap .cas-settings{border-top:1px solid #dfdfdf;border-bottom:1px solid #dfdfdf;background-color:#f7f7f7;margin-left:-8px;margin-right:-8px;margin-bottom:10px;overflow:hidden}.widget-liquid-right .widgets-holder-wrap .sidebar-status{float:right;margin:10px 10px 0}.widget-liquid-right .widgets-holder-wrap .cas-sidebar-link{display:inline-block;border-right:1px solid #dfdfdf;padding:8px 10px;color:#888;text-decoration:none;transition:.4s;box-shadow:none}.widget-liquid-right .widgets-holder-wrap .cas-sidebar-link:hover{background-color:#fff;color:#222}.widget-liquid-right .widgets-holder-wrap.closed .cas-settings{display:none}.widget-liquid-right .widgets-holder-wrap div[id^=ca-sidebar]{box-shadow:inset 0 4px 0 #75d7ef}.cas-form-table{width:97%;margin:0 auto}.cas-form-table tr td:first-child{min-width:30%}.cas-form-table tr td{border-bottom:1px solid #eee}.cas-schedule-days{text-transform:uppercase;overflow:hidden;display:inline-block;border:1px solid #dfdfdf;margin:0;border-radius:3px}.cas-schedule-days li{float:left;margin:0}.cas-schedule-days input{display:none}.cas-schedule-days label{transition:background .2s;background:#0085ba;display:block;padding:8px 12px;color:#fff}.cas-schedule-days label:hover{background:#007aab}.cas-schedule-days input:checked+label{color:inherit;background:#f1f1f1}.cas-schedule-days input:checked+label:hover{background:#e9e9e9}.cas-filter-sidebar{max-width:calc(900px + 2%);margin:10px 0;vertical-align:middle}.cas-filter-sidebar .sidebars-toggle{margin:16px 0 0 10px;display:inline-block}.cas-filter-sidebar .sidebars-toggle a{outline:0;box-shadow:none}.cas-filter-sidebar .button{margin:10px 0}.cas-filter-sidebar input{float:right}input.cas-filter{margin:10px 0}.wp-header-end{visibility:visible;margin:14px -20px 0;clear:both}@media (min-width:783px){.cas-widget-manager:not(.widgets_access) #screen-meta{z-index:20}.cas-widget-manager:not(.widgets_access) .widget-liquid-left{position:absolute;top:50px}.cas-widget-manager:not(.widgets_access) .wrap .error,.cas-widget-manager:not(.widgets_access) .wrap .notice,.cas-widget-manager:not(.widgets_access) .wrap .postbox,.cas-widget-manager:not(.widgets_access) .wrap .updated,.cas-widget-manager:not(.widgets_access) .wrap h1{margin:0 0 0 calc(38% + 56px)}.cas-widget-manager:not(.widgets_access) .update-nag{margin-left:calc(38% + 50px)}.cas-widget-manager:not(.widgets_access) #available-widgets{z-index:1;position:fixed;top:32px;padding:0 10px;background:#fafafa;box-shadow:0 0 4px 0 rgba(0,0,0,.1);width:32%;border-color:#dfdfdf;border-style:solid;border-width:0 1px 1px 0;left:160px}.cas-widget-manager:not(.widgets_access) #available-widgets input.cas-filter{width:100%}.cas-widget-manager:not(.widgets_access) #available-widgets .widget{padding-bottom:10px}.cas-widget-manager:not(.widgets_access) #available-widgets #widget-list{border-top:1px solid #dfdfdf;padding:3px;margin:0 -10px;background:#fff}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed){min-height:600px;bottom:0;border-bottom-width:0}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .sidebar-name{position:static}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .sidebar-name .handlediv,.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .sidebar-name .sidebar-name-arrow{display:block;bottom:auto;right:10px}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .sidebar-name .toggle-indicator{display:block}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) #removing-widget{box-sizing:border-box;padding:10px 0 0;color:#c00;z-index:2;text-align:center;position:absolute;background-color:rgba(255,255,255,.6);border:4px dashed #c00;top:0;left:0;right:0;height:100%}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .description{display:none}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) #widget-list{position:fixed;top:120px;padding:12px 10px;overflow-y:auto;overflow-x:hidden;width:calc(32% - 1px);bottom:0}.cas-widget-manager:not(.widgets_access).folded #available-widgets{left:36px;width:37.5%}.cas-widget-manager:not(.widgets_access).folded #available-widgets:not(.closed) #widget-list{width:calc(37.5% - 1px)}.cas-widget-manager:not(.widgets_access).rtl .wrap .error,.cas-widget-manager:not(.widgets_access).rtl .wrap .notice,.cas-widget-manager:not(.widgets_access).rtl .wrap .postbox,.cas-widget-manager:not(.widgets_access).rtl .wrap .update-nag,.cas-widget-manager:not(.widgets_access).rtl .wrap .updated,.cas-widget-manager:not(.widgets_access).rtl .wrap h1{margin:0 calc(38% + 56px) 0 0}.cas-widget-manager:not(.widgets_access).rtl .update-nag{margin-right:calc(38% + 50px)}.cas-widget-manager:not(.widgets_access).rtl #available-widgets{box-shadow:0 0 5px 0 rgba(0,0,0,.1);right:160px;left:auto;border-width:0 0 1px 1px}.cas-widget-manager:not(.widgets_access).rtl #available-widgets:not(.closed) .sidebar-name .handlediv,.cas-widget-manager:not(.widgets_access).rtl #available-widgets:not(.closed) .sidebar-name .sidebar-name-arrow{left:10px;right:auto}.cas-widget-manager:not(.widgets_access).rtl.folded #available-widgets{left:auto;right:36px}.cas-widget-manager:not(.widgets_access) #widgets-right .widgets-sortables{z-index:2}.cas-widget-manager div.widget-liquid-right{padding:0;margin:0;width:58%;float:right}.cas-widget-manager div.widget-liquid-left{width:38%;margin:0;float:left;padding:0}.cas-widget-manager .fw-ext-sidebars-wrap-container{float:right}}@media (min-width:783px) and (max-width:960px){.cas-widget-manager.auto-fold:not(.widgets_access) #available-widgets{left:36px;width:36%}.cas-widget-manager.auto-fold:not(.widgets_access) #available-widgets:not(.closed) #widget-list{width:calc(36% - 1px)}.cas-widget-manager.auto-fold:not(.widgets_access).rtl #available-widgets{left:auto;right:36px}}@media (max-width:782px){input.cas-filter{width:100%}}@media (max-width:1249px){div#widgets-right .sidebars-column-1,div#widgets-right .sidebars-column-2{max-width:inherit}}@media (min-width:1250px){.cas-widget-manager:not(.widgets_access) #widgets-left #available-widgets .widget:nth-child(even){float:left;margin:0 0 0 2%}.cas-widget-manager:not(.widgets_access) #available-widgets{width:34.5%}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) #widget-list{width:calc(34.5% - 1px)}.cas-widget-manager:not(.widgets_access).rtl #widgets-left #available-widgets .widget{float:right;padding-left:2%}.cas-widget-manager:not(.widgets_access).rtl #widgets-left #available-widgets .widget:nth-child(odd){margin-right:-2%}}
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
+ * @copyright 2021 by Joachim Jensen
6
+ */#cas-rules .cas-heart{color:#ac170a}body.js .js-cas-visibility{max-height:30px;overflow:hidden}.cas-section,.js-cas-action{display:none}.nav-tab-wrapper.js-cas-tabs .nav-tab{position:relative}.nav-tab-active:focus{box-shadow:none}.cas-input-inline{display:inline-block}.cas-input-sm{max-width:80px;font-size:.8em;vertical-align:middle}.cas-metabox-holder .hndle{cursor:auto!important}#submitdiv .handlediv,#submitdiv .hndle,#submitdiv .postbox-header,.cas-metabox-holder .handle-actions,.cas-metabox-holder .handlediv{display:none!important}#submitdiv .cas-save{background:#f5f5f5;border-bottom:1px solid #ddd;overflow:hidden;padding:7px 10px}#submitdiv .cas-overview-actions{padding:0 10px}#submitdiv .cas-overview-actions .dashicons{color:#82878c}#submitdiv .cas-overview-actions>li{margin:0}#submitdiv .cas-overview-actions>li:not(:last-of-type){padding:0 0 10px;margin:0 0 10px;border-bottom:1px solid #eee}.cas-pro-label{font-size:.8em;background-color:#31c455;border-radius:5px;color:#fff;padding:2px 6px;text-transform:uppercase;vertical-align:baseline;white-space:nowrap;font-weight:700}.button.button-cas-delete{color:#fff;text-decoration:none;background-color:#a00;border:1px solid #000}.button.button-cas-delete:hover{color:#fff;background-color:red}a.cas-delete{color:#a00;text-decoration:none}a.cas-delete:hover{color:red}.cas-schedule-slide.ui-slider{position:relative;margin:12px;border-radius:4px;background:#c5c5c5;color:#333}.cas-schedule-slide.ui-slider .ui-slider-handle{position:absolute;z-index:2;height:24px;width:24px;touch-action:none;text-align:center;border-radius:12px;transition:background .2s}.cas-schedule-slide.ui-slider .ui-slider-handle.ui-state-default{border:1px solid #c5c5c5;background:#fff;box-shadow:0 0 0 9px #fff inset,0 1px 2px rgba(0,0,0,.15)}.cas-schedule-slide.ui-slider .ui-slider-handle.ui-state-active{background:#7ad03a;border-color:#999}.cas-schedule-slide.ui-slider .ui-slider-handle.ui-state-focus:focus{outline:0}.cas-schedule-slide.ui-slider .ui-slider-range{position:absolute;z-index:1;font-size:.7em;display:block;border:0;background:#7ad03a}.cas-schedule-slide.ui-slider.ui-state-disabled{opacity:.35;cursor:default!important;pointer-events:none}.cas-schedule-slide.ui-slider.ui-slider-horizontal{height:4px}.cas-schedule-slide.ui-slider.ui-slider-horizontal .ui-slider-handle{margin-left:-12px;top:-12px}.cas-schedule-slide.ui-slider.ui-slider-horizontal .ui-slider-range{top:0;height:100%}.cas-schedule-slide.ui-slider.ui-slider-horizontal .ui-slider-range-min{left:0}.cas-schedule-slide.ui-slider.ui-slider-horizontal .ui-slider-range-max{right:0}.button.button-cas-upgrade{background:#dd1d0c;color:#fff;border-color:#ac170a;font-weight:700;box-shadow:0 0 0 1px rgba(255,255,255,.3) inset,0 1px 0 #ac170a}.button.button-cas-upgrade:hover{color:#fff;border-color:#ac170a;background:#eb5c50}.button.button-cas-upgrade:active,.button.button-cas-upgrade:focus{color:#fff;background:#dd1d0c;border-color:#ac170a;box-shadow:inset 0 2px 0 #ac170a;vertical-align:top}#cas-plugin-links.postbox{background-color:#ddecf4;border-color:#9fcadf;box-shadow:0 0 0 1px #fff inset,0 1px 1px rgba(0,0,0,.04)}#cas-plugin-links .postbox-header{border-bottom-color:#9fcadf;box-shadow:0 -1px #fff inset}#cas-plugin-links .handle-actions{display:none!important}.wp-list-table.fixed.striped>tbody>:nth-child(2n+1){background-color:#f9f9f9}.wp-list-table.fixed .column-handler,.wp-list-table.fixed .column-visibility{width:20%}.wp-list-table.fixed .column-status,.wp-list-table.fixed .column-widgets{width:80px}.wp-list-table.fixed .column-status .dashicons{color:#999}.wp-list-table.fixed .column-status .sidebar-status{display:inline-block;margin-right:6px}.sidebar-status{margin:2px 0 0;position:relative;width:28px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;box-sizing:border-box}.sidebar-status .sidebar-status-input{display:none}.sidebar-status .sidebar-status-label{display:block;overflow:hidden;cursor:pointer;height:16px;padding:0;line-height:16px;border-radius:16px;background-color:#dc3232;box-shadow:0 0 2px rgba(0,0,0,.2) inset;transition:background-color .2s ease-in}.sidebar-status .sidebar-status-label:before{content:"";display:block;width:12px;height:12px;margin:0;background:#fff;position:absolute;top:2px;bottom:0;right:14px;border-radius:16px;transition:right .2s ease-in;box-shadow:0 1px 2px rgba(0,0,0,.2)}.sidebar-status .sidebar-status-input:checked+.sidebar-status-label{background-color:#7ad03a}.sidebar-status .sidebar-status-input:checked+.sidebar-status-label:before{right:2px}.sidebar-status .sidebar-status-input.sidebar-status-future:not(:checked)+.sidebar-status-label{background-color:#ffb900}.sidebar-status .sidebar-status-input:disabled+.sidebar-status-label{cursor:auto}.widget-liquid-right .widgets-holder-wrap .sidebar-name h2,.widget-liquid-right .widgets-holder-wrap .sidebar-name h3{text-overflow:ellipsis}.widget-liquid-right .widgets-holder-wrap .cas-settings{border-top:1px solid #dfdfdf;border-bottom:1px solid #dfdfdf;background-color:#f7f7f7;margin-left:-8px;margin-right:-8px;margin-bottom:10px;overflow:hidden}.widget-liquid-right .widgets-holder-wrap .sidebar-status{float:right;margin:10px 10px 0}.widget-liquid-right .widgets-holder-wrap .cas-sidebar-link{display:inline-block;border-right:1px solid #dfdfdf;padding:8px 10px;color:#888;text-decoration:none;transition:.4s;box-shadow:none}.widget-liquid-right .widgets-holder-wrap .cas-sidebar-link:hover{background-color:#fff;color:#222}.widget-liquid-right .widgets-holder-wrap.closed .cas-settings{display:none}.widget-liquid-right .widgets-holder-wrap div[id^=ca-sidebar]{box-shadow:inset 0 4px 0 #75d7ef}.cas-form-table{width:97%;margin:0 auto}.cas-form-table tr td:first-child{min-width:30%}.cas-form-table tr td{border-bottom:1px solid #eee}.cas-schedule-days{text-transform:uppercase;overflow:hidden;display:inline-block;border:1px solid #dfdfdf;margin:0;border-radius:3px}.cas-schedule-days li{float:left;margin:0}.cas-schedule-days input{display:none}.cas-schedule-days label{transition:background .2s;background:#0085ba;display:block;padding:8px 12px;color:#fff}.cas-schedule-days label:hover{background:#007aab}.cas-schedule-days input:checked+label{color:inherit;background:#f1f1f1}.cas-schedule-days input:checked+label:hover{background:#e9e9e9}.cas-filter-sidebar{max-width:calc(900px + 2%);margin:10px 0;vertical-align:middle}.cas-filter-sidebar .sidebars-toggle{margin:16px 0 0 10px;display:inline-block}.cas-filter-sidebar .sidebars-toggle a{outline:0;box-shadow:none}.cas-filter-sidebar .button{margin:10px 0}.cas-filter-sidebar input{float:right}input.cas-filter{margin:10px 0}.wp-header-end{visibility:visible;margin:14px -20px 0;clear:both}@media (min-width:783px){.cas-widget-manager:not(.widgets_access) #screen-meta{z-index:20}.cas-widget-manager:not(.widgets_access) .widget-liquid-left{position:absolute;top:50px}.cas-widget-manager:not(.widgets_access) .wrap .error,.cas-widget-manager:not(.widgets_access) .wrap .notice,.cas-widget-manager:not(.widgets_access) .wrap .postbox,.cas-widget-manager:not(.widgets_access) .wrap .updated,.cas-widget-manager:not(.widgets_access) .wrap h1{margin:0 0 0 calc(38% + 56px)}.cas-widget-manager:not(.widgets_access) .update-nag{margin-left:calc(38% + 50px)}.cas-widget-manager:not(.widgets_access) #available-widgets{z-index:1;position:fixed;top:32px;padding:0 10px;background:#fafafa;box-shadow:0 0 4px 0 rgba(0,0,0,.1);width:32%;border-color:#dfdfdf;border-style:solid;border-width:0 1px 1px 0;left:160px}.cas-widget-manager:not(.widgets_access) #available-widgets input.cas-filter{width:100%}.cas-widget-manager:not(.widgets_access) #available-widgets .widget{padding-bottom:10px}.cas-widget-manager:not(.widgets_access) #available-widgets #widget-list{border-top:1px solid #dfdfdf;padding:3px;margin:0 -10px;background:#fff}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed){min-height:600px;bottom:0;border-bottom-width:0}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .sidebar-name{position:static}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .sidebar-name .handlediv,.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .sidebar-name .sidebar-name-arrow{display:block;bottom:auto;right:10px}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .sidebar-name .toggle-indicator{display:block}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) #removing-widget{box-sizing:border-box;padding:10px 0 0;color:#c00;z-index:2;text-align:center;position:absolute;background-color:rgba(255,255,255,.6);border:4px dashed #c00;top:0;left:0;right:0;height:100%}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) .description{display:none}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) #widget-list{position:fixed;top:120px;padding:12px 10px;overflow-y:auto;overflow-x:hidden;width:calc(32% - 1px);bottom:0}.cas-widget-manager:not(.widgets_access).folded #available-widgets{left:36px;width:37.5%}.cas-widget-manager:not(.widgets_access).folded #available-widgets:not(.closed) #widget-list{width:calc(37.5% - 1px)}.cas-widget-manager:not(.widgets_access).rtl .wrap .error,.cas-widget-manager:not(.widgets_access).rtl .wrap .notice,.cas-widget-manager:not(.widgets_access).rtl .wrap .postbox,.cas-widget-manager:not(.widgets_access).rtl .wrap .update-nag,.cas-widget-manager:not(.widgets_access).rtl .wrap .updated,.cas-widget-manager:not(.widgets_access).rtl .wrap h1{margin:0 calc(38% + 56px) 0 0}.cas-widget-manager:not(.widgets_access).rtl .update-nag{margin-right:calc(38% + 50px)}.cas-widget-manager:not(.widgets_access).rtl #available-widgets{box-shadow:0 0 5px 0 rgba(0,0,0,.1);right:160px;left:auto;border-width:0 0 1px 1px}.cas-widget-manager:not(.widgets_access).rtl #available-widgets:not(.closed) .sidebar-name .handlediv,.cas-widget-manager:not(.widgets_access).rtl #available-widgets:not(.closed) .sidebar-name .sidebar-name-arrow{left:10px;right:auto}.cas-widget-manager:not(.widgets_access).rtl.folded #available-widgets{left:auto;right:36px}.cas-widget-manager:not(.widgets_access) #widgets-right .widgets-sortables{z-index:2}.cas-widget-manager div.widget-liquid-right{padding:0;margin:0;width:58%;float:right;background:0 0}.cas-widget-manager div.widget-liquid-left{width:38%;margin:0;float:left;padding:0}.cas-widget-manager .fw-ext-sidebars-wrap-container{float:right}}@media (min-width:783px) and (max-width:960px){.cas-widget-manager.auto-fold:not(.widgets_access) #available-widgets{left:36px;width:36%}.cas-widget-manager.auto-fold:not(.widgets_access) #available-widgets:not(.closed) #widget-list{width:calc(36% - 1px)}.cas-widget-manager.auto-fold:not(.widgets_access).rtl #available-widgets{left:auto;right:36px}}@media (max-width:782px){input.cas-filter{width:100%}}@media (max-width:1249px){div#widgets-right .sidebars-column-1,div#widgets-right .sidebars-column-2{max-width:inherit}}@media (min-width:1250px){.cas-widget-manager:not(.widgets_access) #widgets-left #available-widgets .widget:nth-child(even){float:left;margin:0 0 0 2%}.cas-widget-manager:not(.widgets_access) #available-widgets{width:34.5%}.cas-widget-manager:not(.widgets_access) #available-widgets:not(.closed) #widget-list{width:calc(34.5% - 1px)}.cas-widget-manager:not(.widgets_access).rtl #widgets-left #available-widgets .widget{float:right;padding-left:2%}.cas-widget-manager:not(.widgets_access).rtl #widgets-left #available-widgets .widget:nth-child(odd){margin-right:-2%}}.widgets-php #wpcontent .wrap .cs-wrap{margin:0!important}#cs-title-options,.custom-sidebars-add-new,div[id^=ca-sidebar]+.cs-toolbar{display:none}
assets/js/cas_admin.min.js CHANGED
@@ -2,6 +2,6 @@
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
- * @copyright 2020 by Joachim Jensen
6
  */
7
  !function($){"use strict";var e={current_section:0,sections:[],init:function(){this.tabController(),this.actionOptionHandler(),this.suggestVisibility(),this.suggestTarget(),this.initSidebarActivation(),$(".js-cas-color-field").wpColorPicker(),$(".js-cas-html").on("change",function(t){var e=$(this);$(e.data("target")).attr("disabled",!e.is(":checked"))}).trigger("change")},initSidebarActivation:function(){flatpickr.l10ns.default.weekdays=CASAdmin.weekdays,flatpickr.l10ns.default.months=CASAdmin.months,flatpickr.l10ns.default.firstDayOfWeek=CASAdmin.weekStart;var t=-1===CASAdmin.timeFormat.toLowerCase().indexOf("a"),i=flatpickr(".js-cas-activation",{wrap:!0,clickOpens:!0,enableTime:!0,time_24hr:t,allowInput:!0,enableSeconds:!0,onChange:function(t,e,n){(e||a.config.minDate)&&a.set("minDate",e?new Date(t):null),e?s.prop("checked",!1):s.is(":checked")||a.clear()}}),a=flatpickr(".js-cas-expiry",{wrap:!0,clickOpens:!0,enableTime:!0,time_24hr:t,allowInput:!0,enableSeconds:!0,onChange:function(t,e,n){(e||i.config.maxDate)&&i.set("maxDate",e?new Date(t):null)}}),s=$(".js-cas-status");s.on("change",function(t){$(this).is(":checked")?i.clear():i.selectedDates.length||a.clear()})},initTabSections:function(){$(".js-cas-tabs").find(".nav-tab").each(function(){var t=this.href.lastIndexOf("#");0<=t&&(t=this.href.substr(t),e.sections.push(t),$(t).hide())})},tabController:function(){this.initTabSections(),this.setCurrentSection(window.location.hash),$("#poststuff").on("click",".js-nav-link",function(t){e.setCurrentSection(this.href)})},findSectionByURL:function(t){t=this.sections.indexOf(t.substring(t.lastIndexOf("#")));return 0<=t?t:null},setCurrentSection:function(t){var e=this.findSectionByURL(t)||0,t=$(".js-cas-tabs").find(".nav-tab");t.eq(e).is(":visible")&&($(this.sections[this.current_section]).hide(),t.eq(this.current_section).removeClass("nav-tab-active"),this.current_section=e,$(this.sections[this.current_section]).show(),t.eq(this.current_section).addClass("nav-tab-active"),$("#_cas_section").val("#top"+this.sections[this.current_section]))},actionOptionHandler:function(){var t=$("#cas-options"),e=t.find(".js-cas-action");t.on("change",".js-cas-handle",function(){var t=$(this),t=e.filter(".js-cas-action-"+t.val());e.not(t).hide().find("input,select").attr("disabled",!0),t.fadeIn("fast").find("input,select").attr("disabled",!1)}),t.find(".js-cas-handle").trigger("change")},suggestVisibility:function(){var e=$(".js-cas-visibility");e.select2({theme:"wpca",placeholder:CASAdmin.allVisibility,minimumInputLength:0,closeOnSelect:!0,allowClear:!1,nextSearchTerm:function(t,e){return e},data:CASAdmin.visibility}).on("select2:selecting",function(t){e.data("forceOpen",!0)}).on("select2:close",function(t){e.data("forceOpen")&&(t.preventDefault(),e.select2("open"),e.data("forceOpen",!1))}),e.data("value")&&e.val(e.data("value").toString().split(",")).trigger("change")},suggestTarget:function(){var e=$(".js-cas-host");e.select2({theme:"wpca",minimumInputLength:0,closeOnSelect:!0,allowClear:!1,width:"250px",nextSearchTerm:function(t,e){return e},data:CASAdmin.target}).on("select2:selecting",function(t){e.data("forceOpen",!0)}).on("select2:close",function(t){e.data("forceOpen")&&(t.preventDefault(),e.select2("open"),e.data("forceOpen",!1))}),e.data("value")&&e.val(e.data("value").toString().split(",")).trigger("change")}};$(document).ready(function(){e.init()})}(jQuery);
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
+ * @copyright 2021 by Joachim Jensen
6
  */
7
  !function($){"use strict";var e={current_section:0,sections:[],init:function(){this.tabController(),this.actionOptionHandler(),this.suggestVisibility(),this.suggestTarget(),this.initSidebarActivation(),$(".js-cas-color-field").wpColorPicker(),$(".js-cas-html").on("change",function(t){var e=$(this);$(e.data("target")).attr("disabled",!e.is(":checked"))}).trigger("change")},initSidebarActivation:function(){flatpickr.l10ns.default.weekdays=CASAdmin.weekdays,flatpickr.l10ns.default.months=CASAdmin.months,flatpickr.l10ns.default.firstDayOfWeek=CASAdmin.weekStart;var t=-1===CASAdmin.timeFormat.toLowerCase().indexOf("a"),i=flatpickr(".js-cas-activation",{wrap:!0,clickOpens:!0,enableTime:!0,time_24hr:t,allowInput:!0,enableSeconds:!0,onChange:function(t,e,n){(e||a.config.minDate)&&a.set("minDate",e?new Date(t):null),e?s.prop("checked",!1):s.is(":checked")||a.clear()}}),a=flatpickr(".js-cas-expiry",{wrap:!0,clickOpens:!0,enableTime:!0,time_24hr:t,allowInput:!0,enableSeconds:!0,onChange:function(t,e,n){(e||i.config.maxDate)&&i.set("maxDate",e?new Date(t):null)}}),s=$(".js-cas-status");s.on("change",function(t){$(this).is(":checked")?i.clear():i.selectedDates.length||a.clear()})},initTabSections:function(){$(".js-cas-tabs").find(".nav-tab").each(function(){var t=this.href.lastIndexOf("#");0<=t&&(t=this.href.substr(t),e.sections.push(t),$(t).hide())})},tabController:function(){this.initTabSections(),this.setCurrentSection(window.location.hash),$("#poststuff").on("click",".js-nav-link",function(t){e.setCurrentSection(this.href)})},findSectionByURL:function(t){t=this.sections.indexOf(t.substring(t.lastIndexOf("#")));return 0<=t?t:null},setCurrentSection:function(t){var e=this.findSectionByURL(t)||0,t=$(".js-cas-tabs").find(".nav-tab");t.eq(e).is(":visible")&&($(this.sections[this.current_section]).hide(),t.eq(this.current_section).removeClass("nav-tab-active"),this.current_section=e,$(this.sections[this.current_section]).show(),t.eq(this.current_section).addClass("nav-tab-active"),$("#_cas_section").val("#top"+this.sections[this.current_section]))},actionOptionHandler:function(){var t=$("#cas-options"),e=t.find(".js-cas-action");t.on("change",".js-cas-handle",function(){var t=$(this),t=e.filter(".js-cas-action-"+t.val());e.not(t).hide().find("input,select").attr("disabled",!0),t.fadeIn("fast").find("input,select").attr("disabled",!1)}),t.find(".js-cas-handle").trigger("change")},suggestVisibility:function(){var e=$(".js-cas-visibility");e.select2({theme:"wpca",placeholder:CASAdmin.allVisibility,minimumInputLength:0,closeOnSelect:!0,allowClear:!1,nextSearchTerm:function(t,e){return e},data:CASAdmin.visibility}).on("select2:selecting",function(t){e.data("forceOpen",!0)}).on("select2:close",function(t){e.data("forceOpen")&&(t.preventDefault(),e.select2("open"),e.data("forceOpen",!1))}),e.data("value")&&e.val(e.data("value").toString().split(",")).trigger("change")},suggestTarget:function(){var e=$(".js-cas-host");e.select2({theme:"wpca",minimumInputLength:0,closeOnSelect:!0,allowClear:!1,width:"250px",nextSearchTerm:function(t,e){return e},data:CASAdmin.target}).on("select2:selecting",function(t){e.data("forceOpen",!0)}).on("select2:close",function(t){e.data("forceOpen")&&(t.preventDefault(),e.select2("open"),e.data("forceOpen",!1))}),e.data("value")&&e.val(e.data("value").toString().split(",")).trigger("change")}};$(document).ready(function(){e.init()})}(jQuery);
assets/js/general.min.js CHANGED
@@ -2,6 +2,6 @@
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
- * @copyright 2020 by Joachim Jensen
6
  */
7
  !function($){"use strict";var t={init:function(){this.toggleSidebarStatus(),CAS.showPopups&&(this.upgradeNoticeHandler(),this.reviewNoticeHandler())},toggleSidebarStatus:function(){$(".sidebar-status").on("change","input.sidebar-status-input",function(t){var a=$(this),e=a.is(":checked");if(a.hasClass("sidebar-status-future")&&!confirm(CAS.enableConfirm))return a.attr("checked",!e),t.preventDefault(),!1;$.post(ajaxurl,{action:"cas_sidebar_status",sidebar_id:a.val(),token:a.attr("data-nonce"),status:e},function(t){t.success?(a.next().attr("title",t.data.title),a.removeClass("sidebar-status-future")):(alert(t.data),a.attr("checked",!e))})})},upgradeNoticeHandler:function(){$(".js-cas-pro-notice.button").attr("disabled",!0),$(".js-cas-pro-notice").on("click",function(t){t.preventDefault(),$(".js-cas-pro-read-more").attr("href",$(this).data("url")),$(".js-cas-pro-popup").trigger("click")})},reviewNoticeHandler:function(){var e=$(".js-cas-notice-review");e.on("click","a, button",function(t){var a=$(this);$.ajax({url:ajaxurl,data:{action:"cas_dismiss_review_notice",dismiss:a.data("cas-rating")?1:0},dataType:"JSON",type:"POST",success:function(t){e.fadeOut(400,function(){e.remove()})},error:function(t,a,e){}})})}};$(document).ready(function(){t.init()})}(jQuery);
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
+ * @copyright 2021 by Joachim Jensen
6
  */
7
  !function($){"use strict";var t={init:function(){this.toggleSidebarStatus(),CAS.showPopups&&(this.upgradeNoticeHandler(),this.reviewNoticeHandler())},toggleSidebarStatus:function(){$(".sidebar-status").on("change","input.sidebar-status-input",function(t){var a=$(this),e=a.is(":checked");if(a.hasClass("sidebar-status-future")&&!confirm(CAS.enableConfirm))return a.attr("checked",!e),t.preventDefault(),!1;$.post(ajaxurl,{action:"cas_sidebar_status",sidebar_id:a.val(),token:a.attr("data-nonce"),status:e},function(t){t.success?(a.next().attr("title",t.data.title),a.removeClass("sidebar-status-future")):(alert(t.data),a.attr("checked",!e))})})},upgradeNoticeHandler:function(){$(".js-cas-pro-notice.button").attr("disabled",!0),$(".js-cas-pro-notice").on("click",function(t){t.preventDefault(),$(".js-cas-pro-read-more").attr("href",$(this).data("url")),$(".js-cas-pro-popup").trigger("click")})},reviewNoticeHandler:function(){var e=$(".js-cas-notice-review");e.on("click","a, button",function(t){var a=$(this);$.ajax({url:ajaxurl,data:{action:"cas_dismiss_review_notice",dismiss:a.data("cas-rating")?1:0},dataType:"JSON",type:"POST",success:function(t){e.fadeOut(400,function(){e.remove()})},error:function(t,a,e){}})})}};$(document).ready(function(){t.init()})}(jQuery);
assets/js/suggest-sidebars.min.js CHANGED
@@ -2,6 +2,6 @@
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
- * @copyright 2020 by Joachim Jensen
6
  */
7
  !function($){"use strict";var e={init:function(){this.suggestSidebars(),this.toggleSidebarInputs()},toggleSidebarInputs:function(){$(".js-cas-more").click(function(e){e.preventDefault();var t=$(this),e=$(t.data("toggle")),t=t.children(":first");t.hasClass("dashicons-arrow-down-alt2")?(t.addClass("dashicons-arrow-up-alt2").removeClass("dashicons-arrow-down-alt2"),e.slideDown()):(t.addClass("dashicons-arrow-down-alt2").removeClass("dashicons-arrow-up-alt2"),e.slideUp())})},suggestSidebars:function(){$(".js-cas-sidebars").each(function(){$(this).select2({theme:"wpca",minimumInputLength:0,closeOnSelect:!0,allowClear:!1,width:"100%",escapeMarkup:function(e){return e},createTag:function(e){e=$.trim(e.term);return""===e?null:{id:"_"+e.replace(/,/g,"__"),text:e,new:!0}},templateSelection:function(e){return(e.new?"<b>("+CAS.labelNew+")</b> ":"")+e.text},templateResult:function(e){return(e.new?"<b>"+CAS.createNew+":</b> ":"")+e.text},templateNoMatches:function(e){return CAS.notFound}})})}};$(document).ready(function(){e.init()})}(jQuery);
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
+ * @copyright 2021 by Joachim Jensen
6
  */
7
  !function($){"use strict";var e={init:function(){this.suggestSidebars(),this.toggleSidebarInputs()},toggleSidebarInputs:function(){$(".js-cas-more").click(function(e){e.preventDefault();var t=$(this),e=$(t.data("toggle")),t=t.children(":first");t.hasClass("dashicons-arrow-down-alt2")?(t.addClass("dashicons-arrow-up-alt2").removeClass("dashicons-arrow-down-alt2"),e.slideDown()):(t.addClass("dashicons-arrow-down-alt2").removeClass("dashicons-arrow-up-alt2"),e.slideUp())})},suggestSidebars:function(){$(".js-cas-sidebars").each(function(){$(this).select2({theme:"wpca",minimumInputLength:0,closeOnSelect:!0,allowClear:!1,width:"100%",escapeMarkup:function(e){return e},createTag:function(e){e=$.trim(e.term);return""===e?null:{id:"_"+e.replace(/,/g,"__"),text:e,new:!0}},templateSelection:function(e){return(e.new?"<b>("+CAS.labelNew+")</b> ":"")+e.text},templateResult:function(e){return(e.new?"<b>"+CAS.createNew+":</b> ":"")+e.text},templateNoMatches:function(e){return CAS.notFound}})})}};$(document).ready(function(){e.init()})}(jQuery);
assets/js/widgets.min.js CHANGED
@@ -2,6 +2,6 @@
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
- * @copyright 2020 by Joachim Jensen
6
  */
7
  !function($){"use strict";var e={$sidebarContainer:$(".widget-liquid-right"),$widgetContainer:$("#available-widgets"),init:function(){this.openSidebarByURL(),this.addSidebarToolbar(),this.addWidgetSearch(),this.enhancedWidgetManager()},openSidebarByURL:function(){var e,i;!window.location.hash||(i=(e=this.$sidebarContainer.find(".widgets-holder-wrap")).has(window.location.hash)).length&&i.add(e.first()).find(".handlediv,.sidebar-name-arrow").trigger("click")},enhancedWidgetManager:function(){var i,a;$("body").hasClass("cas-widget-manager")&&(this.$widgetContainer.find(".widget").draggable("option","scroll",!1),i=this,(a=$("#widgets-left .inactive-sidebar")).toggle(this.$widgetContainer.hasClass("closed")),this.$widgetContainer.find(".sidebar-name").click(function(e){a.toggle(i.$widgetContainer.hasClass("closed"))}))},addWidgetSearch:function(){var e=$(".widget",this.$widgetContainer).get().reverse();$(".sidebar-description",this.$widgetContainer).prepend('<input type="search" class="js-cas-widget-filter cas-filter" placeholder="'+CASAdmin.filterWidgets+'...">'),this.searchWidgetListener(e)},searchWidgetListener:function(i){var t,s="";this.$widgetContainer.on("input",".js-cas-widget-filter",function(e){var a=$(this).val();a!=s&&(s=a,t&&clearTimeout(t),t=setTimeout(function(){$(i).each(function(e,i){i=$(i);i.find(".widget-title :nth-child(1)").text().search(new RegExp(a,"i"))<0?i.fadeOut():(i.prependTo(i.parent()),i.fadeIn().css("display",""))})},250))})},addSidebarToolbar:function(){var e='<div class="wp-filter cas-filter-sidebar"><a href="admin.php?page=wpcas-edit" class="button button-primary">'+CASAdmin.addNew+'</a><div class="sidebars-toggle"><a href="#" title="'+CASAdmin.collapse+'" class="js-sidebars-toggle" data-toggle="0"><span class="dashicons dashicons-arrow-up-alt2"></span></a><a href="#" title="'+CASAdmin.expand+'" class="js-sidebars-toggle" data-toggle="1"><span class="dashicons dashicons-arrow-down-alt2"></span></a></div><input type="search" class="js-cas-filter cas-filter" placeholder="'+CASAdmin.filterSidebars+'..."></div>';this.$sidebarContainer.prepend(e),this.searchSidebarListener(),this.addSidebarToggle()},addSidebarToggle:function(){var i=$(document),a=this.$sidebarContainer.find(".widgets-holder-wrap");$("body").on("click",".js-sidebars-toggle",function(e){e.preventDefault();e=!!$(this).data("toggle");a.toggleClass("closed",!e),e&&a.children(".widgets-sortables").sortable("refresh"),i.triggerHandler("wp-pin-menu")})},searchSidebarListener:function(){var i,t=this,s="";this.$sidebarContainer.on("input",".js-cas-filter",function(e){var a=$(this).val();a!=s&&(s=a,i&&clearTimeout(i),i=setTimeout(function(){$(".widgets-holder-wrap",t.$sidebarContainer).each(function(e,i){i=$(i);i.find(".sidebar-name :nth-child(2)").text().search(new RegExp(a,"i"))<0?i.fadeOut():i.fadeIn()})},250))})}};$(document).ready(function(){e.init()})}(jQuery);
2
  * @package Content Aware Sidebars
3
  * @author Joachim Jensen <joachim@dev.institute>
4
  * @license GPLv3
5
+ * @copyright 2021 by Joachim Jensen
6
  */
7
  !function($){"use strict";var e={$sidebarContainer:$(".widget-liquid-right"),$widgetContainer:$("#available-widgets"),init:function(){this.openSidebarByURL(),this.addSidebarToolbar(),this.addWidgetSearch(),this.enhancedWidgetManager()},openSidebarByURL:function(){var e,i;!window.location.hash||(i=(e=this.$sidebarContainer.find(".widgets-holder-wrap")).has(window.location.hash)).length&&i.add(e.first()).find(".handlediv,.sidebar-name-arrow").trigger("click")},enhancedWidgetManager:function(){var i,a;$("body").hasClass("cas-widget-manager")&&(this.$widgetContainer.find(".widget").draggable("option","scroll",!1),i=this,(a=$("#widgets-left .inactive-sidebar")).toggle(this.$widgetContainer.hasClass("closed")),this.$widgetContainer.find(".sidebar-name").click(function(e){a.toggle(i.$widgetContainer.hasClass("closed"))}))},addWidgetSearch:function(){var e=$(".widget",this.$widgetContainer).get().reverse();$(".sidebar-description",this.$widgetContainer).prepend('<input type="search" class="js-cas-widget-filter cas-filter" placeholder="'+CASAdmin.filterWidgets+'...">'),this.searchWidgetListener(e)},searchWidgetListener:function(i){var t,s="";this.$widgetContainer.on("input",".js-cas-widget-filter",function(e){var a=$(this).val();a!=s&&(s=a,t&&clearTimeout(t),t=setTimeout(function(){$(i).each(function(e,i){i=$(i);i.find(".widget-title :nth-child(1)").text().search(new RegExp(a,"i"))<0?i.fadeOut():(i.prependTo(i.parent()),i.fadeIn().css("display",""))})},250))})},addSidebarToolbar:function(){var e='<div class="wp-filter cas-filter-sidebar"><a href="admin.php?page=wpcas-edit" class="button button-primary">'+CASAdmin.addNew+'</a><div class="sidebars-toggle"><a href="#" title="'+CASAdmin.collapse+'" class="js-sidebars-toggle" data-toggle="0"><span class="dashicons dashicons-arrow-up-alt2"></span></a><a href="#" title="'+CASAdmin.expand+'" class="js-sidebars-toggle" data-toggle="1"><span class="dashicons dashicons-arrow-down-alt2"></span></a></div><input type="search" class="js-cas-filter cas-filter" placeholder="'+CASAdmin.filterSidebars+'..."></div>';this.$sidebarContainer.prepend(e),this.searchSidebarListener(),this.addSidebarToggle()},addSidebarToggle:function(){var i=$(document),a=this.$sidebarContainer.find(".widgets-holder-wrap");$("body").on("click",".js-sidebars-toggle",function(e){e.preventDefault();e=!!$(this).data("toggle");a.toggleClass("closed",!e),e&&a.children(".widgets-sortables").sortable("refresh"),i.triggerHandler("wp-pin-menu")})},searchSidebarListener:function(){var i,t=this,s="";this.$sidebarContainer.on("input",".js-cas-filter",function(e){var a=$(this).val();a!=s&&(s=a,i&&clearTimeout(i),i=setTimeout(function(){$(".widgets-holder-wrap",t.$sidebarContainer).each(function(e,i){i=$(i);i.find(".sidebar-name :nth-child(2)").text().search(new RegExp(a,"i"))<0?i.fadeOut():i.fadeIn()})},250))})}};$(document).ready(function(){e.init()})}(jQuery);
cas_uninstall.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -19,16 +19,16 @@ delete_option('cas_db_version');
19
  delete_option('cas_pro');
20
 
21
  //Remove all sidebars, groups, meta and terms.
22
- $sidebars = get_posts(array(
23
  'post_type' => 'sidebar',
24
  'posts_per_page' => -1
25
- ));
26
  foreach ($sidebars as $sidebar) {
27
- $groups = get_posts(array(
28
  'post_parent' => $sidebar->ID,
29
  'post_type' => 'condition_group',
30
  'posts_per_page' => -1
31
- ));
32
  foreach ($groups as $group) {
33
  wp_delete_post($group->ID, true);
34
  }
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
19
  delete_option('cas_pro');
20
 
21
  //Remove all sidebars, groups, meta and terms.
22
+ $sidebars = get_posts([
23
  'post_type' => 'sidebar',
24
  'posts_per_page' => -1
25
+ ]);
26
  foreach ($sidebars as $sidebar) {
27
+ $groups = get_posts([
28
  'post_parent' => $sidebar->ID,
29
  'post_type' => 'condition_group',
30
  'posts_per_page' => -1
31
+ ]);
32
  foreach ($groups as $group) {
33
  wp_delete_post($group->ID, true);
34
  }
changelog.txt CHANGED
@@ -1,3 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  = 3.11.1 =
2
 
3
  * [fixed] conditions would not always be auto-saved
1
+ = 3.12.2 =
2
+
3
+ * [fixed] sidebars inserted with shortcode can now be replaced/merged
4
+
5
+ **Pro Plan:**
6
+
7
+ * [fixed] acf condition now works with relational fields
8
+ * [fixed] ensure sticky js is only loaded once
9
+
10
+ = 3.12.1 =
11
+
12
+ **Pro Plan:**
13
+
14
+ * [fixed] acf condition loaded improperly without acf installed
15
+
16
+ = 3.12 =
17
+
18
+ * [new] translatepress display condition
19
+ * [new] wordpress 5.4 support
20
+ * [new] minimum wordpress version 4.8
21
+ * [new] activation/deactivation can now be same day
22
+ * [updated] wp-content-aware-engine library
23
+ * [updated] optimized and reduced plugin size with 37%
24
+
25
+ **Pro Plan:**
26
+
27
+ * [new] advanced custom fields display condition
28
+ * [new] action to display widget area after paragraphs
29
+ * [updated] css will no longer be loaded for empty sidebars
30
+
31
  = 3.11.1 =
32
 
33
  * [fixed] conditions would not always be auto-saved
conditions/index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
  /**/
1
+ <?php
2
  /**/
conditions/placeholder.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -33,13 +33,13 @@ final class CASConditionPlaceholder extends WPCAModule_Base
33
  */
34
  public function list_module($list)
35
  {
36
- $list[] = array(
37
  'id' => $this->id,
38
  'text' => $this->name,
39
  'placeholder' => $this->placeholder,
40
  'default_value' => $this->default_value,
41
  'disabled' => true,
42
- );
43
  return $list;
44
  }
45
 
@@ -81,9 +81,9 @@ final class CASConditionPlaceholder extends WPCAModule_Base
81
  *
82
  * @return void
83
  */
84
- protected function _get_content($args = array())
85
  {
86
- return array();
87
  }
88
 
89
  /**
@@ -103,7 +103,7 @@ final class CASConditionPlaceholder extends WPCAModule_Base
103
  */
104
  public function get_context_data()
105
  {
106
- return array();
107
  }
108
 
109
  /**
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
33
  */
34
  public function list_module($list)
35
  {
36
+ $list[] = [
37
  'id' => $this->id,
38
  'text' => $this->name,
39
  'placeholder' => $this->placeholder,
40
  'default_value' => $this->default_value,
41
  'disabled' => true,
42
+ ];
43
  return $list;
44
  }
45
 
81
  *
82
  * @return void
83
  */
84
+ protected function _get_content($args = [])
85
  {
86
+ return [];
87
  }
88
 
89
  /**
103
  */
104
  public function get_context_data()
105
  {
106
+ return [];
107
  }
108
 
109
  /**
content-aware-sidebars.php CHANGED
@@ -3,13 +3,13 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
  /*
9
  Plugin Name: Content Aware Sidebars
10
  Plugin URI: https://dev.institute/wordpress-sidebars/
11
  Description: Unlimited custom sidebars and widget areas for any post, page, category etc.
12
- Version: 3.14.1
13
  Author: Joachim Jensen - DEV Institute
14
  Author URI: https://dev.institute
15
  Requires at least: 4.9
@@ -53,6 +53,7 @@ if (!class_exists('CAS_App')) {
53
  require($cas_dir_path.'app.php');
54
  require($cas_dir_path.'lib/wp-pointer-tour/wp-pointer-tour.php');
55
  require($cas_dir_path.'admin/admin.php');
 
56
  require($cas_dir_path.'admin/quick_select.php');
57
  require($cas_dir_path.'admin/sidebar-list-table.php');
58
  require($cas_dir_path.'admin/sidebar-overview.php');
@@ -72,7 +73,7 @@ if (!class_exists('CAS_App')) {
72
  * @param array|string $args
73
  * @return void
74
  */
75
- function ca_display_sidebar($args = array())
76
  {
77
  CAS_App::instance()->manager()->manual_sidebar($args);
78
  }
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
  /*
9
  Plugin Name: Content Aware Sidebars
10
  Plugin URI: https://dev.institute/wordpress-sidebars/
11
  Description: Unlimited custom sidebars and widget areas for any post, page, category etc.
12
+ Version: 3.15
13
  Author: Joachim Jensen - DEV Institute
14
  Author URI: https://dev.institute
15
  Requires at least: 4.9
53
  require($cas_dir_path.'app.php');
54
  require($cas_dir_path.'lib/wp-pointer-tour/wp-pointer-tour.php');
55
  require($cas_dir_path.'admin/admin.php');
56
+ require($cas_dir_path.'admin/admin_bar.php');
57
  require($cas_dir_path.'admin/quick_select.php');
58
  require($cas_dir_path.'admin/sidebar-list-table.php');
59
  require($cas_dir_path.'admin/sidebar-overview.php');
73
  * @param array|string $args
74
  * @return void
75
  */
76
+ function ca_display_sidebar($args = [])
77
  {
78
  CAS_App::instance()->manager()->manual_sidebar($args);
79
  }
freemius.php CHANGED
@@ -4,7 +4,7 @@
4
  * @package Content Aware Sidebars
5
  * @author Joachim Jensen <joachim@dev.institute>
6
  * @license GPLv3
7
- * @copyright 2020 by Joachim Jensen
8
  */
9
  defined( 'ABSPATH' ) || exit;
10
  // Create a helper function for easy SDK access.
@@ -15,7 +15,7 @@ function cas_fs()
15
  if ( !isset( $cas_fs ) ) {
16
  // Include Freemius SDK.
17
  require_once dirname( __FILE__ ) . '/lib/freemius/start.php';
18
- $cas_fs = fs_dynamic_init( array(
19
  'id' => '259',
20
  'slug' => 'content-aware-sidebars',
21
  'type' => 'plugin',
@@ -25,14 +25,14 @@ function cas_fs()
25
  'has_addons' => false,
26
  'has_paid_plans' => true,
27
  'has_affiliation' => 'selected',
28
- 'menu' => array(
29
  'slug' => 'wpcas',
30
  'support' => false,
31
  'contact' => false,
32
  'affiliation' => false,
33
- ),
34
  'is_live' => true,
35
- ) );
36
  }
37
 
38
  return $cas_fs;
4
  * @package Content Aware Sidebars
5
  * @author Joachim Jensen <joachim@dev.institute>
6
  * @license GPLv3
7
+ * @copyright 2021 by Joachim Jensen
8
  */
9
  defined( 'ABSPATH' ) || exit;
10
  // Create a helper function for easy SDK access.
15
  if ( !isset( $cas_fs ) ) {
16
  // Include Freemius SDK.
17
  require_once dirname( __FILE__ ) . '/lib/freemius/start.php';
18
+ $cas_fs = fs_dynamic_init( [
19
  'id' => '259',
20
  'slug' => 'content-aware-sidebars',
21
  'type' => 'plugin',
25
  'has_addons' => false,
26
  'has_paid_plans' => true,
27
  'has_affiliation' => 'selected',
28
+ 'menu' => [
29
  'slug' => 'wpcas',
30
  'support' => false,
31
  'contact' => false,
32
  'affiliation' => false,
33
+ ],
34
  'is_live' => true,
35
+ ] );
36
  }
37
 
38
  return $cas_fs;
lib/wp-content-aware-engine/bootstrap.php CHANGED
@@ -12,7 +12,7 @@ defined('ABSPATH') || exit;
12
  * Version of this WPCA
13
  * @var string
14
  */
15
- $this_wpca_version = '9.1.1.3';
16
 
17
  /**
18
  * Class to make sure the latest
@@ -61,10 +61,8 @@ if (!class_exists('WPCALoader')) {
61
  return;
62
  }
63
 
64
- //SORT_NUMERIC added in 9.1
65
- arsort(self::$_paths, SORT_NUMERIC);
66
-
67
- foreach (self::$_paths as $path => $version) {
68
  $file = $path.'core.php';
69
  if (file_exists($file)) {
70
  include($file);
12
  * Version of this WPCA
13
  * @var string
14
  */
15
+ $this_wpca_version = '9.2a';
16
 
17
  /**
18
  * Class to make sure the latest
61
  return;
62
  }
63
 
64
+ uasort(self::$_paths, 'version_compare');
65
+ foreach (array_reverse(self::$_paths, true) as $path => $version) {
 
 
66
  $file = $path.'core.php';
67
  if (file_exists($file)) {
68
  include($file);
lib/wp-content-aware-engine/core.php CHANGED
@@ -87,6 +87,10 @@ if (!class_exists('WPCACore')) {
87
  */
88
  private static $post_cache = array();
89
 
 
 
 
 
90
  /**
91
  * Constructor
92
  */
@@ -382,7 +386,17 @@ GROUP BY p.post_type, m.meta_key
382
  }
383
  }
384
 
385
- private static $wp_query_original = array();
 
 
 
 
 
 
 
 
 
 
386
 
387
  /**
388
  * Get filtered condition groups
@@ -436,6 +450,7 @@ GROUP BY p.post_type, m.meta_key
436
  $data = "($name.meta_value IS NULL OR $name.meta_value IN ('".implode("','", $data) ."'))";
437
  }
438
  $where[$id] = apply_filters("wpca/module/$id/db-where", $data);
 
439
  } else {
440
  $excluded[] = $module;
441
  }
@@ -633,7 +648,7 @@ GROUP BY p.post_type, m.meta_key
633
  //desc
634
  if ($post_a_handle != $post_b_handle) {
635
  return $post_a_handle > $post_b_handle ? -1 : 1;
636
- }
637
 
638
  //desc
639
  if ($post_a->post_date != $post_b->post_date) {
@@ -668,7 +683,7 @@ GROUP BY p.post_type, m.meta_key
668
  */
669
  public static function add_group_meta_box($post_type, $post)
670
  {
671
- if(is_null($post)) {
672
  return;
673
  }
674
  self::render_group_meta_box($post, $post_type, 'normal', 'default');
@@ -765,7 +780,7 @@ GROUP BY p.post_type, m.meta_key
765
  'post_type' => self::TYPE_CONDITION_GROUP,
766
  'post_parent' => $post->ID,
767
  'post_status' => array(self::STATUS_PUBLISHED,self::STATUS_NEGATED,self::STATUS_EXCEPT, self::STATUS_OR),
768
- 'order' => 'DESC',
769
  'orderby' => 'post_status'
770
  ));
771
  }
87
  */
88
  private static $post_cache = array();
89
 
90
+ private static $wp_query_original = array();
91
+
92
+ private static $filtered_modules = array();
93
+
94
  /**
95
  * Constructor
96
  */
386
  }
387
  }
388
 
389
+ /**
390
+ * @param string $post_type
391
+ * @return array
392
+ */
393
+ public static function get_conditional_modules($post_type)
394
+ {
395
+ if (!isset(self::$filtered_modules[$post_type])) {
396
+ return array();
397
+ }
398
+ return self::$filtered_modules[$post_type];
399
+ }
400
 
401
  /**
402
  * Get filtered condition groups
450
  $data = "($name.meta_value IS NULL OR $name.meta_value IN ('".implode("','", $data) ."'))";
451
  }
452
  $where[$id] = apply_filters("wpca/module/$id/db-where", $data);
453
+ self::$filtered_modules[$post_type][] = $module;
454
  } else {
455
  $excluded[] = $module;
456
  }
648
  //desc
649
  if ($post_a_handle != $post_b_handle) {
650
  return $post_a_handle > $post_b_handle ? -1 : 1;
651
+ }
652
 
653
  //desc
654
  if ($post_a->post_date != $post_b->post_date) {
683
  */
684
  public static function add_group_meta_box($post_type, $post)
685
  {
686
+ if (is_null($post)) {
687
  return;
688
  }
689
  self::render_group_meta_box($post, $post_type, 'normal', 'default');
780
  'post_type' => self::TYPE_CONDITION_GROUP,
781
  'post_parent' => $post->ID,
782
  'post_status' => array(self::STATUS_PUBLISHED,self::STATUS_NEGATED,self::STATUS_EXCEPT, self::STATUS_OR),
783
+ 'order' => 'ASC',
784
  'orderby' => 'post_status'
785
  ));
786
  }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: custom sidebars, sidebar, hide sidebar, display widgets, widget, bbpress,
5
  Requires at least: 4.9
6
  Requires PHP: 5.6
7
  Tested up to: 5.6
8
- Stable tag: 3.14.1
9
  License: GPLv3
10
 
11
  Display new sidebars and widget areas on any post, page, category etc. Works with all themes, no code required.
@@ -184,6 +184,13 @@ Of course! Check out the links below:
184
 
185
  ####Highlights
186
 
 
 
 
 
 
 
 
187
  = 3.14.1 =
188
 
189
  * [fixed] sidebar quick select now displays all eligible sidebars
@@ -235,34 +242,4 @@ Of course! Check out the links below:
235
  * [new] sticky support for storefront theme
236
  * [fixed] sticky left sidebars in generatepress
237
 
238
- = 3.12.2 =
239
-
240
- * [fixed] sidebars inserted with shortcode can now be replaced/merged
241
-
242
- **Pro Plan:**
243
-
244
- * [fixed] acf condition now works with relational fields
245
- * [fixed] ensure sticky js is only loaded once
246
-
247
- = 3.12.1 =
248
-
249
- **Pro Plan:**
250
-
251
- * [fixed] acf condition loaded improperly without acf installed
252
-
253
- = 3.12 =
254
-
255
- * [new] translatepress display condition
256
- * [new] wordpress 5.4 support
257
- * [new] minimum wordpress version 4.8
258
- * [new] activation/deactivation can now be same day
259
- * [updated] wp-content-aware-engine library
260
- * [updated] optimized and reduced plugin size with 37%
261
-
262
- **Pro Plan:**
263
-
264
- * [new] advanced custom fields display condition
265
- * [new] action to display widget area after paragraphs
266
- * [updated] css will no longer be loaded for empty sidebars
267
-
268
  See changelog.txt for previous changes.
5
  Requires at least: 4.9
6
  Requires PHP: 5.6
7
  Tested up to: 5.6
8
+ Stable tag: 3.15
9
  License: GPLv3
10
 
11
  Display new sidebars and widget areas on any post, page, category etc. Works with all themes, no code required.
184
 
185
  ####Highlights
186
 
187
+ = 3.15 =
188
+
189
+ * [new] toolbar menu to view conditions, theme areas, and sidebars for a given page
190
+ * [new] better compatibility with retired custom sidebars plugin
191
+ * [updated] ui improvements
192
+ * [updated] wp-content-aware-engine library
193
+
194
  = 3.14.1 =
195
 
196
  * [fixed] sidebar quick select now displays all eligible sidebars
242
  * [new] sticky support for storefront theme
243
  * [fixed] sticky left sidebars in generatepress
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  See changelog.txt for previous changes.
sidebar.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
@@ -21,19 +21,19 @@ final class CAS_Sidebar_Manager
21
  * Custom sidebars
22
  * @var array
23
  */
24
- public $sidebars = array();
25
 
26
  /**
27
  * Cache replaced sidebars
28
  * @var array
29
  */
30
- protected $replaced_sidebars = array();
31
 
32
  /**
33
  * Sidebar replacement map
34
  * @var array
35
  */
36
- protected $replace_map = array();
37
 
38
  /**
39
  * @var array
@@ -45,31 +45,34 @@ final class CAS_Sidebar_Manager
45
  {
46
  add_action(
47
  'wpca/loaded',
48
- array($this,'late_init')
49
  );
50
  add_action(
51
  'wp_head',
52
- array($this,'sidebar_notify_theme_customizer')
53
  );
54
  add_action(
55
  'init',
56
- array($this,'init_sidebar_type'),
57
  99
58
  );
59
  add_action(
60
  'widgets_init',
61
- array($this,'create_sidebars'),
62
  99
63
  );
64
  add_action(
65
  'wp_loaded',
66
- array($this,'set_sidebar_styles'),
67
  99
68
  );
69
 
 
 
 
70
  add_shortcode(
71
  'ca-sidebar',
72
- array($this,'sidebar_shortcode')
73
  );
74
  }
75
 
@@ -86,31 +89,31 @@ final class CAS_Sidebar_Manager
86
  if (!is_admin()) {
87
  add_filter(
88
  'sidebars_widgets',
89
- array($this,'replace_sidebar')
90
  );
91
  add_filter(
92
  'wpca/posts/sidebar',
93
- array(__CLASS__,'filter_password_protection')
94
  );
95
  add_filter(
96
  'wpca/posts/sidebar',
97
- array($this,'filter_visibility')
98
  );
99
  add_filter(
100
  'cas/shortcode/display',
101
- array($this,'filter_shortcode_visibility'),
102
  10,
103
  2
104
  );
105
  add_action(
106
  'dynamic_sidebar_before',
107
- array($this,'render_sidebar_before'),
108
  9,
109
  2
110
  );
111
  add_action(
112
  'dynamic_sidebar_after',
113
- array($this,'render_sidebar_after'),
114
  99,
115
  2
116
  );
@@ -143,54 +146,54 @@ final class CAS_Sidebar_Manager
143
  ->add(new WPCAMeta(
144
  'visibility',
145
  __('User Visibility', 'content-aware-sidebars'),
146
- array(),
147
  'multi',
148
- array(
149
- 'general' => array(
150
  'label' => 'General',
151
- 'options' => array(
152
  -1 => __('Logged-in', 'content-aware-sidebars')
153
- )
154
- )
155
- )
156
  ), 'visibility')
157
  ->add(new WPCAMeta(
158
  'handle',
159
  _x('Action', 'option', 'content-aware-sidebars'),
160
  0,
161
  'select',
162
- array(
163
  0 => __('Replace', 'content-aware-sidebars'),
164
  1 => __('Merge', 'content-aware-sidebars'),
165
  3 => __('Forced replace', 'content-aware-sidebars'),
166
  2 => __('Shortcode')
167
- ),
168
  __('Replace host sidebar, merge with it or add sidebar manually.', 'content-aware-sidebars')
169
  ), 'handle')
170
  ->add(new WPCAMeta(
171
  'host',
172
  __('Target Sidebar', 'content-aware-sidebars'),
173
- array(),
174
  'multi',
175
- array()
176
  ), 'host')
177
  ->add(new WPCAMeta(
178
  'merge_pos',
179
  __('Merge Position', 'content-aware-sidebars'),
180
  1,
181
  'select',
182
- array(
183
  __('Top', 'content-aware-sidebars'),
184
  __('Bottom', 'content-aware-sidebars')
185
- ),
186
  __('Place sidebar on top or bottom of host when merging.', 'content-aware-sidebars')
187
  ), 'merge_pos')
188
  ->add(new WPCAMeta(
189
  'html',
190
  __('HTML', 'content-aware-sidebars'),
191
- array(),
192
  'select',
193
- array('')
194
  ), 'html');
195
  apply_filters('cas/metadata/init', $this->metadata);
196
  }
@@ -208,7 +211,7 @@ final class CAS_Sidebar_Manager
208
  global $wp_registered_sidebars;
209
 
210
  // List of sidebars
211
- $sidebar_list = array();
212
  foreach ($wp_registered_sidebars as $sidebar) {
213
  $sidebar_list[$sidebar['id']] = $sidebar['name'];
214
  }
@@ -241,8 +244,8 @@ final class CAS_Sidebar_Manager
241
  */
242
  public function init_sidebar_type()
243
  {
244
- register_post_type(CAS_App::TYPE_SIDEBAR, array(
245
- 'labels' => array(
246
  'name' => __('Sidebars', 'content-aware-sidebars'),
247
  'singular_name' => __('Sidebar', 'content-aware-sidebars'),
248
  'add_new' => _x('Add New', 'sidebar', 'content-aware-sidebars'),
@@ -256,8 +259,8 @@ final class CAS_Sidebar_Manager
256
  'not_found_in_trash' => __('No sidebars found in Trash', 'content-aware-sidebars'),
257
  //wp-content-aware-engine specific
258
  'ca_title' => __('Where to display', 'content-aware-sidebars')
259
- ),
260
- 'capabilities' => array(
261
  'edit_post' => CAS_App::CAPABILITY,
262
  'read_post' => CAS_App::CAPABILITY,
263
  'delete_post' => CAS_App::CAPABILITY,
@@ -266,7 +269,7 @@ final class CAS_Sidebar_Manager
266
  'edit_others_posts' => CAS_App::CAPABILITY,
267
  'publish_posts' => CAS_App::CAPABILITY,
268
  'read_private_posts' => CAS_App::CAPABILITY
269
- ),
270
  'public' => false,
271
  'hierarchical' => false,
272
  'exclude_from_search' => true,
@@ -278,11 +281,11 @@ final class CAS_Sidebar_Manager
278
  'has_archive' => false,
279
  'rewrite' => false,
280
  'query_var' => false,
281
- 'supports' => array('title','page-attributes'),
282
  'menu_icon' => 'dashicons-welcome-widgets-menus',
283
  'can_export' => false,
284
  'delete_with_user' => false
285
- ));
286
 
287
  WPCACore::types()->add(CAS_App::TYPE_SIDEBAR);
288
  }
@@ -294,27 +297,27 @@ final class CAS_Sidebar_Manager
294
  */
295
  public function create_sidebars()
296
  {
297
- $sidebars = get_posts(array(
298
  'numberposts' => -1,
299
  'post_type' => CAS_App::TYPE_SIDEBAR,
300
- 'post_status' => array(
301
  CAS_App::STATUS_ACTIVE,
302
  CAS_App::STATUS_INACTIVE,
303
  CAS_App::STATUS_SCHEDULED
304
- ),
305
  'orderby' => 'title',
306
  'order' => 'ASC'
307
- ));
308
 
309
  //Register sidebars to add them to the list
310
  foreach ($sidebars as $post) {
311
  $this->sidebars[CAS_App::SIDEBAR_PREFIX.$post->ID] = $post;
312
- register_sidebar(array(
313
  'name' => $post->post_title ? $post->post_title : __('(no title)'),
314
  'id' => CAS_App::SIDEBAR_PREFIX.$post->ID,
315
  'before_sidebar' => '',
316
  'after_sidebar' => ''
317
- ));
318
  }
319
  }
320
 
@@ -328,13 +331,13 @@ final class CAS_Sidebar_Manager
328
  global $wp_registered_sidebars;
329
 
330
  //todo: only for manual
331
- $default_styles = array(
332
  'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
333
  'after_widget' => '</div>',
334
  'before_title' => '<h4 class="widget-title">',
335
  'after_title' => '</h4>'
336
- );
337
- $has_host = array(0 => 1,1 => 1,3 => 1);
338
  $metadata = $this->metadata();
339
 
340
  foreach ($this->sidebars as $id => $post) {
@@ -345,14 +348,14 @@ final class CAS_Sidebar_Manager
345
  //is called directly by other sidebar managers
346
  $host_id = $metadata->get('host')->get_data($post->ID);
347
  if (isset($wp_registered_sidebars[$host_id])) {
348
- foreach (array(
349
  'before_widget',
350
  'after_widget',
351
  'before_title',
352
  'after_title',
353
  'before_sidebar',
354
  'after_sidebar'
355
- ) as $pos) {
356
  if (isset($wp_registered_sidebars[$host_id][$pos])) {
357
  $args[$pos] = $wp_registered_sidebars[$host_id][$pos];
358
  }
@@ -376,11 +379,11 @@ final class CAS_Sidebar_Manager
376
  global $wp_registered_sidebars;
377
  $styles = $wp_registered_sidebars[$i];
378
  //Set user styles
379
- foreach (array(
380
  'widget',
381
  'title',
382
  'sidebar'
383
- ) as $pos) {
384
  if (isset($html[$pos],$html[$pos.'_class'])) {
385
  $e = esc_html($html[$pos]);
386
  $class = esc_html($html[$pos.'_class']);
@@ -415,9 +418,9 @@ final class CAS_Sidebar_Manager
415
 
416
  if ($posts) {
417
  $metadata = $this->metadata();
418
- $has_host = array(0 => 1,1 => 1,3 => 1);
419
 
420
- //replace and merge widgets, build replacement map
421
  foreach ($posts as $post) {
422
  $id = CAS_App::SIDEBAR_PREFIX . $post->ID;
423
 
@@ -439,7 +442,7 @@ final class CAS_Sidebar_Manager
439
 
440
  // Sidebar might not have any widgets. Get it anyway!
441
  if (!isset($sidebars_widgets[$id])) {
442
- $sidebars_widgets[$id] = array();
443
  }
444
 
445
  // If handle is merge or if handle is replace and host has already been replaced
@@ -502,11 +505,11 @@ final class CAS_Sidebar_Manager
502
  global $_wp_sidebars_widgets;
503
 
504
  // Grab args or defaults
505
- $args = wp_parse_args($args, array(
506
  'include' => '',
507
  'before' => '',
508
  'after' => ''
509
- ));
510
  extract($args, EXTR_SKIP);
511
 
512
  // Get sidebars
@@ -562,9 +565,9 @@ final class CAS_Sidebar_Manager
562
  */
563
  public function sidebar_shortcode($atts, $content = '')
564
  {
565
- $a = shortcode_atts(array(
566
  'id' => 0,
567
- ), $atts);
568
 
569
  $id = CAS_App::SIDEBAR_PREFIX.esc_attr($a['id']);
570
 
@@ -596,7 +599,7 @@ final class CAS_Sidebar_Manager
596
  */
597
  public function get_sidebar_styles($i)
598
  {
599
- $styles = array();
600
 
601
  $metadata = $this->metadata()->get('html');
602
  while ($i) {
@@ -626,7 +629,7 @@ final class CAS_Sidebar_Manager
626
  public function render_sidebar_before($i, $has_widgets)
627
  {
628
  //wp5.6 introduced before_sidebar without notice
629
- if (version_compare(get_bloginfo('version'),'5.6', '>=')) {
630
  return;
631
  }
632
 
@@ -647,7 +650,7 @@ final class CAS_Sidebar_Manager
647
  public function render_sidebar_after($i, $has_widgets)
648
  {
649
  //wp5.6 introduced after_sidebar without notice
650
- if (version_compare(get_bloginfo('version'),'5.6', '>=')) {
651
  return;
652
  }
653
  global $wp_registered_sidebars;
@@ -666,7 +669,7 @@ final class CAS_Sidebar_Manager
666
  public static function filter_password_protection($sidebars)
667
  {
668
  if (is_singular() && post_password_required()) {
669
- return array();
670
  }
671
  return $sidebars;
672
  }
@@ -684,7 +687,7 @@ final class CAS_Sidebar_Manager
684
  $metadata = $this->metadata()->get('visibility');
685
 
686
  //temporary filter until WPCACore allows filtering
687
- $user_visibility = is_user_logged_in() ? array(-1) : array();
688
  $user_visibility = apply_filters('cas/user_visibility', $user_visibility);
689
  foreach ($sidebars as $id => $sidebar) {
690
  $visibility = $metadata->get_data($id, true, false);
@@ -712,7 +715,7 @@ final class CAS_Sidebar_Manager
712
  $metadata = $this->metadata()->get('visibility');
713
 
714
  //temporary filter until WPCACore allows filtering
715
- $user_visibility = is_user_logged_in() ? array(-1) : array();
716
  $user_visibility = apply_filters('cas/user_visibility', $user_visibility);
717
 
718
  $visibility = $metadata->get_data($id, true, false);
@@ -747,4 +750,59 @@ final class CAS_Sidebar_Manager
747
  }
748
  }
749
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
750
  }
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  defined('ABSPATH') || exit;
21
  * Custom sidebars
22
  * @var array
23
  */
24
+ public $sidebars = [];
25
 
26
  /**
27
  * Cache replaced sidebars
28
  * @var array
29
  */
30
+ protected $replaced_sidebars = [];
31
 
32
  /**
33
  * Sidebar replacement map
34
  * @var array
35
  */
36
+ protected $replace_map = [];
37
 
38
  /**
39
  * @var array
45
  {
46
  add_action(
47
  'wpca/loaded',
48
+ [$this,'late_init']
49
  );
50
  add_action(
51
  'wp_head',
52
+ [$this,'sidebar_notify_theme_customizer']
53
  );
54
  add_action(
55
  'init',
56
+ [$this,'init_sidebar_type'],
57
  99
58
  );
59
  add_action(
60
  'widgets_init',
61
+ [$this,'create_sidebars'],
62
  99
63
  );
64
  add_action(
65
  'wp_loaded',
66
+ [$this,'set_sidebar_styles'],
67
  99
68
  );
69
 
70
+ add_filter('get_edit_post_link', [$this,'get_edit_post_link'], 10, 3);
71
+ add_filter('get_delete_post_link', [$this,'get_delete_post_link'], 10, 3);
72
+
73
  add_shortcode(
74
  'ca-sidebar',
75
+ [$this,'sidebar_shortcode']
76
  );
77
  }
78
 
89
  if (!is_admin()) {
90
  add_filter(
91
  'sidebars_widgets',
92
+ [$this,'replace_sidebar']
93
  );
94
  add_filter(
95
  'wpca/posts/sidebar',
96
+ [__CLASS__,'filter_password_protection']
97
  );
98
  add_filter(
99
  'wpca/posts/sidebar',
100
+ [$this,'filter_visibility']
101
  );
102
  add_filter(
103
  'cas/shortcode/display',
104
+ [$this,'filter_shortcode_visibility'],
105
  10,
106
  2
107
  );
108
  add_action(
109
  'dynamic_sidebar_before',
110
+ [$this,'render_sidebar_before'],
111
  9,
112
  2
113
  );
114
  add_action(
115
  'dynamic_sidebar_after',
116
+ [$this,'render_sidebar_after'],
117
  99,
118
  2
119
  );
146
  ->add(new WPCAMeta(
147
  'visibility',
148
  __('User Visibility', 'content-aware-sidebars'),
149
+ [],
150
  'multi',
151
+ [
152
+ 'general' => [
153
  'label' => 'General',
154
+ 'options' => [
155
  -1 => __('Logged-in', 'content-aware-sidebars')
156
+ ]
157
+ ]
158
+ ]
159
  ), 'visibility')
160
  ->add(new WPCAMeta(
161
  'handle',
162
  _x('Action', 'option', 'content-aware-sidebars'),
163
  0,
164
  'select',
165
+ [
166
  0 => __('Replace', 'content-aware-sidebars'),
167
  1 => __('Merge', 'content-aware-sidebars'),
168
  3 => __('Forced replace', 'content-aware-sidebars'),
169
  2 => __('Shortcode')
170
+ ],
171
  __('Replace host sidebar, merge with it or add sidebar manually.', 'content-aware-sidebars')
172
  ), 'handle')
173
  ->add(new WPCAMeta(
174
  'host',
175
  __('Target Sidebar', 'content-aware-sidebars'),
176
+ [],
177
  'multi',
178
+ []
179
  ), 'host')
180
  ->add(new WPCAMeta(
181
  'merge_pos',
182
  __('Merge Position', 'content-aware-sidebars'),
183
  1,
184
  'select',
185
+ [
186
  __('Top', 'content-aware-sidebars'),
187
  __('Bottom', 'content-aware-sidebars')
188
+ ],
189
  __('Place sidebar on top or bottom of host when merging.', 'content-aware-sidebars')
190
  ), 'merge_pos')
191
  ->add(new WPCAMeta(
192
  'html',
193
  __('HTML', 'content-aware-sidebars'),
194
+ [],
195
  'select',
196
+ ['']
197
  ), 'html');
198
  apply_filters('cas/metadata/init', $this->metadata);
199
  }
211
  global $wp_registered_sidebars;
212
 
213
  // List of sidebars
214
+ $sidebar_list = [];
215
  foreach ($wp_registered_sidebars as $sidebar) {
216
  $sidebar_list[$sidebar['id']] = $sidebar['name'];
217
  }
244
  */
245
  public function init_sidebar_type()
246
  {
247
+ register_post_type(CAS_App::TYPE_SIDEBAR, [
248
+ 'labels' => [
249
  'name' => __('Sidebars', 'content-aware-sidebars'),
250
  'singular_name' => __('Sidebar', 'content-aware-sidebars'),
251
  'add_new' => _x('Add New', 'sidebar', 'content-aware-sidebars'),
259
  'not_found_in_trash' => __('No sidebars found in Trash', 'content-aware-sidebars'),
260
  //wp-content-aware-engine specific
261
  'ca_title' => __('Where to display', 'content-aware-sidebars')
262
+ ],
263
+ 'capabilities' => [
264
  'edit_post' => CAS_App::CAPABILITY,
265
  'read_post' => CAS_App::CAPABILITY,
266
  'delete_post' => CAS_App::CAPABILITY,
269
  'edit_others_posts' => CAS_App::CAPABILITY,
270
  'publish_posts' => CAS_App::CAPABILITY,
271
  'read_private_posts' => CAS_App::CAPABILITY
272
+ ],
273
  'public' => false,
274
  'hierarchical' => false,
275
  'exclude_from_search' => true,
281
  'has_archive' => false,
282
  'rewrite' => false,
283
  'query_var' => false,
284
+ 'supports' => ['title','page-attributes'],
285
  'menu_icon' => 'dashicons-welcome-widgets-menus',
286
  'can_export' => false,
287
  'delete_with_user' => false
288
+ ]);
289
 
290
  WPCACore::types()->add(CAS_App::TYPE_SIDEBAR);
291
  }
297
  */
298
  public function create_sidebars()
299
  {
300
+ $sidebars = get_posts([
301
  'numberposts' => -1,
302
  'post_type' => CAS_App::TYPE_SIDEBAR,
303
+ 'post_status' => [
304
  CAS_App::STATUS_ACTIVE,
305
  CAS_App::STATUS_INACTIVE,
306
  CAS_App::STATUS_SCHEDULED
307
+ ],
308
  'orderby' => 'title',
309
  'order' => 'ASC'
310
+ ]);
311
 
312
  //Register sidebars to add them to the list
313
  foreach ($sidebars as $post) {
314
  $this->sidebars[CAS_App::SIDEBAR_PREFIX.$post->ID] = $post;
315
+ register_sidebar([
316
  'name' => $post->post_title ? $post->post_title : __('(no title)'),
317
  'id' => CAS_App::SIDEBAR_PREFIX.$post->ID,
318
  'before_sidebar' => '',
319
  'after_sidebar' => ''
320
+ ]);
321
  }
322
  }
323
 
331
  global $wp_registered_sidebars;
332
 
333
  //todo: only for manual
334
+ $default_styles = [
335
  'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
336
  'after_widget' => '</div>',
337
  'before_title' => '<h4 class="widget-title">',
338
  'after_title' => '</h4>'
339
+ ];
340
+ $has_host = [0 => 1,1 => 1,3 => 1];
341
  $metadata = $this->metadata();
342
 
343
  foreach ($this->sidebars as $id => $post) {
348
  //is called directly by other sidebar managers
349
  $host_id = $metadata->get('host')->get_data($post->ID);
350
  if (isset($wp_registered_sidebars[$host_id])) {
351
+ foreach ([
352
  'before_widget',
353
  'after_widget',
354
  'before_title',
355
  'after_title',
356
  'before_sidebar',
357
  'after_sidebar'
358
+ ] as $pos) {
359
  if (isset($wp_registered_sidebars[$host_id][$pos])) {
360
  $args[$pos] = $wp_registered_sidebars[$host_id][$pos];
361
  }
379
  global $wp_registered_sidebars;
380
  $styles = $wp_registered_sidebars[$i];
381
  //Set user styles
382
+ foreach ([
383
  'widget',
384
  'title',
385
  'sidebar'
386
+ ] as $pos) {
387
  if (isset($html[$pos],$html[$pos.'_class'])) {
388
  $e = esc_html($html[$pos]);
389
  $class = esc_html($html[$pos.'_class']);
418
 
419
  if ($posts) {
420
  $metadata = $this->metadata();
421
+ $has_host = [0 => 1,1 => 1,3 => 1];
422
 
423
+ //replace and merge widgets, build replacement map
424
  foreach ($posts as $post) {
425
  $id = CAS_App::SIDEBAR_PREFIX . $post->ID;
426
 
442
 
443
  // Sidebar might not have any widgets. Get it anyway!
444
  if (!isset($sidebars_widgets[$id])) {
445
+ $sidebars_widgets[$id] = [];
446
  }
447
 
448
  // If handle is merge or if handle is replace and host has already been replaced
505
  global $_wp_sidebars_widgets;
506
 
507
  // Grab args or defaults
508
+ $args = wp_parse_args($args, [
509
  'include' => '',
510
  'before' => '',
511
  'after' => ''
512
+ ]);
513
  extract($args, EXTR_SKIP);
514
 
515
  // Get sidebars
565
  */
566
  public function sidebar_shortcode($atts, $content = '')
567
  {
568
+ $a = shortcode_atts([
569
  'id' => 0,
570
+ ], $atts);
571
 
572
  $id = CAS_App::SIDEBAR_PREFIX.esc_attr($a['id']);
573
 
599
  */
600
  public function get_sidebar_styles($i)
601
  {
602
+ $styles = [];
603
 
604
  $metadata = $this->metadata()->get('html');
605
  while ($i) {
629
  public function render_sidebar_before($i, $has_widgets)
630
  {
631
  //wp5.6 introduced before_sidebar without notice
632
+ if (version_compare(get_bloginfo('version'), '5.6', '>=')) {
633
  return;
634
  }
635
 
650
  public function render_sidebar_after($i, $has_widgets)
651
  {
652
  //wp5.6 introduced after_sidebar without notice
653
+ if (version_compare(get_bloginfo('version'), '5.6', '>=')) {
654
  return;
655
  }
656
  global $wp_registered_sidebars;
669
  public static function filter_password_protection($sidebars)
670
  {
671
  if (is_singular() && post_password_required()) {
672
+ return [];
673
  }
674
  return $sidebars;
675
  }
687
  $metadata = $this->metadata()->get('visibility');
688
 
689
  //temporary filter until WPCACore allows filtering
690
+ $user_visibility = is_user_logged_in() ? [-1] : [];
691
  $user_visibility = apply_filters('cas/user_visibility', $user_visibility);
692
  foreach ($sidebars as $id => $sidebar) {
693
  $visibility = $metadata->get_data($id, true, false);
715
  $metadata = $this->metadata()->get('visibility');
716
 
717
  //temporary filter until WPCACore allows filtering
718
+ $user_visibility = is_user_logged_in() ? [-1] : [];
719
  $user_visibility = apply_filters('cas/user_visibility', $user_visibility);
720
 
721
  $visibility = $metadata->get_data($id, true, false);
750
  }
751
  }
752
  }
753
+
754
+ /**
755
+ * Get sidebar edit link
756
+ * TODO: Consider changing post type _edit_link instead
757
+ *
758
+ * @since 3.4
759
+ * @param string $link
760
+ * @param int $post_id
761
+ * @param string $context
762
+ * @return string
763
+ */
764
+ public function get_edit_post_link($link, $post_id, $context)
765
+ {
766
+ $post = get_post($post_id);
767
+ if ($post->post_type == CAS_App::TYPE_SIDEBAR) {
768
+ $sep = '&';
769
+ if ($context == 'display') {
770
+ $sep = '&amp;';
771
+ }
772
+ $link = admin_url('admin.php?page=wpcas-edit'.$sep.'sidebar_id='.$post_id);
773
+
774
+ //load page in all languages for wpml, polylang,
775
+ //ensures post type conditions are not filtered
776
+ if (defined('ICL_SITEPRESS_VERSION') || defined('POLYLANG_VERSION')) {
777
+ $link .= $sep.'lang=all';
778
+ }
779
+ }
780
+ return $link;
781
+ }
782
+
783
+ /**
784
+ * Get sidebar delete link
785
+ * TODO: Consider changing post type _edit_link instead
786
+ *
787
+ * @since 3.4
788
+ * @param string $link
789
+ * @param int $post_id
790
+ * @param boolean $force_delete
791
+ * @return string
792
+ */
793
+ public function get_delete_post_link($link, $post_id, $force_delete)
794
+ {
795
+ $post = get_post($post_id);
796
+ if ($post->post_type == CAS_App::TYPE_SIDEBAR) {
797
+ $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
798
+
799
+ $link = add_query_arg(
800
+ 'action',
801
+ $action,
802
+ admin_url('admin.php?page=wpcas-edit&sidebar_id='.$post_id)
803
+ );
804
+ $link = wp_nonce_url($link, "$action-post_{$post_id}");
805
+ }
806
+ return $link;
807
+ }
808
  }
view/meta_box_action.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  CAS_Sidebar_Edit::form_field('handle');
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  CAS_Sidebar_Edit::form_field('handle');
view/meta_box_advanced.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  if (!EMPTY_TRASH_DAYS) {
@@ -23,7 +23,7 @@ if (!EMPTY_TRASH_DAYS) {
23
  </td>
24
  </tr>
25
 
26
- <?php if (current_user_can("delete_post", $post->ID)) : ?>
27
  <tr>
28
  <td scope="row"></td>
29
  <td>
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  if (!EMPTY_TRASH_DAYS) {
23
  </td>
24
  </tr>
25
 
26
+ <?php if (current_user_can('delete_post', $post->ID)) : ?>
27
  <tr>
28
  <td scope="row"></td>
29
  <td>
view/meta_box_design.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  $url = 'https://dev.institute/wordpress-sidebars/pricing/?utm_source=plugin&utm_medium=popup&utm_content=design&utm_campaign=cas';
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  $url = 'https://dev.institute/wordpress-sidebars/pricing/?utm_source=plugin&utm_medium=popup&utm_content=design&utm_campaign=cas';
view/meta_box_html.php CHANGED
@@ -3,37 +3,37 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  $data = CAS_App::instance()->manager()->metadata()->get('html')->get_data($post->ID, true);
10
 
11
- $data_default = array_merge(array(
12
  'sidebar' => '',
13
  'sidebar_class' => '',
14
  'widget' => '',
15
  'widget_class' => 'widget %2$s',
16
  'title' => '',
17
  'title_class' => 'widget-title'
18
- ), $data);
19
 
20
- $sidebar_opts = array(
21
  'div' => 'div',
22
  'aside' => 'aside',
23
  'ul' => 'ul'
24
- );
25
- $widget_opts = array(
26
  'div' => 'div',
27
  'li' => 'li',
28
  'section' => 'section'
29
- );
30
- $widget_title_opts = array(
31
  'h2' => 'h2',
32
  'h3' => 'h3',
33
  'h4' => 'h4',
34
  'h5' => 'h5',
35
  'h6' => 'h6'
36
- );
37
 
38
  ?>
39
 
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  $data = CAS_App::instance()->manager()->metadata()->get('html')->get_data($post->ID, true);
10
 
11
+ $data_default = array_merge([
12
  'sidebar' => '',
13
  'sidebar_class' => '',
14
  'widget' => '',
15
  'widget_class' => 'widget %2$s',
16
  'title' => '',
17
  'title_class' => 'widget-title'
18
+ ], $data);
19
 
20
+ $sidebar_opts = [
21
  'div' => 'div',
22
  'aside' => 'aside',
23
  'ul' => 'ul'
24
+ ];
25
+ $widget_opts = [
26
  'div' => 'div',
27
  'li' => 'li',
28
  'section' => 'section'
29
+ ];
30
+ $widget_title_opts = [
31
  'h2' => 'h2',
32
  'h3' => 'h3',
33
  'h4' => 'h4',
34
  'h5' => 'h5',
35
  'h6' => 'h6'
36
+ ];
37
 
38
  ?>
39
 
view/meta_box_schedule.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  global $wp_locale;
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  global $wp_locale;
view/meta_box_status.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  $activate_date = $post->post_status == CAS_App::STATUS_SCHEDULED ? $post->post_date : '';
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  $activate_date = $post->post_status == CAS_App::STATUS_SCHEDULED ? $post->post_date : '';
view/meta_box_submit.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  $cas_fs = cas_fs();
@@ -35,11 +35,11 @@ if (post_type_supports($post->post_type, 'revisions')) {
35
  </div>
36
  <ul class="cas-overview-actions">
37
  <li style="overflow: hidden;">
38
- <span class="dashicons dashicons-calendar"></span> <strong><?php _e("Status", 'content-aware-sidebars'); ?></strong>
39
  <div class="wpca-pull-right">
40
  <a class="js-nav-link" href="#top#section-schedule"><?php _ex('Schedule', 'verb', 'content-aware-sidebars'); ?></a>
41
  <label class="cae-toggle">
42
- <input class="js-cas-status" type="checkbox" name="post_status" value="<?php echo CAS_App::STATUS_ACTIVE; ?>" <?php checked(in_array($post->post_status, array(CAS_App::STATUS_ACTIVE,'auto-draft')), true); ?> />
43
  <div class="cae-toggle-bar"></div>
44
  </label>
45
  </div>
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  $cas_fs = cas_fs();
35
  </div>
36
  <ul class="cas-overview-actions">
37
  <li style="overflow: hidden;">
38
+ <span class="dashicons dashicons-calendar"></span> <strong><?php _e('Status', 'content-aware-sidebars'); ?></strong>
39
  <div class="wpca-pull-right">
40
  <a class="js-nav-link" href="#top#section-schedule"><?php _ex('Schedule', 'verb', 'content-aware-sidebars'); ?></a>
41
  <label class="cae-toggle">
42
+ <input class="js-cas-status" type="checkbox" name="post_status" value="<?php echo CAS_App::STATUS_ACTIVE; ?>" <?php checked(in_array($post->post_status, [CAS_App::STATUS_ACTIVE,'auto-draft']), true); ?> />
43
  <div class="cae-toggle-bar"></div>
44
  </label>
45
  </div>
view/meta_box_support.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  $locale = get_locale();
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  $locale = get_locale();
view/notice_review.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  //updated class for wp4.0 and below
@@ -12,20 +12,20 @@
12
  <div class="notice notice-success updated js-cas-notice-review is-dismissible">
13
  <p>
14
  <?php printf(
15
- __("Hey %s, you have used %s for some time now, and I hope you like it so far!", 'content-aware-sidebars'),
16
  '<strong>'.$current_user->display_name.'</strong>',
17
  '<strong>Content Aware Sidebars</strong>'
18
  ); ?>
19
  <br>
20
  <?php printf(
21
- __("May I ask you to %ssupport it with a 5-star rating%s? I have spent countless hours on the plugin, and this will help make it even better.", 'content-aware-sidebars'),
22
  '<strong><a target="_blank" href="https://wordpress.org/support/plugin/content-aware-sidebars/reviews/?rate=5#new-post" data-cas-rating="1">',
23
  '</a></strong>'
24
  ); ?>
25
  <br><br>
26
- <?php _e("Your help is much appreciated. Thank you,", 'content-aware-sidebars'); ?>
27
  <br>
28
  - Joachim Jensen
29
  </p>
30
- <p><a target="_blank" class="button-primary" href="https://wordpress.org/support/plugin/content-aware-sidebars/reviews/?rate=5#new-post" data-cas-rating="1"><?php _e('OK, you deserve it', 'content-aware-sidebars'); ?></a> <button class="button-secondary"><?php _e("No, not good enough", 'content-aware-sidebars'); ?></button> <button class="button-secondary" data-cas-rating="1"><?php _e("I already rated it", 'content-aware-sidebars'); ?></button></p>
31
  </div>
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  //updated class for wp4.0 and below
12
  <div class="notice notice-success updated js-cas-notice-review is-dismissible">
13
  <p>
14
  <?php printf(
15
+ __('Hey %s, you have used %s for some time now, and I hope you like it so far!', 'content-aware-sidebars'),
16
  '<strong>'.$current_user->display_name.'</strong>',
17
  '<strong>Content Aware Sidebars</strong>'
18
  ); ?>
19
  <br>
20
  <?php printf(
21
+ __('May I ask you to %ssupport it with a 5-star rating%s? I have spent countless hours on the plugin, and this will help make it even better.', 'content-aware-sidebars'),
22
  '<strong><a target="_blank" href="https://wordpress.org/support/plugin/content-aware-sidebars/reviews/?rate=5#new-post" data-cas-rating="1">',
23
  '</a></strong>'
24
  ); ?>
25
  <br><br>
26
+ <?php _e('Your help is much appreciated. Thank you,', 'content-aware-sidebars'); ?>
27
  <br>
28
  - Joachim Jensen
29
  </p>
30
+ <p><a target="_blank" class="button-primary" href="https://wordpress.org/support/plugin/content-aware-sidebars/reviews/?rate=5#new-post" data-cas-rating="1"><?php _e('OK, you deserve it', 'content-aware-sidebars'); ?></a> <button class="button-secondary"><?php _e('No, not good enough', 'content-aware-sidebars'); ?></button> <button class="button-secondary" data-cas-rating="1"><?php _e('I already rated it', 'content-aware-sidebars'); ?></button></p>
31
  </div>
view/sidebars_quick_select.php CHANGED
@@ -3,7 +3,7 @@
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
- * @copyright 2020 by Joachim Jensen
7
  */
8
 
9
  $i = 0;
3
  * @package Content Aware Sidebars
4
  * @author Joachim Jensen <joachim@dev.institute>
5
  * @license GPLv3
6
+ * @copyright 2021 by Joachim Jensen
7
  */
8
 
9
  $i = 0;