Content Aware Sidebars – Unlimited Widget Areas - Version 0.5

Version Description

  • Added: search, 404, front page rules now supported
  • Fixed: custom tax and terms are now supported properly (again)
Download this release

Release Info

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

Code changes from version 0.3 to 0.5

Files changed (2) hide show
  1. content-aware-sidebars.php +253 -84
  2. readme.txt +37 -17
content-aware-sidebars.php CHANGED
@@ -6,10 +6,12 @@
6
  Plugin Name: Content Aware Sidebars
7
  Plugin URI: http://www.intox.dk/
8
  Description: Manage and show sidebars according to the content being viewed.
9
- Version: 0.3
10
  Author: Joachim Jensen
11
  Author URI: http://www.intox.dk/
12
- License:
 
 
13
 
14
  Copyright 2011 Joachim Jensen (email : jv@intox.dk)
15
 
@@ -29,8 +31,10 @@ License:
29
  */
30
  class ContentAwareSidebars {
31
 
32
- public $version = 0.3;
33
- public $settings = array();
 
 
34
 
35
  /**
36
  *
@@ -43,7 +47,7 @@ class ContentAwareSidebars {
43
  add_action('init', array(&$this,'init_sidebar_type'),20);
44
  add_action('widgets_init', array(&$this,'create_sidebars'));
45
  add_action('admin_init', array(&$this,'create_meta_boxes'));
46
- add_action('admin_head', array(&$this,'init_settings'));
47
  add_action('admin_menu', array(&$this,'clear_admin_menu'));
48
  add_action('save_post', array(&$this,'save_post'));
49
 
@@ -51,13 +55,29 @@ class ContentAwareSidebars {
51
 
52
  }
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  /**
55
  *
56
  * Create post meta fields
57
  * Loaded in admin_head due to $post. Should be loaded even later if possible.
58
  *
59
  */
60
- public function init_settings() {
61
  global $post, $wp_registered_sidebars;
62
 
63
  // List of sidebars
@@ -67,44 +87,78 @@ class ContentAwareSidebars {
67
  $sidebar_list[$sidebar['id']] = $sidebar['name'];
68
  }
69
 
70
- // List of public post types
71
- $post_type_list = array();
72
- foreach(get_post_types(array('public'=>true),'objects') as $post_type)
73
- $post_type_list[$post_type->name] = $post_type->label;
74
-
75
  // Meta fields
76
  $this->settings = array(
77
  'post_types' => array(
78
- 'name' => 'Post Types',
79
  'id' => 'post_types',
80
  'desc' => '',
81
- 'val' => '',
82
- 'type' => 'select-multi',
83
- 'list' => $post_type_list
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  ),
85
  'handle' => array(
86
- 'name' => 'Handle',
87
  'id' => 'handle',
88
- 'desc' => 'Replace host sidebar, merge with it or add sidebar manually.',
89
  'val' => 0,
90
  'type' => 'select',
91
- 'list' => array('Replace','Merge','Manual')
 
 
 
 
92
  ),
93
  'host' => array(
94
- 'name' => 'Host Sidebar',
95
  'id' => 'host',
96
- 'desc' => 'The sidebar that should be handled with. Nesting is possible. Manual handling makes this option superfluous.',
97
  'val' => 'sidebar-1',
98
  'type' => 'select',
99
  'list' => $sidebar_list
100
  ),
101
  'merge-pos' => array(
102
- 'name' => 'Merge position',
103
  'id' => 'merge-pos',
104
- 'desc' => 'Place sidebar on top or bottom of host when merging.',
105
  'val' => 1,
106
  'type' => 'select',
107
- 'list' => array('Top','Bottom')
 
 
 
108
  )
109
  );
110
  }
@@ -115,33 +169,34 @@ class ContentAwareSidebars {
115
  *
116
  */
117
  public function init_sidebar_type() {
118
- global $submenu;
 
 
 
 
119
  register_post_type('sidebar',array(
120
  'labels' => array(
121
- 'name' => _x('Sidebars', 'post type general name'),
122
- 'singular_name' => _x('Sidebar', 'post type singular name'),
123
- 'add_new' => _x('Add New', 'sidebar'),
124
- 'add_new_item' => __('Add New Sidebar'),
125
- 'edit_item' => __('Edit Sidebar'),
126
- 'new_item' => __('New Sidebar'),
127
- 'all_items' => __('All Sidebars'),
128
- 'view_item' => __('View Sidebar'),
129
- 'search_items' => __('Search Sidebars'),
130
- 'not_found' => __('No sidebars found'),
131
- 'not_found_in_trash' => __('No sidebars found in Trash'),
132
  'parent_item_colon' => '',
133
- 'menu_name' => 'Sidebars'
134
  ),
135
  'show_ui' => true,
136
  'query_var' => false,
137
  'rewrite' => false,
138
  'menu_position' => null,
139
  'supports' => array('title','excerpt','page-attributes'),
140
- 'taxonomies' => get_taxonomies(array('public'=>true))
141
- ));
142
-
143
-
144
-
145
  }
146
 
147
  /**
@@ -150,9 +205,8 @@ class ContentAwareSidebars {
150
  *
151
  */
152
  function clear_admin_menu() {
153
- $taxonomies = get_taxonomies(array('public'=>true));
154
- foreach($taxonomies as $tax)
155
- remove_submenu_page('edit.php?post_type=sidebar','edit-tags.php?taxonomy='.$tax.'&post_type=sidebar');
156
  }
157
 
158
  /**
@@ -212,38 +266,120 @@ class ContentAwareSidebars {
212
  }
213
  }
214
 
 
 
 
 
 
 
215
  public function get_sidebars($handle = "!= '2'") {
216
- global $wpdb;
217
 
218
  $errors = 1;
219
 
220
  $joins = "";
221
  $where = "";
222
 
223
- if(is_singular()) {
 
 
 
 
 
 
 
 
 
 
 
224
 
225
  $joins .= "LEFT JOIN $wpdb->postmeta post_types ON post_types.post_id = posts.ID AND post_types.meta_key = 'post_types' ";
226
  $where .= "(post_types.meta_value LIKE '%".serialize(get_post_type())."%'";
227
 
228
- if(has_term() || has_category() || has_tag()) {
 
 
 
 
 
 
 
 
229
 
230
- $post_terms = wp_get_object_terms(get_the_ID(),get_object_taxonomies(get_post_type()));
231
- $terms = array();
232
-
233
- //Grab posts terms by slugs.
234
- foreach($post_terms as $term)
235
- $terms[] = $term->slug;
236
-
237
- $joins .= "LEFT JOIN $wpdb->term_relationships term ON term.object_id = posts.ID ";
238
- $joins .= "LEFT JOIN $wpdb->term_taxonomy taxonomy ON taxonomy.term_taxonomy_id = term.term_taxonomy_id ";
239
- $joins .= "LEFT JOIN $wpdb->terms terms ON terms.term_id = taxonomy.term_id ";
240
- $where .= " OR terms.slug IN('".implode("','",$terms)."')";
 
241
 
 
 
242
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  $where .= ") AND ";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  $errors--;
245
  }
246
 
 
247
  if($errors)
248
  return false;
249
 
@@ -254,7 +390,7 @@ class ContentAwareSidebars {
254
  $post_status = "= 'publish'";
255
  $where .= "posts.post_status ".$post_status." AND ";
256
 
257
- // Get proper sidebars
258
  return $wpdb->get_results("
259
  SELECT
260
  posts.ID,
@@ -271,6 +407,9 @@ class ContentAwareSidebars {
271
  LEFT JOIN $wpdb->postmeta merge_pos
272
  ON merge_pos.post_id = posts.ID
273
  AND merge_pos.meta_key = 'merge-pos'
 
 
 
274
  $joins
275
  WHERE
276
  posts.post_type = 'sidebar' AND
@@ -289,12 +428,21 @@ class ContentAwareSidebars {
289
  public function create_meta_boxes() {
290
  add_meta_box(
291
  'ca-sidebar',
292
- 'Options',
293
  array(&$this,'meta_box_content'),
294
  'sidebar',
295
  'normal',
296
  'high'
297
- );
 
 
 
 
 
 
 
 
 
298
  }
299
 
300
  /**
@@ -303,30 +451,51 @@ class ContentAwareSidebars {
303
  *
304
  */
305
  public function meta_box_content() {
306
- $this->form_fields(array('post_types','handle','merge-pos','host'));
307
  }
308
 
309
  /**
310
  *
311
- * Create form fields
312
  *
313
  */
314
- private function form_fields($array) {
315
- global $post;
316
-
317
  // Use nonce for verification
318
  wp_nonce_field(basename(__FILE__),'_ca-sidebar-nonce');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  ?>
320
  <table class="form-table">
321
  <?php
322
- $array = array_intersect_key($this->settings,array_flip($array));
 
 
 
323
  foreach($array as $setting) :
324
 
325
- $meta = get_post_meta($post->ID, $setting['id'], true);
326
- $current = $meta != '' ? $meta : $setting['val'];
327
- ?>
 
328
  <tr valign="top">
329
- <th scope="row"><?php echo $setting['name'] ?></th>
330
  <td>
331
  <?php switch($setting['type']) :
332
  case 'select' :
@@ -343,9 +512,16 @@ class ContentAwareSidebars {
343
  }
344
  echo '</select>'."\n";
345
  break;
 
 
 
 
 
 
 
346
  case 'text' :
347
  default :
348
- echo '<input style="width:200px;" type="text" name="'.$setting['id'].'" value="'.implode(",",unserialize($current)).'" />'."\n";
349
  break;
350
  endswitch; ?>
351
  <br /><span class="description"><?php echo $setting['desc'] ?></span>
@@ -384,21 +560,13 @@ class ContentAwareSidebars {
384
  return $post_id;
385
 
386
  // Load settings manually here. This ought to be done with action/filter
387
- $this->init_settings();
388
 
389
  // Update values
390
  foreach ($this->settings as $field) {
391
  $old = get_post_meta($post_id, $field['id'], true);
392
- $new = $_POST[$field['id']];
393
-
394
- //switch($field['id']) {
395
- // case 'post_types' :
396
- // $new = serialize($new);
397
- // break;
398
- // default :
399
- // break;
400
- //}
401
-
402
  if ($new != '' && $new != $old) {
403
  update_post_meta($post_id, $field['id'], $new);
404
  }elseif ($new == '' && $old != '') {
@@ -426,7 +594,8 @@ $ca_sidebars = new ContentAwareSidebars();
426
  // Template function
427
  function display_ca_sidebar($args = array()) {
428
  global $ca_sidebars, $_wp_sidebars_widgets;
429
-
 
430
  $defaults = array (
431
  'before' => '<div id="sidebar" class="widget-area"><ul class="xoxo">',
432
  'after' => '</ul></div>'
6
  Plugin Name: Content Aware Sidebars
7
  Plugin URI: http://www.intox.dk/
8
  Description: Manage and show sidebars according to the content being viewed.
9
+ Version: 0.5
10
  Author: Joachim Jensen
11
  Author URI: http://www.intox.dk/
12
+ Text Domain: content-aware-sidebars
13
+ Domain Path: /lang/
14
+ License: GPL2
15
 
16
  Copyright 2011 Joachim Jensen (email : jv@intox.dk)
17
 
31
  */
32
  class ContentAwareSidebars {
33
 
34
+ protected $version = 0.5;
35
+ protected $settings = array();
36
+ protected $post_types = array();
37
+ protected $taxonomies = array();
38
 
39
  /**
40
  *
47
  add_action('init', array(&$this,'init_sidebar_type'),20);
48
  add_action('widgets_init', array(&$this,'create_sidebars'));
49
  add_action('admin_init', array(&$this,'create_meta_boxes'));
50
+ add_action('admin_head', array(&$this,'init_metadata'));
51
  add_action('admin_menu', array(&$this,'clear_admin_menu'));
52
  add_action('save_post', array(&$this,'save_post'));
53
 
55
 
56
  }
57
 
58
+ /**
59
+ *
60
+ * Initiate lists
61
+ *
62
+ */
63
+ private function init_settings() {
64
+
65
+ // Public post types
66
+ foreach(get_post_types(array('public'=>true),'objects') as $post_type)
67
+ $this->post_types[$post_type->name] = $post_type->label;
68
+
69
+ // Public taxonomies
70
+ foreach(get_taxonomies(array('public'=>true),'objects') as $tax)
71
+ $this->taxonomies[$tax->name] = $tax->label;
72
+ }
73
+
74
  /**
75
  *
76
  * Create post meta fields
77
  * Loaded in admin_head due to $post. Should be loaded even later if possible.
78
  *
79
  */
80
+ public function init_metadata() {
81
  global $post, $wp_registered_sidebars;
82
 
83
  // List of sidebars
87
  $sidebar_list[$sidebar['id']] = $sidebar['name'];
88
  }
89
 
 
 
 
 
 
90
  // Meta fields
91
  $this->settings = array(
92
  'post_types' => array(
93
+ 'name' => __('Post Types', 'content-aware-sidebars'),
94
  'id' => 'post_types',
95
  'desc' => '',
96
+ 'val' => array(),
97
+ 'type' => 'checkbox',
98
+ 'list' => $this->post_types
99
+ ),
100
+ 'taxonomies' => array(
101
+ 'name' => __('Taxonomies', 'content-aware-sidebars'),
102
+ 'id' => 'taxonomies',
103
+ 'desc' => '',
104
+ 'val' => array(),
105
+ 'type' => 'checkbox',
106
+ 'list' => $this->taxonomies
107
+ ),
108
+ 'static' => array(
109
+ 'name' => __('Static Pages', 'content-aware-sidebars'),
110
+ 'id' => 'static',
111
+ 'desc' => '',
112
+ 'val' => array(),
113
+ 'type' => 'checkbox',
114
+ 'list' => array(
115
+ 'front-page' => __('Front Page', 'content-aware-sidebars'),
116
+ 'search' => __('Search', 'content-aware-sidebars'),
117
+ '404' => __('404', 'content-aware-sidebars')
118
+ )
119
+ ),
120
+ 'exposure' => array(
121
+ 'name' => __('Exposure', 'content-aware-sidebars'),
122
+ 'id' => 'exposure',
123
+ 'desc' => __('Affects post types, taxonomies and taxonomy terms.', 'content-aware-sidebars'),
124
+ 'val' => 1,
125
+ 'type' => 'select',
126
+ 'list' => array(
127
+ __('Singular', 'content-aware-sidebars'),
128
+ __('Singular & Archive', 'content-aware-sidebars'),
129
+ __('Archive', 'content-aware-sidebars')
130
+ )
131
  ),
132
  'handle' => array(
133
+ 'name' => _x('Handle','option', 'content-aware-sidebars'),
134
  'id' => 'handle',
135
+ 'desc' => __('Replace host sidebar, merge with it or add sidebar manually.', 'content-aware-sidebars'),
136
  'val' => 0,
137
  'type' => 'select',
138
+ 'list' => array(
139
+ __('Replace', 'content-aware-sidebars'),
140
+ __('Merge', 'content-aware-sidebars'),
141
+ __('Manual', 'content-aware-sidebars')
142
+ )
143
  ),
144
  'host' => array(
145
+ 'name' => __('Host Sidebar', 'content-aware-sidebars'),
146
  'id' => 'host',
147
+ 'desc' => __('The sidebar that should be handled with. Nesting is possible. Manual handling makes this option superfluous.', 'content-aware-sidebars'),
148
  'val' => 'sidebar-1',
149
  'type' => 'select',
150
  'list' => $sidebar_list
151
  ),
152
  'merge-pos' => array(
153
+ 'name' => __('Merge position', 'content-aware-sidebars'),
154
  'id' => 'merge-pos',
155
+ 'desc' => __('Place sidebar on top or bottom of host when merging.', 'content-aware-sidebars'),
156
  'val' => 1,
157
  'type' => 'select',
158
+ 'list' => array(
159
+ __('Top', 'content-aware-sidebars'),
160
+ __('Bottom', 'content-aware-sidebars')
161
+ )
162
  )
163
  );
164
  }
169
  *
170
  */
171
  public function init_sidebar_type() {
172
+
173
+ load_plugin_textdomain('content-aware-sidebars', false, dirname( plugin_basename(__FILE__)).'/lang/');
174
+
175
+ $this->init_settings();
176
+
177
  register_post_type('sidebar',array(
178
  'labels' => array(
179
+ 'name' => __('Sidebars', 'content-aware-sidebars'),
180
+ 'singular_name' => __('Sidebar', 'content-aware-sidebars'),
181
+ 'add_new' => _x('Add New', 'sidebar', 'content-aware-sidebars'),
182
+ 'add_new_item' => __('Add New Sidebar', 'content-aware-sidebars'),
183
+ 'edit_item' => __('Edit Sidebar', 'content-aware-sidebars'),
184
+ 'new_item' => __('New Sidebar', 'content-aware-sidebars'),
185
+ 'all_items' => __('All Sidebars', 'content-aware-sidebars'),
186
+ 'view_item' => __('View Sidebar', 'content-aware-sidebars'),
187
+ 'search_items' => __('Search Sidebars', 'content-aware-sidebars'),
188
+ 'not_found' => __('No sidebars found', 'content-aware-sidebars'),
189
+ 'not_found_in_trash' => __('No sidebars found in Trash', 'content-aware-sidebars'),
190
  'parent_item_colon' => '',
191
+ 'menu_name' => __('Sidebars', 'content-aware-sidebars')
192
  ),
193
  'show_ui' => true,
194
  'query_var' => false,
195
  'rewrite' => false,
196
  'menu_position' => null,
197
  'supports' => array('title','excerpt','page-attributes'),
198
+ 'taxonomies' => array_flip($this->taxonomies)
199
+ ));
 
 
 
200
  }
201
 
202
  /**
205
  *
206
  */
207
  function clear_admin_menu() {
208
+ foreach($this->taxonomies as $key => $value)
209
+ remove_submenu_page('edit.php?post_type=sidebar','edit-tags.php?taxonomy='.$key.'&amp;post_type=sidebar');
 
210
  }
211
 
212
  /**
266
  }
267
  }
268
 
269
+ /**
270
+ *
271
+ * Query sidebars according to content
272
+ * @return array|bool
273
+ *
274
+ */
275
  public function get_sidebars($handle = "!= '2'") {
276
+ global $wpdb, $post_type;
277
 
278
  $errors = 1;
279
 
280
  $joins = "";
281
  $where = "";
282
 
283
+ // Front page
284
+ if(is_front_page()) {
285
+
286
+ $joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
287
+
288
+ $where .= "(static.meta_value LIKE '%".serialize('front-page')."%') AND ";
289
+ $where .= "exposure.meta_value <= '1' AND ";
290
+
291
+ $errors--;
292
+
293
+ // Single content
294
+ } elseif(is_singular()) {
295
 
296
  $joins .= "LEFT JOIN $wpdb->postmeta post_types ON post_types.post_id = posts.ID AND post_types.meta_key = 'post_types' ";
297
  $where .= "(post_types.meta_value LIKE '%".serialize(get_post_type())."%'";
298
 
299
+ $post_taxonomies = get_object_taxonomies(get_post_type());
300
+
301
+ // Check if content has any taxonomies supported
302
+ if($post_taxonomies) {
303
+ $post_terms = wp_get_object_terms(get_the_ID(),$post_taxonomies);
304
+ // Check if content has any actual taxonomy terms
305
+ if($post_terms) {
306
+ $terms = array();
307
+ $taxonomies = array();
308
 
309
+ //Grab posts terms and make where rules for taxonomies.
310
+ foreach($post_terms as $term) {
311
+ $terms[] = $term->slug;
312
+ if(!isset($taxonomies[$term->taxonomy])) {
313
+ $where .= " OR post_tax.meta_value LIKE '%".$taxonomies[$term->taxonomy] = $term->taxonomy."%'";
314
+ }
315
+ }
316
+
317
+ $joins .= "LEFT JOIN $wpdb->term_relationships term ON term.object_id = posts.ID ";
318
+ $joins .= "LEFT JOIN $wpdb->term_taxonomy taxonomy ON taxonomy.term_taxonomy_id = term.term_taxonomy_id ";
319
+ $joins .= "LEFT JOIN $wpdb->terms terms ON terms.term_id = taxonomy.term_id ";
320
+ $joins .= "LEFT JOIN $wpdb->postmeta post_tax ON post_tax.post_id = posts.ID AND post_tax.meta_key = 'taxonomies'";
321
 
322
+ $where .= " OR terms.slug IN('".implode("','",$terms)."')";
323
+ }
324
  }
325
+
326
+ $where .= ") AND ";
327
+ $where .= "exposure.meta_value <= '1' AND ";
328
+
329
+ $errors--;
330
+
331
+ // Taxonomy archives
332
+ } elseif(is_tax() || is_category() || is_tag()) {
333
+
334
+ $term = get_queried_object();
335
+
336
+ $joins .= "LEFT JOIN $wpdb->term_relationships term ON term.object_id = posts.ID ";
337
+ $joins .= "LEFT JOIN $wpdb->term_taxonomy taxonomy ON taxonomy.term_taxonomy_id = term.term_taxonomy_id ";
338
+ $joins .= "LEFT JOIN $wpdb->terms terms ON terms.term_id = taxonomy.term_id ";
339
+ $joins .= "LEFT JOIN $wpdb->postmeta post_tax ON post_tax.post_id = posts.ID AND post_tax.meta_key = 'taxonomies'";
340
+
341
+ $where .= "(terms.slug = '$term->slug'";
342
+ $where .= " OR post_tax.meta_value LIKE '%$term->taxonomy%'";
343
  $where .= ") AND ";
344
+ $where .= "exposure.meta_value >= '1' AND ";
345
+
346
+ $errors--;
347
+
348
+ // Post Type archives
349
+ } elseif(is_post_type_archive() || is_home()) {
350
+
351
+ // Home has post as default post type
352
+ if(!$post_type) $post_type = 'post';
353
+
354
+ $joins .= "LEFT JOIN $wpdb->postmeta post_types ON post_types.post_id = posts.ID AND post_types.meta_key = 'post_types' ";
355
+
356
+ $where .= "(post_types.meta_value LIKE '%$post_type%') AND ";
357
+ $where .= "exposure.meta_value >= '1' AND ";
358
+
359
+ $errors--;
360
+
361
+ // Search
362
+ } elseif(is_search()) {
363
+
364
+ $joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
365
+
366
+ $where .= "(static.meta_value LIKE '%".serialize('search')."%') AND ";
367
+ $where .= "exposure.meta_value <= '1' AND ";
368
+
369
+ $errors--;
370
+
371
+ // 404
372
+ } elseif(is_404()) {
373
+
374
+ $joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
375
+
376
+ $where .= "(static.meta_value LIKE '%".serialize('404')."%') AND ";
377
+ $where .= "exposure.meta_value <= '1' AND ";
378
+
379
  $errors--;
380
  }
381
 
382
+ // Check if any errors are left
383
  if($errors)
384
  return false;
385
 
390
  $post_status = "= 'publish'";
391
  $where .= "posts.post_status ".$post_status." AND ";
392
 
393
+ // Return proper sidebars
394
  return $wpdb->get_results("
395
  SELECT
396
  posts.ID,
407
  LEFT JOIN $wpdb->postmeta merge_pos
408
  ON merge_pos.post_id = posts.ID
409
  AND merge_pos.meta_key = 'merge-pos'
410
+ LEFT JOIN $wpdb->postmeta exposure
411
+ ON exposure.post_id = posts.ID
412
+ AND exposure.meta_key = 'exposure'
413
  $joins
414
  WHERE
415
  posts.post_type = 'sidebar' AND
428
  public function create_meta_boxes() {
429
  add_meta_box(
430
  'ca-sidebar',
431
+ __('Options', 'content-aware-sidebars'),
432
  array(&$this,'meta_box_content'),
433
  'sidebar',
434
  'normal',
435
  'high'
436
+ );
437
+ add_meta_box(
438
+ 'ca-sidebar-author-words',
439
+ __('Words from the author', 'content-aware-sidebars'),
440
+ array(&$this,'meta_box_author_words'),
441
+ 'sidebar',
442
+ 'side',
443
+ 'high'
444
+ );
445
+
446
  }
447
 
448
  /**
451
  *
452
  */
453
  public function meta_box_content() {
454
+ $this->form_fields();
455
  }
456
 
457
  /**
458
  *
459
+ * Author words content
460
  *
461
  */
462
+ public function meta_box_author_words() {
 
 
463
  // Use nonce for verification
464
  wp_nonce_field(basename(__FILE__),'_ca-sidebar-nonce');
465
+ ?>
466
+ <div style="text-align:center;">
467
+ <div><p><?php _e('If you love this plugin, please consider donating.', 'content-aware-sidebars'); ?></p></div>
468
+ <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KPZHE6A72LEN4&lc=US&item_name=WordPress%20Plugin%3a%20Content%20Aware%20Sidebars&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"
469
+ target="_blank" title="PayPal - The safer, easier way to pay online!">
470
+ <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" width="147" height="47" alt="PayPal - The safer, easier way to pay online!">
471
+ </a>
472
+ </div>
473
+ <?php
474
+ }
475
+
476
+ /**
477
+ *
478
+ * Create form fields
479
+ *
480
+ */
481
+ private function form_fields($array = array(), $show_name = 1) {
482
+ global $post;
483
+
484
  ?>
485
  <table class="form-table">
486
  <?php
487
+ if(!empty($array))
488
+ $array = array_intersect_key($this->settings,array_flip($array));
489
+ else
490
+ $array = $this->settings;
491
  foreach($array as $setting) :
492
 
493
+ $meta = get_post_meta($post->ID, $setting['id'], true);
494
+ $current = $meta != '' ? $meta : $setting['val'];
495
+ ?>
496
+
497
  <tr valign="top">
498
+ <?php if($show_name) echo '<th scope="row">'.$setting['name'].'</th>'; ?>
499
  <td>
500
  <?php switch($setting['type']) :
501
  case 'select' :
512
  }
513
  echo '</select>'."\n";
514
  break;
515
+ case 'checkbox' :
516
+ echo '<ul>'."\n";
517
+ foreach($setting['list'] as $key => $value) {
518
+ echo '<li><label><input type="checkbox" name="'.$setting['id'].'[]" value="'.$key.'"'.(in_array($key,$current) ? ' checked="checked"' : '').' /> '.$value.'</label></li>'."\n";
519
+ }
520
+ echo '</ul>'."\n";
521
+ break;
522
  case 'text' :
523
  default :
524
+ echo '<input style="width:200px;" type="text" name="'.$setting['id'].'" value="'.$current.'" />'."\n";
525
  break;
526
  endswitch; ?>
527
  <br /><span class="description"><?php echo $setting['desc'] ?></span>
560
  return $post_id;
561
 
562
  // Load settings manually here. This ought to be done with action/filter
563
+ $this->init_metadata();
564
 
565
  // Update values
566
  foreach ($this->settings as $field) {
567
  $old = get_post_meta($post_id, $field['id'], true);
568
+ $new = isset($_POST[$field['id']]) ? $_POST[$field['id']] : '';
569
+
 
 
 
 
 
 
 
 
570
  if ($new != '' && $new != $old) {
571
  update_post_meta($post_id, $field['id'], $new);
572
  }elseif ($new == '' && $old != '') {
594
  // Template function
595
  function display_ca_sidebar($args = array()) {
596
  global $ca_sidebars, $_wp_sidebars_widgets;
597
+
598
+ // Grab args or defaults
599
  $defaults = array (
600
  'before' => '<div id="sidebar" class="widget-area"><ul class="xoxo">',
601
  'after' => '</ul></div>'
readme.txt CHANGED
@@ -1,36 +1,40 @@
1
  === Plugin Name ===
2
  Contributors: intoxstudio
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KPZHE6A72LEN4&lc=US&item_name=WordPress%20Plugin%3a%20Content%20Aware%20Sidebars&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
4
- Tags: sidebar, widget, content aware, post type, taxonomy, term
5
- Requires at least: 3.0
6
  Tested up to: 3.2.1
7
- Stable tag: 0.3
8
 
9
  Manage and show sidebars according to the content being viewed.
10
 
11
  == Description ==
12
 
13
- Manage an infinite number of sidebars. Each with different rules for which content they should be visible with. Creating flexible sidebars has never been easier, and no code is needed at all as everything is done in a simple GUI.
 
14
 
15
- Current features include:
16
 
17
- * Show sidebars with specific post types only
18
- * Show sidebars with posts containing specific taxonomy terms only
 
 
19
  * Merge new sidebars with others, replace them or simply add them to your theme manually
20
  * Create complex content with nested sidebars
21
  * Private sidebars only for members
22
  * Schedule sidebars for later publishing
23
 
24
- Some upcoming features:
25
 
26
- * Show sidebars in a time span only
27
- * Show sidebars with (taxonomy term and post type) archives
28
 
29
- If you have any suggestions, please send a mail to jv[at]intox.dk or contact me at www.intox.dk.
 
 
30
 
31
  == Installation ==
32
 
33
- Do as follows
34
 
35
  1. Upload the full plugin directory to your `/wp-content/plugins/` directory or install the plugin through `Plugins` in the administration
36
  1. Activate the plugin through `Plugins` in the administration
@@ -52,9 +56,21 @@ You are.
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  = 0.3 =
56
 
57
- * Added: Sidebars can now be private
58
  * Fixed: taxonomy terms are now supported by template function
59
  * Fixed: faster rule recognition and handling
60
  * Fixed: custom taxonomies are now supported properly
@@ -74,10 +90,14 @@ You are.
74
 
75
  == Upgrade Notice ==
76
 
77
- = 0.1 =
 
 
78
 
79
- * Hello World
80
 
81
- == Translations ==
 
 
82
 
83
- None yet. Might come in the future. Do you want to contribute? Send a mail to jv[at]intox.dk
1
  === Plugin Name ===
2
  Contributors: intoxstudio
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KPZHE6A72LEN4&lc=US&item_name=WordPress%20Plugin%3a%20Content%20Aware%20Sidebars&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
4
+ Tags: sidebar, widget, content aware, post type, taxonomy, term, archive
5
+ Requires at least: 3.1
6
  Tested up to: 3.2.1
7
+ Stable tag: 0.5
8
 
9
  Manage and show sidebars according to the content being viewed.
10
 
11
  == Description ==
12
 
13
+ Manage an infinite number of sidebars. Each with different rules for which content they should be visible with. Creating flexible sidebars has never been easier, and no code is needed at all as everything is done in the administration.
14
+ No extra database tables or table columns will be added.
15
 
16
+ = Features =
17
 
18
+ * Show sidebars with specific post types
19
+ * Show sidebars with posts containing specific taxonomies or taxonomy terms
20
+ * Show sidebars with specific post type archives, taxonomy archives or taxonomy term archives
21
+ * Show sidebars with search, 404 page and front page
22
  * Merge new sidebars with others, replace them or simply add them to your theme manually
23
  * Create complex content with nested sidebars
24
  * Private sidebars only for members
25
  * Schedule sidebars for later publishing
26
 
27
+ = Translations =
28
 
29
+ Content Aware Sidebars can now be translated. If you want to help, please send your translation to jv[at]intox.dk!
 
30
 
31
+ = Contact =
32
+
33
+ www.intox.dk
34
 
35
  == Installation ==
36
 
37
+ Easy install:
38
 
39
  1. Upload the full plugin directory to your `/wp-content/plugins/` directory or install the plugin through `Plugins` in the administration
40
  1. Activate the plugin through `Plugins` in the administration
56
 
57
  == Changelog ==
58
 
59
+ = 0.5 =
60
+
61
+ * Added: search, 404, front page rules now supported
62
+ * Fixed: custom tax and terms are now supported properly (again)
63
+
64
+ = 0.4 =
65
+
66
+ * Added: post type archives, taxonomy archives and taxonomy terms archives now supported
67
+ * Added: taxonomy rules
68
+ * Added: removable donation button
69
+ * Fixed: faster!
70
+
71
  = 0.3 =
72
 
73
+ * Added: sidebars can now be private
74
  * Fixed: taxonomy terms are now supported by template function
75
  * Fixed: faster rule recognition and handling
76
  * Fixed: custom taxonomies are now supported properly
90
 
91
  == Upgrade Notice ==
92
 
93
+ = 0.5 =
94
+
95
+ * Note that the plugin now requires at least WordPress 3.1 because of post type archives.
96
 
97
+ = 0.4 =
98
 
99
+ * All current custom sidebars have to be updated after plugin upgrade due to the new archive rules
100
+
101
+ = 0.1 =
102
 
103
+ * Hello World