Version Description
- Added: sidebars will be displayed even if empty (i.e. hidden)
- Added: author rules on singulars and archives
- Added: page template rules
- Added: javascript handling for disabling/enabling specific input on editor page
- Fixed: minor tweak for full compatibility with wp3.3
- Fixed: function for meta boxes is called only on editor page
- Fixed: proper column sorting in administration
- Fixed: specific post type label not supported in WP3.1.x
- Fixed: type (array) not supported as post_status in get_posts() in WP3.1.x
- Fixed: code cleanup
Download this release
Release Info
Developer | intoxstudio |
Plugin | Content Aware Sidebars – Unlimited Widget Areas |
Version | 0.7 |
Comparing to | |
See all releases |
Code changes from version 0.6.3 to 0.7
- content-aware-sidebars.php +216 -115
- js/cas_admin.js +83 -0
- readme.txt +44 -15
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- screenshot-4.png +0 -0
- screenshot-5.png +0 -0
- walker.php +37 -57
content-aware-sidebars.php
CHANGED
@@ -6,7 +6,7 @@
|
|
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.
|
10 |
Author: Joachim Jensen
|
11 |
Author URI: http://www.intox.dk/
|
12 |
Text Domain: content-aware-sidebars
|
@@ -31,13 +31,13 @@ License: GPL2
|
|
31 |
*/
|
32 |
class ContentAwareSidebars {
|
33 |
|
34 |
-
protected $
|
35 |
protected $post_types = array();
|
36 |
protected $post_type_objects = array();
|
37 |
protected $taxonomies = array();
|
38 |
protected $taxonomy_objects = array();
|
39 |
protected $sidebar_cache = array();
|
40 |
-
|
41 |
/**
|
42 |
*
|
43 |
* Constructor
|
@@ -51,50 +51,31 @@ class ContentAwareSidebars {
|
|
51 |
add_filter('request', array(&$this,'admin_column_orderby'));
|
52 |
add_filter('default_hidden_meta_boxes', array(&$this,'change_default_hidden'),10,2);
|
53 |
add_filter('manage_edit-sidebar_columns', array(&$this,'admin_column_headers'));
|
54 |
-
add_filter('manage_edit-sidebar_sortable_columns', array(&$this,'
|
55 |
add_filter('manage_posts_custom_column', array(&$this,'admin_column_rows'),10,3);
|
56 |
add_filter('post_row_actions', array(&$this,'sidebar_row_actions'),10,2);
|
57 |
add_filter('post_updated_messages', array(&$this,'sidebar_updated_messages'));
|
58 |
|
59 |
add_action('init', array(&$this,'init_sidebar_type'),50);
|
60 |
add_action('widgets_init', array(&$this,'create_sidebars'));
|
61 |
-
add_action('
|
62 |
-
add_action('
|
63 |
add_action('admin_menu', array(&$this,'clear_admin_menu'));
|
64 |
add_action('save_post', array(&$this,'save_post'));
|
|
|
|
|
65 |
|
66 |
register_activation_hook(__FILE__, array(&$this,'upon_activation'));
|
67 |
|
68 |
}
|
69 |
-
|
70 |
-
|
71 |
-
/**
|
72 |
-
*
|
73 |
-
* Initiate lists
|
74 |
-
*
|
75 |
-
*/
|
76 |
-
private function init_settings() {
|
77 |
-
// Public post types
|
78 |
-
foreach(get_post_types(array('public'=>true),'objects') as $post_type) {
|
79 |
-
$this->post_types[$post_type->name] = $post_type->label;
|
80 |
-
$this->post_type_objects[$post_type->name] = $post_type;
|
81 |
-
}
|
82 |
-
|
83 |
-
// Public taxonomies
|
84 |
-
foreach(get_taxonomies(array('public'=>true),'objects') as $tax) {
|
85 |
-
$this->taxonomies[$tax->name] = $tax->label;
|
86 |
-
$this->taxonomy_objects[$tax->name] = $tax;
|
87 |
-
}
|
88 |
-
}
|
89 |
|
90 |
/**
|
91 |
*
|
92 |
* Create post meta fields
|
93 |
-
* Loaded in admin_head due to $post. Should be loaded even later if possible.
|
94 |
*
|
95 |
*/
|
96 |
-
|
97 |
-
global $post, $wp_registered_sidebars;
|
98 |
|
99 |
// List of sidebars
|
100 |
$sidebar_list = array();
|
@@ -103,8 +84,14 @@ class ContentAwareSidebars {
|
|
103 |
$sidebar_list[$sidebar['id']] = $sidebar['name'];
|
104 |
}
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
// Meta fields
|
107 |
-
$this->
|
108 |
'post_types' => array(
|
109 |
'name' => __('Post Types', 'content-aware-sidebars'),
|
110 |
'id' => 'post_types',
|
@@ -121,6 +108,22 @@ class ContentAwareSidebars {
|
|
121 |
'type' => 'checkbox',
|
122 |
'list' => $this->taxonomies
|
123 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
'static' => array(
|
125 |
'name' => __('Static Pages', 'content-aware-sidebars'),
|
126 |
'id' => 'static',
|
@@ -188,8 +191,19 @@ class ContentAwareSidebars {
|
|
188 |
|
189 |
load_plugin_textdomain('content-aware-sidebars', false, dirname( plugin_basename(__FILE__)).'/lang/');
|
190 |
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
|
|
193 |
register_post_type('sidebar',array(
|
194 |
'labels' => array(
|
195 |
'name' => __('Sidebars', 'content-aware-sidebars'),
|
@@ -258,10 +272,11 @@ class ContentAwareSidebars {
|
|
258 |
*
|
259 |
*/
|
260 |
public function create_sidebars() {
|
|
|
261 |
$posts = get_posts(array(
|
262 |
'numberposts' => -1,
|
263 |
'post_type' => 'sidebar',
|
264 |
-
'post_status' =>
|
265 |
));
|
266 |
foreach($posts as $post)
|
267 |
register_sidebar( array(
|
@@ -277,7 +292,7 @@ class ContentAwareSidebars {
|
|
277 |
|
278 |
/**
|
279 |
*
|
280 |
-
* Add
|
281 |
*
|
282 |
*/
|
283 |
public function admin_column_headers($columns) {
|
@@ -292,6 +307,22 @@ class ContentAwareSidebars {
|
|
292 |
$columns
|
293 |
);
|
294 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
/**
|
297 |
*
|
@@ -315,28 +346,17 @@ class ContentAwareSidebars {
|
|
315 |
*/
|
316 |
public function admin_column_rows($column_name,$post_id) {
|
317 |
|
318 |
-
//
|
319 |
-
if(!$this->
|
320 |
|
321 |
$current = get_post_meta($post_id,$column_name,true);
|
322 |
-
$current_from_list = $this->
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
} elseif($current == 1) {
|
330 |
-
printf(__("Merge with %s",'content-aware-sidebars'),$host);
|
331 |
-
} else {
|
332 |
-
echo $current_from_list;
|
333 |
-
}
|
334 |
-
break;
|
335 |
-
case 'exposure':
|
336 |
-
case 'merge-pos':
|
337 |
-
echo $current_from_list;
|
338 |
-
break;
|
339 |
-
}
|
340 |
}
|
341 |
|
342 |
/**
|
@@ -359,8 +379,8 @@ class ContentAwareSidebars {
|
|
359 |
|
360 |
/**
|
361 |
*
|
362 |
-
* Replace a sidebar with content aware sidebars
|
363 |
-
* Handles
|
364 |
*
|
365 |
*/
|
366 |
public function replace_sidebar() {
|
@@ -374,10 +394,14 @@ class ContentAwareSidebars {
|
|
374 |
|
375 |
$id = 'ca-sidebar-'.$post->ID;
|
376 |
|
377 |
-
// Check for correct handling
|
378 |
-
if ($post->handle == 2
|
379 |
continue;
|
380 |
|
|
|
|
|
|
|
|
|
381 |
// If host has already been replaced, merge with it instead. Might change in future.
|
382 |
if($post->handle || isset($handled_already[$post->host])) {
|
383 |
if($post->merge_pos)
|
@@ -398,7 +422,7 @@ class ContentAwareSidebars {
|
|
398 |
*
|
399 |
*/
|
400 |
public function get_sidebars() {
|
401 |
-
global $wpdb, $post_type;
|
402 |
|
403 |
// Return cache if present
|
404 |
if(!empty($this->sidebar_cache)) {
|
@@ -408,8 +432,6 @@ class ContentAwareSidebars {
|
|
408 |
return $this->sidebar_cache;
|
409 |
}
|
410 |
|
411 |
-
$errors = 1;
|
412 |
-
|
413 |
$joins = "";
|
414 |
$where = "";
|
415 |
|
@@ -418,21 +440,29 @@ class ContentAwareSidebars {
|
|
418 |
|
419 |
$joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
|
420 |
|
421 |
-
$where .= "(static.meta_value LIKE '%
|
422 |
-
$where .= "exposure.meta_value <= '1' AND ";
|
423 |
-
|
424 |
-
$errors--;
|
425 |
|
426 |
// Single content
|
427 |
} elseif(is_singular()) {
|
428 |
|
|
|
429 |
$joins .= "LEFT JOIN $wpdb->postmeta post_types ON post_types.post_id = posts.ID AND post_types.meta_key = 'post_types' ";
|
430 |
-
$where .= "(post_types.meta_value LIKE '%".serialize(get_post_type())."%'";
|
431 |
-
|
|
|
|
|
|
|
432 |
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
434 |
|
435 |
// Check if content has any taxonomies supported
|
|
|
436 |
if($post_taxonomies) {
|
437 |
$post_terms = wp_get_object_terms(get_the_ID(),$post_taxonomies);
|
438 |
// Check if content has any actual taxonomy terms
|
@@ -460,8 +490,6 @@ class ContentAwareSidebars {
|
|
460 |
$where .= ") AND ";
|
461 |
$where .= "exposure.meta_value <= '1' AND ";
|
462 |
|
463 |
-
$errors--;
|
464 |
-
|
465 |
// Taxonomy archives
|
466 |
} elseif(is_tax() || is_category() || is_tag()) {
|
467 |
|
@@ -473,11 +501,9 @@ class ContentAwareSidebars {
|
|
473 |
$joins .= "LEFT JOIN $wpdb->postmeta post_tax ON post_tax.post_id = posts.ID AND post_tax.meta_key = 'taxonomies'";
|
474 |
|
475 |
$where .= "(terms.slug = '$term->slug'";
|
476 |
-
$where .= " OR post_tax.meta_value LIKE '
|
477 |
$where .= ") AND ";
|
478 |
-
$where .= "exposure.meta_value >= '1' AND ";
|
479 |
-
|
480 |
-
$errors--;
|
481 |
|
482 |
// Post Type archives
|
483 |
} elseif(is_post_type_archive() || is_home()) {
|
@@ -486,37 +512,35 @@ class ContentAwareSidebars {
|
|
486 |
if(!$post_type) $post_type = 'post';
|
487 |
|
488 |
$joins .= "LEFT JOIN $wpdb->postmeta post_types ON post_types.post_id = posts.ID AND post_types.meta_key = 'post_types' ";
|
489 |
-
|
490 |
-
$where .= "
|
491 |
-
|
492 |
-
|
493 |
-
|
|
|
|
|
|
|
|
|
494 |
|
495 |
// Search
|
496 |
} elseif(is_search()) {
|
497 |
|
498 |
-
$joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
|
499 |
-
|
500 |
-
$where .= "
|
501 |
-
$where .= "exposure.meta_value <= '1' AND ";
|
502 |
-
|
503 |
-
$errors--;
|
504 |
|
505 |
// 404
|
506 |
} elseif(is_404()) {
|
507 |
|
508 |
-
$joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
|
509 |
-
|
510 |
-
$where .= "(static.meta_value LIKE '%".serialize('404')."%') AND ";
|
511 |
$where .= "exposure.meta_value <= '1' AND ";
|
512 |
|
513 |
-
$errors--;
|
514 |
}
|
515 |
|
516 |
-
// Check if any
|
517 |
-
if(
|
518 |
return false;
|
519 |
-
}
|
520 |
|
521 |
// Show private sidebars or not
|
522 |
if(current_user_can('read_private_posts'))
|
@@ -564,6 +588,11 @@ class ContentAwareSidebars {
|
|
564 |
*
|
565 |
*/
|
566 |
public function create_meta_boxes() {
|
|
|
|
|
|
|
|
|
|
|
567 |
// Author Words
|
568 |
add_meta_box(
|
569 |
'ca-sidebar-author-words',
|
@@ -597,6 +626,21 @@ class ContentAwareSidebars {
|
|
597 |
$tax
|
598 |
);
|
599 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
// Options
|
601 |
add_meta_box(
|
602 |
'ca-sidebar',
|
@@ -626,12 +670,17 @@ class ContentAwareSidebars {
|
|
626 |
// Use nonce for verification
|
627 |
wp_nonce_field(basename(__FILE__),'_ca-sidebar-nonce');
|
628 |
?>
|
629 |
-
<div style="
|
630 |
-
<
|
631 |
-
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KPZHE6A72LEN4&lc=US&item_name=WordPress%20Plugin%3a%20Content%20Aware%20Sidebars¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"
|
632 |
target="_blank" title="PayPal - The safer, easier way to pay online!">
|
633 |
-
<img
|
634 |
-
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
635 |
</div>
|
636 |
<?php
|
637 |
}
|
@@ -652,7 +701,7 @@ class ContentAwareSidebars {
|
|
652 |
<div id="taxonomy-<?php echo $taxonomy->name; ?>" class="categorydiv">
|
653 |
<ul id="<?php echo $taxonomy->name; ?>-tabs" class="category-tabs">
|
654 |
<li class="hide-if-no-js"><a href="#<?php echo $taxonomy->name; ?>-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
|
655 |
-
<li class="tabs"><a href="#<?php echo $taxonomy->name; ?>-all" tabindex="3"><?php _e('View All')
|
656 |
</ul>
|
657 |
|
658 |
<div id="<?php echo $taxonomy->name; ?>-pop" class="tabs-panel" style="display: none;height:inherit;max-height:200px;">
|
@@ -662,10 +711,7 @@ class ContentAwareSidebars {
|
|
662 |
</div>
|
663 |
|
664 |
<div id="<?php echo $taxonomy->name; ?>-all" class="tabs-panel" style="height:inherit;max-height:200px;">
|
665 |
-
<?php
|
666 |
-
$name = ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . $taxonomy->name . ']';
|
667 |
-
echo "<input type='hidden' name='{$name}' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
|
668 |
-
?>
|
669 |
<ul id="<?php echo $taxonomy->name; ?>checklist" class="list:<?php echo $taxonomy->name?> categorychecklist form-no-clear">
|
670 |
<?php cas_terms_checklist($post->ID, array('taxonomy' => $taxonomy,'popular_terms' => $popular_ids, 'terms' => $terms)) ?>
|
671 |
</ul>
|
@@ -691,10 +737,11 @@ class ContentAwareSidebars {
|
|
691 |
$exclude[] = get_option('page_for_posts');
|
692 |
}
|
693 |
|
|
|
694 |
$posts = get_posts(array(
|
695 |
'numberposts' => -1,
|
696 |
'post_type' => $post_type->name,
|
697 |
-
'post_status' =>
|
698 |
'exclude' => $exclude
|
699 |
));
|
700 |
|
@@ -705,7 +752,7 @@ class ContentAwareSidebars {
|
|
705 |
?>
|
706 |
<div id="posttype-<?php echo $post_type->name; ?>" class="categorydiv">
|
707 |
<ul id="posttype-<?php echo $post_type->name; ?>-tabs" class="category-tabs">
|
708 |
-
<li class="tabs"><a href="#<?php echo $post_type->name; ?>-all" tabindex="3"><?php _e('View All')
|
709 |
</ul>
|
710 |
<div id="<?php echo $post_type->name; ?>-all" class="tabs-panel" style="height:inherit;max-height:200px;">
|
711 |
<ul id="<?php echo $post_type->name; ?>checklist" class="list:<?php echo $post_type->name?> categorychecklist form-no-clear">
|
@@ -716,29 +763,63 @@ class ContentAwareSidebars {
|
|
716 |
<?php
|
717 |
}
|
718 |
|
|
|
719 |
echo '<p style="padding:6px 0 4px;">'."\n";
|
720 |
-
echo '<label><input type="checkbox" name="post_types[]" value="'.$post_type->name.'"'.(in_array($post_type->name,$current) ? ' checked="checked"' : '').' /> '.sprintf(__('Show with %s'),$post_type->
|
721 |
echo '</p>'."\n";
|
722 |
|
723 |
}
|
724 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
725 |
/**
|
726 |
*
|
727 |
* Hide some meta boxes from start
|
728 |
*
|
729 |
*/
|
730 |
function change_default_hidden( $hidden, $screen ) {
|
731 |
-
|
732 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
733 |
|
734 |
-
|
735 |
-
|
736 |
|
737 |
-
|
738 |
-
|
739 |
|
740 |
-
|
741 |
-
|
742 |
}
|
743 |
|
744 |
/**
|
@@ -753,11 +834,13 @@ class ContentAwareSidebars {
|
|
753 |
<table class="form-table">
|
754 |
<?php
|
755 |
if(!empty($array)) {
|
756 |
-
$array = array_intersect_key($this->
|
757 |
} else {
|
758 |
-
$array = $this->
|
759 |
unset($array['taxonomies']);
|
760 |
unset($array['post_types']);
|
|
|
|
|
761 |
}
|
762 |
|
763 |
foreach($array as $setting) :
|
@@ -835,7 +918,7 @@ class ContentAwareSidebars {
|
|
835 |
$this->init_metadata();
|
836 |
|
837 |
// Update metadata
|
838 |
-
foreach ($this->
|
839 |
$old = get_post_meta($post_id, $field['id'], true);
|
840 |
$new = isset($_POST[$field['id']]) ? $_POST[$field['id']] : '';
|
841 |
|
@@ -868,6 +951,24 @@ class ContentAwareSidebars {
|
|
868 |
|
869 |
}
|
870 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
871 |
}
|
872 |
|
873 |
// Launch plugin
|
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.7
|
10 |
Author: Joachim Jensen
|
11 |
Author URI: http://www.intox.dk/
|
12 |
Text Domain: content-aware-sidebars
|
31 |
*/
|
32 |
class ContentAwareSidebars {
|
33 |
|
34 |
+
protected $metadata = array();
|
35 |
protected $post_types = array();
|
36 |
protected $post_type_objects = array();
|
37 |
protected $taxonomies = array();
|
38 |
protected $taxonomy_objects = array();
|
39 |
protected $sidebar_cache = array();
|
40 |
+
|
41 |
/**
|
42 |
*
|
43 |
* Constructor
|
51 |
add_filter('request', array(&$this,'admin_column_orderby'));
|
52 |
add_filter('default_hidden_meta_boxes', array(&$this,'change_default_hidden'),10,2);
|
53 |
add_filter('manage_edit-sidebar_columns', array(&$this,'admin_column_headers'));
|
54 |
+
add_filter('manage_edit-sidebar_sortable_columns', array(&$this,'admin_column_sortable_headers'));
|
55 |
add_filter('manage_posts_custom_column', array(&$this,'admin_column_rows'),10,3);
|
56 |
add_filter('post_row_actions', array(&$this,'sidebar_row_actions'),10,2);
|
57 |
add_filter('post_updated_messages', array(&$this,'sidebar_updated_messages'));
|
58 |
|
59 |
add_action('init', array(&$this,'init_sidebar_type'),50);
|
60 |
add_action('widgets_init', array(&$this,'create_sidebars'));
|
61 |
+
add_action('add_meta_boxes_sidebar', array(&$this,'create_meta_boxes'));
|
62 |
+
add_action('admin_init', array(&$this,'prepare_admin_scripts'));
|
63 |
add_action('admin_menu', array(&$this,'clear_admin_menu'));
|
64 |
add_action('save_post', array(&$this,'save_post'));
|
65 |
+
add_action('admin_print_scripts-post-new.php', array(&$this,'load_admin_scripts'));
|
66 |
+
add_action('admin_print_scripts-post.php', array(&$this,'load_admin_scripts'));
|
67 |
|
68 |
register_activation_hook(__FILE__, array(&$this,'upon_activation'));
|
69 |
|
70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
/**
|
73 |
*
|
74 |
* Create post meta fields
|
|
|
75 |
*
|
76 |
*/
|
77 |
+
private function init_metadata() {
|
78 |
+
global $post, $wp_registered_sidebars, $wpdb;
|
79 |
|
80 |
// List of sidebars
|
81 |
$sidebar_list = array();
|
84 |
$sidebar_list[$sidebar['id']] = $sidebar['name'];
|
85 |
}
|
86 |
|
87 |
+
// List of authors
|
88 |
+
$author_list = array();
|
89 |
+
foreach($wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID ASC") as $user) {
|
90 |
+
$author_list[$user->ID] = $user->display_name;
|
91 |
+
}
|
92 |
+
|
93 |
// Meta fields
|
94 |
+
$this->metadata = array(
|
95 |
'post_types' => array(
|
96 |
'name' => __('Post Types', 'content-aware-sidebars'),
|
97 |
'id' => 'post_types',
|
108 |
'type' => 'checkbox',
|
109 |
'list' => $this->taxonomies
|
110 |
),
|
111 |
+
'authors' => array(
|
112 |
+
'name' => __('Authors', 'content-aware-sidebars'),
|
113 |
+
'id' => 'authors',
|
114 |
+
'desc' => '',
|
115 |
+
'val' => array(),
|
116 |
+
'type' => 'checkbox',
|
117 |
+
'list' => $author_list
|
118 |
+
),
|
119 |
+
'page_templates'=> array(
|
120 |
+
'name' => __('Page Templates', 'content-aware-sidebars'),
|
121 |
+
'id' => 'page_templates',
|
122 |
+
'desc' => '',
|
123 |
+
'val' => array(),
|
124 |
+
'type' => 'checkbox',
|
125 |
+
'list' => array_flip(get_page_templates())
|
126 |
+
),
|
127 |
'static' => array(
|
128 |
'name' => __('Static Pages', 'content-aware-sidebars'),
|
129 |
'id' => 'static',
|
191 |
|
192 |
load_plugin_textdomain('content-aware-sidebars', false, dirname( plugin_basename(__FILE__)).'/lang/');
|
193 |
|
194 |
+
// List public post types
|
195 |
+
foreach(get_post_types(array('public'=>true),'objects') as $post_type) {
|
196 |
+
$this->post_types[$post_type->name] = $post_type->label;
|
197 |
+
$this->post_type_objects[$post_type->name] = $post_type;
|
198 |
+
}
|
199 |
+
|
200 |
+
// List public taxonomies
|
201 |
+
foreach(get_taxonomies(array('public'=>true),'objects') as $tax) {
|
202 |
+
$this->taxonomies[$tax->name] = $tax->label;
|
203 |
+
$this->taxonomy_objects[$tax->name] = $tax;
|
204 |
+
}
|
205 |
|
206 |
+
// Register the sidebar type
|
207 |
register_post_type('sidebar',array(
|
208 |
'labels' => array(
|
209 |
'name' => __('Sidebars', 'content-aware-sidebars'),
|
272 |
*
|
273 |
*/
|
274 |
public function create_sidebars() {
|
275 |
+
//WP3.1 does not support (array) as post_status
|
276 |
$posts = get_posts(array(
|
277 |
'numberposts' => -1,
|
278 |
'post_type' => 'sidebar',
|
279 |
+
'post_status' => 'publish,private,future'
|
280 |
));
|
281 |
foreach($posts as $post)
|
282 |
register_sidebar( array(
|
292 |
|
293 |
/**
|
294 |
*
|
295 |
+
* Add admin column headers
|
296 |
*
|
297 |
*/
|
298 |
public function admin_column_headers($columns) {
|
307 |
$columns
|
308 |
);
|
309 |
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
*
|
313 |
+
* Make some headers sortable
|
314 |
+
*
|
315 |
+
*/
|
316 |
+
public function admin_column_sortable_headers($columns) {
|
317 |
+
return array_merge(
|
318 |
+
array(
|
319 |
+
'exposure' => 'exposure',
|
320 |
+
'handle' => 'handle',
|
321 |
+
'merge-pos' => 'merge-pos'
|
322 |
+
),
|
323 |
+
$columns
|
324 |
+
);
|
325 |
+
}
|
326 |
|
327 |
/**
|
328 |
*
|
346 |
*/
|
347 |
public function admin_column_rows($column_name,$post_id) {
|
348 |
|
349 |
+
// Load metadata
|
350 |
+
if(!$this->metadata) $this->init_metadata();
|
351 |
|
352 |
$current = get_post_meta($post_id,$column_name,true);
|
353 |
+
$current_from_list = $this->metadata[$column_name]['list'][$current];
|
354 |
+
|
355 |
+
if($column_name == 'handle' && $current < 2) {
|
356 |
+
$host = $this->metadata['host']['list'][get_post_meta($post_id,'host',true)];
|
357 |
+
$current_from_list .= ": ".$host;
|
358 |
+
}
|
359 |
+
echo $current_from_list;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
}
|
361 |
|
362 |
/**
|
379 |
|
380 |
/**
|
381 |
*
|
382 |
+
* Replace or merge a sidebar with content aware sidebars
|
383 |
+
* Handles content aware sidebars with hosts
|
384 |
*
|
385 |
*/
|
386 |
public function replace_sidebar() {
|
394 |
|
395 |
$id = 'ca-sidebar-'.$post->ID;
|
396 |
|
397 |
+
// Check for correct handling
|
398 |
+
if ($post->handle == 2)
|
399 |
continue;
|
400 |
|
401 |
+
// Sidebar might not have any widgets. Get it anyway!
|
402 |
+
if(!isset($_wp_sidebars_widgets[$id]))
|
403 |
+
$_wp_sidebars_widgets[$id] = array();
|
404 |
+
|
405 |
// If host has already been replaced, merge with it instead. Might change in future.
|
406 |
if($post->handle || isset($handled_already[$post->host])) {
|
407 |
if($post->merge_pos)
|
422 |
*
|
423 |
*/
|
424 |
public function get_sidebars() {
|
425 |
+
global $wpdb, $post_type, $post;
|
426 |
|
427 |
// Return cache if present
|
428 |
if(!empty($this->sidebar_cache)) {
|
432 |
return $this->sidebar_cache;
|
433 |
}
|
434 |
|
|
|
|
|
435 |
$joins = "";
|
436 |
$where = "";
|
437 |
|
440 |
|
441 |
$joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
|
442 |
|
443 |
+
$where .= "(static.meta_value LIKE '%front-page%') AND ";
|
444 |
+
$where .= "exposure.meta_value <= '1' AND ";
|
|
|
|
|
445 |
|
446 |
// Single content
|
447 |
} elseif(is_singular()) {
|
448 |
|
449 |
+
// Post Type
|
450 |
$joins .= "LEFT JOIN $wpdb->postmeta post_types ON post_types.post_id = posts.ID AND post_types.meta_key = 'post_types' ";
|
451 |
+
$where .= "(post_types.meta_value LIKE '%".serialize(get_post_type())."%' OR post_types.meta_value LIKE '%".serialize((string)get_the_ID())."%'";
|
452 |
+
|
453 |
+
//Author
|
454 |
+
$joins .= "LEFT JOIN $wpdb->postmeta authors ON authors.post_id = posts.ID AND authors.meta_key = 'authors' ";
|
455 |
+
$where .= "OR (authors.meta_value LIKE '%authors%' OR authors.meta_value LIKE '%".serialize((string)$post->post_author)."%')";
|
456 |
|
457 |
+
//Page Template
|
458 |
+
$template = get_post_meta(get_the_ID(),'_wp_page_template',true);
|
459 |
+
if($template && $template != 'default') {
|
460 |
+
$joins .= "LEFT JOIN $wpdb->postmeta page_templates ON page_templates.post_id = posts.ID AND page_templates.meta_key = 'page_templates' ";
|
461 |
+
$where .= "OR (page_templates.meta_value LIKE '%page_templates%' OR page_templates.meta_value LIKE '%".$template."%')";
|
462 |
+
}
|
463 |
|
464 |
// Check if content has any taxonomies supported
|
465 |
+
$post_taxonomies = get_object_taxonomies(get_post_type());
|
466 |
if($post_taxonomies) {
|
467 |
$post_terms = wp_get_object_terms(get_the_ID(),$post_taxonomies);
|
468 |
// Check if content has any actual taxonomy terms
|
490 |
$where .= ") AND ";
|
491 |
$where .= "exposure.meta_value <= '1' AND ";
|
492 |
|
|
|
|
|
493 |
// Taxonomy archives
|
494 |
} elseif(is_tax() || is_category() || is_tag()) {
|
495 |
|
501 |
$joins .= "LEFT JOIN $wpdb->postmeta post_tax ON post_tax.post_id = posts.ID AND post_tax.meta_key = 'taxonomies'";
|
502 |
|
503 |
$where .= "(terms.slug = '$term->slug'";
|
504 |
+
$where .= " OR post_tax.meta_value LIKE '%".serialize($term->taxonomy)."%'";
|
505 |
$where .= ") AND ";
|
506 |
+
$where .= "exposure.meta_value >= '1' AND ";
|
|
|
|
|
507 |
|
508 |
// Post Type archives
|
509 |
} elseif(is_post_type_archive() || is_home()) {
|
512 |
if(!$post_type) $post_type = 'post';
|
513 |
|
514 |
$joins .= "LEFT JOIN $wpdb->postmeta post_types ON post_types.post_id = posts.ID AND post_types.meta_key = 'post_types' ";
|
515 |
+
$where .= "(post_types.meta_value LIKE '%".serialize($post_type)."%') AND ";
|
516 |
+
$where .= "exposure.meta_value >= '1' AND ";
|
517 |
+
|
518 |
+
// Search
|
519 |
+
} elseif(is_author()) {
|
520 |
+
|
521 |
+
$joins .= "LEFT JOIN $wpdb->postmeta authors ON authors.post_id = posts.ID AND authors.meta_key = 'authors' ";
|
522 |
+
$where .= "(authors.meta_value LIKE '%authors%' OR authors.meta_value LIKE '%".serialize((string)get_query_var('author'))."%') AND ";
|
523 |
+
$where .= "exposure.meta_value >= '1' AND ";
|
524 |
|
525 |
// Search
|
526 |
} elseif(is_search()) {
|
527 |
|
528 |
+
$joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
|
529 |
+
$where .= "(static.meta_value LIKE '%search%') AND ";
|
530 |
+
$where .= "exposure.meta_value <= '1' AND ";
|
|
|
|
|
|
|
531 |
|
532 |
// 404
|
533 |
} elseif(is_404()) {
|
534 |
|
535 |
+
$joins .= "LEFT JOIN $wpdb->postmeta static ON static.post_id = posts.ID AND static.meta_key = 'static' ";
|
536 |
+
$where .= "(static.meta_value LIKE '%404%') AND ";
|
|
|
537 |
$where .= "exposure.meta_value <= '1' AND ";
|
538 |
|
|
|
539 |
}
|
540 |
|
541 |
+
// Check if there are any rules for this type of content
|
542 |
+
if(!$where)
|
543 |
return false;
|
|
|
544 |
|
545 |
// Show private sidebars or not
|
546 |
if(current_user_can('read_private_posts'))
|
588 |
*
|
589 |
*/
|
590 |
public function create_meta_boxes() {
|
591 |
+
|
592 |
+
// Load metadata
|
593 |
+
$this->init_metadata();
|
594 |
+
|
595 |
+
// Add boxes
|
596 |
// Author Words
|
597 |
add_meta_box(
|
598 |
'ca-sidebar-author-words',
|
626 |
$tax
|
627 |
);
|
628 |
}
|
629 |
+
|
630 |
+
// Author and Page Template lists
|
631 |
+
$checkbox_meta_boxes = array('authors','page_templates');
|
632 |
+
foreach($checkbox_meta_boxes as $meta_box) {
|
633 |
+
add_meta_box(
|
634 |
+
'ca-sidebar-'.$meta_box,
|
635 |
+
$this->metadata[$meta_box]['name'],
|
636 |
+
array(&$this,'meta_box_checkboxes'),
|
637 |
+
'sidebar',
|
638 |
+
'side',
|
639 |
+
'default',
|
640 |
+
$meta_box
|
641 |
+
);
|
642 |
+
}
|
643 |
+
|
644 |
// Options
|
645 |
add_meta_box(
|
646 |
'ca-sidebar',
|
670 |
// Use nonce for verification
|
671 |
wp_nonce_field(basename(__FILE__),'_ca-sidebar-nonce');
|
672 |
?>
|
673 |
+
<div style="overflow:hidden;">
|
674 |
+
<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KPZHE6A72LEN4&lc=US&item_name=WordPress%20Plugin%3a%20Content%20Aware%20Sidebars¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"
|
|
|
675 |
target="_blank" title="PayPal - The safer, easier way to pay online!">
|
676 |
+
<img align="right" 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!">
|
677 |
+
</a></p>
|
678 |
+
<p><?php _e('If you love this plugin, please consider donating.', 'content-aware-sidebars'); ?></p>
|
679 |
+
<br />
|
680 |
+
<p><?php printf(__('Remember to <a class="button" href="%1$s" target="_blank">rate</a> and <a class="button" href="%2$s" target="_blank">share</a> it too!', 'content-aware-sidebars'),
|
681 |
+
'http://wordpress.org/extend/plugins/content-aware-sidebars/',
|
682 |
+
'http://twitter.com/?status='.__('Check out Content Aware Sidebars for %23WordPress! :)','content-aware-sidebars').' http://tiny.cc/ca-sidebars'
|
683 |
+
); ?></p>
|
684 |
</div>
|
685 |
<?php
|
686 |
}
|
701 |
<div id="taxonomy-<?php echo $taxonomy->name; ?>" class="categorydiv">
|
702 |
<ul id="<?php echo $taxonomy->name; ?>-tabs" class="category-tabs">
|
703 |
<li class="hide-if-no-js"><a href="#<?php echo $taxonomy->name; ?>-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
|
704 |
+
<li class="tabs"><a href="#<?php echo $taxonomy->name; ?>-all" tabindex="3"><?php _e('View All'); ?></a></li>
|
705 |
</ul>
|
706 |
|
707 |
<div id="<?php echo $taxonomy->name; ?>-pop" class="tabs-panel" style="display: none;height:inherit;max-height:200px;">
|
711 |
</div>
|
712 |
|
713 |
<div id="<?php echo $taxonomy->name; ?>-all" class="tabs-panel" style="height:inherit;max-height:200px;">
|
714 |
+
<input type="hidden" name="<?php echo ($taxonomy->name == "category" ? "post_category[]" : "tax_input['.$taxonomy->name.']"); ?>" value="0" />
|
|
|
|
|
|
|
715 |
<ul id="<?php echo $taxonomy->name; ?>checklist" class="list:<?php echo $taxonomy->name?> categorychecklist form-no-clear">
|
716 |
<?php cas_terms_checklist($post->ID, array('taxonomy' => $taxonomy,'popular_terms' => $popular_ids, 'terms' => $terms)) ?>
|
717 |
</ul>
|
737 |
$exclude[] = get_option('page_for_posts');
|
738 |
}
|
739 |
|
740 |
+
//WP3.1 does not support (array) as post_status
|
741 |
$posts = get_posts(array(
|
742 |
'numberposts' => -1,
|
743 |
'post_type' => $post_type->name,
|
744 |
+
'post_status' => 'publish,private,future',
|
745 |
'exclude' => $exclude
|
746 |
));
|
747 |
|
752 |
?>
|
753 |
<div id="posttype-<?php echo $post_type->name; ?>" class="categorydiv">
|
754 |
<ul id="posttype-<?php echo $post_type->name; ?>-tabs" class="category-tabs">
|
755 |
+
<li class="tabs"><a href="#<?php echo $post_type->name; ?>-all" tabindex="3"><?php _e('View All'); ?></a></li>
|
756 |
</ul>
|
757 |
<div id="<?php echo $post_type->name; ?>-all" class="tabs-panel" style="height:inherit;max-height:200px;">
|
758 |
<ul id="<?php echo $post_type->name; ?>checklist" class="list:<?php echo $post_type->name?> categorychecklist form-no-clear">
|
763 |
<?php
|
764 |
}
|
765 |
|
766 |
+
//WP3.1.4 does not support $post_type->labels->all_items
|
767 |
echo '<p style="padding:6px 0 4px;">'."\n";
|
768 |
+
echo '<label><input type="checkbox" name="post_types[]" value="'.$post_type->name.'"'.(in_array($post_type->name,$current) ? ' checked="checked"' : '').' /> '.sprintf(__('Show with All %s'),$post_type->label).'</label>'."\n";
|
769 |
echo '</p>'."\n";
|
770 |
|
771 |
}
|
772 |
|
773 |
+
public function meta_box_checkboxes($post, $box) {
|
774 |
+
$field = $box['args'];
|
775 |
+
$meta = get_post_meta($post->ID, $field, true);
|
776 |
+
$current = $meta != '' ? $meta : array();
|
777 |
+
?>
|
778 |
+
<div id="list-<?php echo $field; ?>" class="categorydiv">
|
779 |
+
<ul id="<?php echo $field; ?>-tabs" class="category-tabs">
|
780 |
+
<li class="tabs"><a href="#<?php echo $field; ?>-all" tabindex="3"><?php _e('View All'); ?></a></li>
|
781 |
+
</ul>
|
782 |
+
<div id="<?php echo $field; ?>-all" class="tabs-panel" style="height:inherit;max-height:200px;">
|
783 |
+
<ul id="authorlistchecklist" class="list:<?php echo $field; ?> categorychecklist form-no-clear">
|
784 |
+
<?php
|
785 |
+
foreach($this->metadata[$field]['list'] as $id => $name) {
|
786 |
+
echo '<li><label><input type="checkbox" name="'.$field.'[]" value="'.$id.'"'.(in_array($id,$current) ? ' checked="checked"' : '').' /> '.$name.'</label></li>'."\n";
|
787 |
+
}
|
788 |
+
?>
|
789 |
+
</ul>
|
790 |
+
</div>
|
791 |
+
</div>
|
792 |
+
<p style="padding:6px 0 4px;">
|
793 |
+
<label><input type="checkbox" name="<?php echo $field; ?>[]" value="<?php echo $field; ?>"<?php echo (in_array($field,$current) ? ' checked="checked"' : ''); ?> /> <?php _e('Show with All '.$this->metadata[$field]['name']); ?></label>
|
794 |
+
</p>
|
795 |
+
<?php
|
796 |
+
}
|
797 |
+
|
798 |
/**
|
799 |
*
|
800 |
* Hide some meta boxes from start
|
801 |
*
|
802 |
*/
|
803 |
function change_default_hidden( $hidden, $screen ) {
|
804 |
+
global $wp_version;
|
805 |
+
|
806 |
+
//WordPress 3.3 has changed get_hidden_meta_boxes().
|
807 |
+
if($wp_version < 3.3) {
|
808 |
+
$condition = $screen->base == 'sidebar';
|
809 |
+
} else {
|
810 |
+
$condition = $screen->post_type == 'sidebar';
|
811 |
+
}
|
812 |
+
|
813 |
+
if ($condition && get_user_option( 'metaboxhidden_sidebar' ) === false) {
|
814 |
|
815 |
+
$hidden_meta_boxes = array('postexcerpt','pageparentdiv','ca-sidebar-tax-post_format','ca-sidebar-post-type-attachment','ca-sidebar-authors');
|
816 |
+
$hidden = array_merge($hidden,$hidden_meta_boxes);
|
817 |
|
818 |
+
$user = wp_get_current_user();
|
819 |
+
update_user_option( $user->ID, 'metaboxhidden_sidebar', $hidden, true );
|
820 |
|
821 |
+
}
|
822 |
+
return $hidden;
|
823 |
}
|
824 |
|
825 |
/**
|
834 |
<table class="form-table">
|
835 |
<?php
|
836 |
if(!empty($array)) {
|
837 |
+
$array = array_intersect_key($this->metadata,array_keys($array));
|
838 |
} else {
|
839 |
+
$array = $this->metadata;
|
840 |
unset($array['taxonomies']);
|
841 |
unset($array['post_types']);
|
842 |
+
unset($array['authors']);
|
843 |
+
unset($array['page_templates']);
|
844 |
}
|
845 |
|
846 |
foreach($array as $setting) :
|
918 |
$this->init_metadata();
|
919 |
|
920 |
// Update metadata
|
921 |
+
foreach ($this->metadata as $field) {
|
922 |
$old = get_post_meta($post_id, $field['id'], true);
|
923 |
$new = isset($_POST[$field['id']]) ? $_POST[$field['id']] : '';
|
924 |
|
951 |
|
952 |
}
|
953 |
|
954 |
+
/**
|
955 |
+
*
|
956 |
+
* Load scripts for administration
|
957 |
+
*
|
958 |
+
*/
|
959 |
+
public function load_admin_scripts() {
|
960 |
+
wp_enqueue_script('cas_admin');
|
961 |
+
}
|
962 |
+
|
963 |
+
/**
|
964 |
+
*
|
965 |
+
* Prepare scripts for administration
|
966 |
+
*
|
967 |
+
*/
|
968 |
+
public function prepare_admin_scripts() {
|
969 |
+
wp_register_script('cas_admin', WP_PLUGIN_URL.'/'.plugin_basename(dirname(__FILE__)).'/js/cas_admin.js', array('jquery'), '0.1');
|
970 |
+
}
|
971 |
+
|
972 |
}
|
973 |
|
974 |
// Launch plugin
|
js/cas_admin.js
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* @package Content Aware Sidebars
|
3 |
+
*/
|
4 |
+
jQuery(document).ready(function($) {
|
5 |
+
|
6 |
+
handleAllCheckbox("post_types","posttype");
|
7 |
+
handleAllCheckbox("taxonomies","taxonomy");
|
8 |
+
handleAllCheckbox("authors","list");
|
9 |
+
handleAllCheckbox("page_templates","list");
|
10 |
+
|
11 |
+
handleSidebarHandle();
|
12 |
+
|
13 |
+
/**
|
14 |
+
*
|
15 |
+
* Handle "Show with All" checkbox
|
16 |
+
*
|
17 |
+
*/
|
18 |
+
function handleAllCheckbox(name,type) {
|
19 |
+
|
20 |
+
var checkbox = "input[name='"+name+"[]']";
|
21 |
+
|
22 |
+
// Execute on ready for each checkbox
|
23 |
+
$(checkbox).each(function() {
|
24 |
+
disenableSingleCheckboxes($(this),type);
|
25 |
+
});
|
26 |
+
|
27 |
+
// Execute on change
|
28 |
+
$(checkbox).change(function(){
|
29 |
+
disenableSingleCheckboxes($(this),type);
|
30 |
+
});
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
*
|
35 |
+
* The state of a "Show with All" checkbox will control the accessibility of the respective checkboxes for specific entities
|
36 |
+
* If state is checked, they will be disabled
|
37 |
+
*
|
38 |
+
*/
|
39 |
+
function disenableSingleCheckboxes(checkbox,type) {
|
40 |
+
var checkboxes = "#"+type+"-"+checkbox.val()+" :input";
|
41 |
+
|
42 |
+
if(checkbox.is(":checked")) {
|
43 |
+
$(checkboxes).attr("disabled", true);
|
44 |
+
} else {
|
45 |
+
$(checkboxes).removeAttr("disabled");
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
*
|
51 |
+
* Handle the Handle selection
|
52 |
+
*
|
53 |
+
*/
|
54 |
+
function handleSidebarHandle() {
|
55 |
+
|
56 |
+
var name = "select[name='handle']";
|
57 |
+
|
58 |
+
// Execute on ready
|
59 |
+
$(name).each(function(){
|
60 |
+
endisableHostSidebars($(this));
|
61 |
+
});
|
62 |
+
|
63 |
+
// Execute on change
|
64 |
+
$(name).change(function(){
|
65 |
+
endisableHostSidebars($(this));
|
66 |
+
});
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
*
|
71 |
+
* The value of Handle selection will control the accessibility of the host sidebar selection
|
72 |
+
* If Handling is manual, selection of host sidebar will be disabled
|
73 |
+
*
|
74 |
+
*/
|
75 |
+
function endisableHostSidebars(select) {
|
76 |
+
var name = "select[name='host']";
|
77 |
+
if(select.val() == 2)
|
78 |
+
$(name).attr("disabled", true);
|
79 |
+
else
|
80 |
+
$(name).removeAttr("disabled");
|
81 |
+
}
|
82 |
+
|
83 |
+
});
|
readme.txt
CHANGED
@@ -1,28 +1,30 @@
|
|
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¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
-
Tags: sidebar, widget, content aware, post type, taxonomy, term, archive, singular
|
5 |
Requires at least: 3.1
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 0.
|
8 |
|
9 |
Manage and show sidebars according to the content being viewed.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
-
Manage an infinite number of sidebars.
|
14 |
No extra database tables or table columns will be added.
|
15 |
|
16 |
= Features =
|
17 |
|
18 |
* Show sidebars with:
|
19 |
-
* Specific singulars
|
20 |
-
* Specific post types
|
|
|
21 |
* Singulars containing specific taxonomies or taxonomy terms
|
22 |
-
*
|
|
|
23 |
* Search results, 404 page and front page
|
24 |
* Any combination of the above
|
25 |
-
* Merge new sidebars with others, replace them or simply add them to your theme manually
|
26 |
* Create complex content with nested sidebars
|
27 |
* Private sidebars only for members
|
28 |
* Schedule sidebars for later publishing
|
@@ -44,20 +46,46 @@ www.intox.dk
|
|
44 |
|
45 |
== Frequently Asked Questions ==
|
46 |
|
47 |
-
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
== Screenshots ==
|
52 |
|
53 |
-
1. Add a new
|
54 |
-
2. Simple overview of
|
55 |
-
3. Add widgets to
|
56 |
-
4. Viewing
|
57 |
-
5. Viewing
|
58 |
|
59 |
== Changelog ==
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
= 0.6.3 =
|
62 |
|
63 |
* Added: scheduled and private singulars are selectable in sidebar editor
|
@@ -127,3 +155,4 @@ You are.
|
|
127 |
= 0.1 =
|
128 |
|
129 |
* Hello World
|
|
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¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
+
Tags: sidebar, widget, content aware, post type, taxonomy, term, archive, singular, seo
|
5 |
Requires at least: 3.1
|
6 |
+
Tested up to: 3.3
|
7 |
+
Stable tag: 0.7
|
8 |
|
9 |
Manage and show sidebars according to the content being viewed.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
+
Manage an infinite number of sidebars. Make your WordPress site even more dynamic and boost SEO by controlling what content the sidebars should be displayed with. Creating flexible, dynamic sidebars has never been easier, and no code is needed at all as everything is easily done in the administration.
|
14 |
No extra database tables or table columns will be added.
|
15 |
|
16 |
= Features =
|
17 |
|
18 |
* Show sidebars with:
|
19 |
+
* Specific singulars - e.g. specific posts or pages
|
20 |
+
* Specific (custom) post types
|
21 |
+
* Specific page templates
|
22 |
* Singulars containing specific taxonomies or taxonomy terms
|
23 |
+
* Singulars made by specific authors
|
24 |
+
* Specific post type archives, author archives, taxonomy archives or taxonomy term archives
|
25 |
* Search results, 404 page and front page
|
26 |
* Any combination of the above
|
27 |
+
* Merge new sidebars with others, replace them or simply add them to your theme manually with a template tag
|
28 |
* Create complex content with nested sidebars
|
29 |
* Private sidebars only for members
|
30 |
* Schedule sidebars for later publishing
|
46 |
|
47 |
== Frequently Asked Questions ==
|
48 |
|
49 |
+
If you have any questions not answered here, feel free to contact jv[at]intox.dk.
|
50 |
|
51 |
+
= How do I use `display_ca_sidebar()`? =
|
52 |
+
|
53 |
+
This function handles all sidebars that are set to be handled manually. It can be inserted anywhere on your site in any quantity, either as it is, or with the following parameters:
|
54 |
+
|
55 |
+
`include` (array|string)
|
56 |
+
Insert IDs of sidebars. By using this, the function will only handle the sidebars whose IDs are included. Default is `null`.
|
57 |
+
|
58 |
+
`before` (string)
|
59 |
+
Change the html to be displayed before the sidebar. Default is `<div id="sidebar" class="widget-area"><ul class="xoxo">`.
|
60 |
+
|
61 |
+
`after` (string)
|
62 |
+
Change the html to be displayed after the sidebar. Default is `</ul></div>`.
|
63 |
+
|
64 |
+
The function accepts URL-style strings as parameters too, like the standard WordPress Template Tags.
|
65 |
|
66 |
== Screenshots ==
|
67 |
|
68 |
+
1. Add a new Content Aware Sidebar to be displayed with All Posts and Another Page. It replaces `Main Sidebar`
|
69 |
+
2. Simple overview of all created Content Aware Sidebars
|
70 |
+
3. Add widgets to the newly added sidebar
|
71 |
+
4. Viewing front page of site. `Main Sidebar` is displayed
|
72 |
+
5. Viewing Another Page. The Content Aware Sidebar has replaced `Main Sidebar`
|
73 |
|
74 |
== Changelog ==
|
75 |
|
76 |
+
= 0.7 =
|
77 |
+
|
78 |
+
* Added: sidebars will be displayed even if empty (i.e. hidden)
|
79 |
+
* Added: author rules on singulars and archives
|
80 |
+
* Added: page template rules
|
81 |
+
* Added: javascript handling for disabling/enabling specific input on editor page
|
82 |
+
* Fixed: minor tweak for full compatibility with wp3.3
|
83 |
+
* Fixed: function for meta boxes is called only on editor page
|
84 |
+
* Fixed: proper column sorting in administration
|
85 |
+
* Fixed: specific post type label not supported in WP3.1.x
|
86 |
+
* Fixed: type (array) not supported as post_status in get_posts() in WP3.1.x
|
87 |
+
* Fixed: code cleanup
|
88 |
+
|
89 |
= 0.6.3 =
|
90 |
|
91 |
* Added: scheduled and private singulars are selectable in sidebar editor
|
155 |
= 0.1 =
|
156 |
|
157 |
* Hello World
|
158 |
+
|
screenshot-1.png
CHANGED
Binary file
|
screenshot-2.png
CHANGED
Binary file
|
screenshot-3.png
CHANGED
Binary file
|
screenshot-4.png
CHANGED
Binary file
|
screenshot-5.png
CHANGED
Binary file
|
walker.php
CHANGED
@@ -1,81 +1,65 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
*/
|
6 |
|
7 |
/**
|
8 |
*
|
9 |
-
*
|
10 |
*
|
11 |
*/
|
12 |
-
class
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
$
|
18 |
-
$output .= "$indent<ul class='children'>\n";
|
19 |
-
}
|
20 |
-
|
21 |
-
public function end_lvl(&$output, $depth, $args) {
|
22 |
-
$indent = str_repeat("\t", $depth);
|
23 |
-
$output .= "$indent</ul>\n";
|
24 |
-
}
|
25 |
-
|
26 |
-
public function start_el(&$output, $term, $depth, $args) {
|
27 |
-
extract($args);
|
28 |
|
29 |
-
if ( empty($taxonomy) ) {
|
30 |
-
$output .= "\n<li>";
|
31 |
-
return;
|
32 |
-
}
|
33 |
-
|
34 |
-
$name = $taxonomy->name == 'category' ? 'post_category' : 'tax_input['.$taxonomy->name.']';
|
35 |
-
$value = $taxonomy->hierarchical ? 'term_id' : 'slug';
|
36 |
-
$class = in_array( $term->term_id, $popular_terms ) ? ' class="popular-category"' : '';
|
37 |
-
|
38 |
-
$output .= "\n".'<li id="'.$taxonomy->name.'-'.$term->term_id.'"$class><label class="selectit"><input value="'.$term->$value.'" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy->name.'-'.$term->term_id.'"'.checked(in_array($term->term_id,$selected_terms),true,false).disabled(empty($disabled),false,false).'/> '.esc_html( apply_filters('the_category', $term->name )) . '</label>';
|
39 |
-
}
|
40 |
-
|
41 |
-
public function end_el(&$output, $term, $depth, $args) {
|
42 |
-
$output .= "</li>\n";
|
43 |
}
|
44 |
-
|
45 |
-
|
46 |
-
/**
|
47 |
-
*
|
48 |
-
* Custom Walker Class
|
49 |
-
*
|
50 |
-
*/
|
51 |
-
class CAS_Walker_Post_Checklist extends Walker {
|
52 |
-
var $tree_type = 'post';
|
53 |
-
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
|
54 |
-
|
55 |
public function start_lvl(&$output, $depth, $args) {
|
56 |
$indent = str_repeat("\t", $depth);
|
57 |
$output .= "$indent<ul class='children'>\n";
|
58 |
}
|
59 |
-
|
60 |
public function end_lvl(&$output, $depth, $args) {
|
61 |
$indent = str_repeat("\t", $depth);
|
62 |
$output .= "$indent</ul>\n";
|
63 |
}
|
64 |
-
|
65 |
public function start_el(&$output, $term, $depth, $args) {
|
66 |
extract($args);
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
|
73 |
-
|
74 |
-
}
|
75 |
|
76 |
public function end_el(&$output, $term, $depth, $args) {
|
77 |
$output .= "</li>\n";
|
78 |
}
|
|
|
79 |
}
|
80 |
|
81 |
/**
|
@@ -86,15 +70,13 @@ class CAS_Walker_Post_Checklist extends Walker {
|
|
86 |
function cas_terms_checklist($post_id = 0, $args = array()) {
|
87 |
$defaults = array(
|
88 |
'popular_terms' => false,
|
89 |
-
'walker' => null,
|
90 |
'taxonomy' => 'category',
|
91 |
'terms' => null,
|
92 |
'checked_ontop' => true
|
93 |
);
|
94 |
extract(wp_parse_args($args, $defaults), EXTR_SKIP);
|
95 |
|
96 |
-
|
97 |
-
$walker = new CAS_Walker_Tax_Checklist();
|
98 |
|
99 |
if(!is_object($taxonomy))
|
100 |
$taxonomy = get_taxonomy($taxonomy);
|
@@ -179,15 +161,13 @@ function cas_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ec
|
|
179 |
*/
|
180 |
function cas_posts_checklist($post_id = 0, $args = array()) {
|
181 |
$defaults = array(
|
182 |
-
'walker' => null,
|
183 |
'post_type' => 'post',
|
184 |
'posts' => null,
|
185 |
'checked_ontop' => true
|
186 |
);
|
187 |
extract(wp_parse_args($args, $defaults), EXTR_SKIP);
|
188 |
|
189 |
-
|
190 |
-
$walker = new CAS_Walker_Post_Checklist();
|
191 |
|
192 |
if(!is_object($post_type))
|
193 |
$post_type = get_post_type_object($post_type);
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* @package Content Aware Sidebars
|
4 |
*/
|
5 |
|
6 |
/**
|
7 |
*
|
8 |
+
* Walker for post types and taxonomies
|
9 |
*
|
10 |
*/
|
11 |
+
class CAS_Walker_Checklist extends Walker {
|
12 |
+
|
13 |
+
function __construct($tree_type, $db_fields) {
|
14 |
+
|
15 |
+
$this->tree_type = $tree_type;
|
16 |
+
$this->db_fields = $db_fields;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
public function start_lvl(&$output, $depth, $args) {
|
21 |
$indent = str_repeat("\t", $depth);
|
22 |
$output .= "$indent<ul class='children'>\n";
|
23 |
}
|
24 |
+
|
25 |
public function end_lvl(&$output, $depth, $args) {
|
26 |
$indent = str_repeat("\t", $depth);
|
27 |
$output .= "$indent</ul>\n";
|
28 |
}
|
29 |
+
|
30 |
public function start_el(&$output, $term, $depth, $args) {
|
31 |
extract($args);
|
32 |
|
33 |
+
if(isset($post_type)) {
|
34 |
+
|
35 |
+
if ( empty($post_type) ) {
|
36 |
+
$output .= "\n<li>";
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
|
40 |
+
$output .= "\n".'<li id="'.$post_type->name.'-'.$term->ID.'"><label class="selectit"><input value="'.$term->ID.'" type="checkbox" name="post_types[]" id="in-'.$post_type->name.'-'.$term->ID.'"'.checked(in_array($term->ID,$selected_cats),true,false).disabled(empty($disabled),false,false).'/> '.esc_html( $term->post_title ).'</label>';
|
41 |
+
|
42 |
+
} else {
|
43 |
+
|
44 |
+
if ( empty($taxonomy) ) {
|
45 |
+
$output .= "\n<li>";
|
46 |
+
return;
|
47 |
+
}
|
48 |
+
|
49 |
+
$name = $taxonomy->name == 'category' ? 'post_category' : 'tax_input['.$taxonomy->name.']';
|
50 |
+
$value = $taxonomy->hierarchical ? 'term_id' : 'slug';
|
51 |
+
$class = in_array( $term->term_id, $popular_terms ) ? ' class="popular-category"' : '';
|
52 |
+
|
53 |
+
$output .= "\n".'<li id="'.$taxonomy->name.'-'.$term->term_id.'"$class><label class="selectit"><input value="'.$term->$value.'" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy->name.'-'.$term->term_id.'"'.checked(in_array($term->term_id,$selected_terms),true,false).disabled(empty($disabled),false,false).'/> '.esc_html( apply_filters('the_category', $term->name )) . '</label>';
|
54 |
+
|
55 |
}
|
56 |
|
57 |
+
}
|
|
|
58 |
|
59 |
public function end_el(&$output, $term, $depth, $args) {
|
60 |
$output .= "</li>\n";
|
61 |
}
|
62 |
+
|
63 |
}
|
64 |
|
65 |
/**
|
70 |
function cas_terms_checklist($post_id = 0, $args = array()) {
|
71 |
$defaults = array(
|
72 |
'popular_terms' => false,
|
|
|
73 |
'taxonomy' => 'category',
|
74 |
'terms' => null,
|
75 |
'checked_ontop' => true
|
76 |
);
|
77 |
extract(wp_parse_args($args, $defaults), EXTR_SKIP);
|
78 |
|
79 |
+
$walker = new CAS_Walker_Checklist('category',array ('parent' => 'parent', 'id' => 'term_id'));
|
|
|
80 |
|
81 |
if(!is_object($taxonomy))
|
82 |
$taxonomy = get_taxonomy($taxonomy);
|
161 |
*/
|
162 |
function cas_posts_checklist($post_id = 0, $args = array()) {
|
163 |
$defaults = array(
|
|
|
164 |
'post_type' => 'post',
|
165 |
'posts' => null,
|
166 |
'checked_ontop' => true
|
167 |
);
|
168 |
extract(wp_parse_args($args, $defaults), EXTR_SKIP);
|
169 |
|
170 |
+
$walker = new CAS_Walker_Checklist('post',array ('parent' => 'post_parent', 'id' => 'ID'));
|
|
|
171 |
|
172 |
if(!is_object($post_type))
|
173 |
$post_type = get_post_type_object($post_type);
|