Changeset 1077464
- Timestamp:
- 01/28/2015 12:47:38 PM (11 years ago)
- File:
-
- 1 edited
-
conditional-logic-solution/trunk/lib/widgets.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
conditional-logic-solution/trunk/lib/widgets.php
r1075601 r1077464 2 2 class cls_widgets extends class_cls { 3 3 var $id = 'cls_widgets'; 4 var $template; 4 5 5 6 public function __construct(){ … … 12 13 add_filter( 'is_active_sidebar', array( $this, 'is_active_sidebar' ), 999, 2 ); 13 14 add_action( 'widget_display_callback', array( $this, 'widget_callback' ), 999, 3); 15 add_filter( 'template_include', array( $this, 'get_template') ); 14 16 15 17 parent::__construct(); 18 } 19 20 public function get_template( $template ){ 21 $this->template = $template; 22 return $template; 16 23 } 17 24 … … 31 38 elseif( $type == 'template' ){ 32 39 $template = $users[$pos]; 33 if( ( is_home() && $template == 'homepage' ) 34 || ( is_singular() && get_post_type() == 'post' && $template = 'single' ) 35 || ( is_page() && $template == 'page' ) 36 || ( is_archive() && $template == 'archive' ) 37 || ( is_category() && $template == 'category' ) 38 || ( is_search() && $template == 'search' ) 39 || ( is_tag() && $template == 'tag' ) 40 || ( is_404() && $template == '404' ) ){ 41 return false; 42 } 40 41 if( $template == 'homepage' && is_home() ) return false; 42 43 if( $template == 'page' && is_page() ) return false; 44 45 if( $template == '404' && is_404() ) return false; 46 47 if( $template == 'single' && is_singular() && 'post' == get_post_type() ) return false; 48 49 if( $template == 'archive' && is_archive() ) return false; 50 51 if( $template == 'category' && is_category() ) return false; 52 53 if( $template == 'tag' && is_tag() ) return false; 54 55 if( $template == 'search' && is_search() ) return false; 56 57 if( $template == 'author' && is_author() ) return false; 58 59 $post = get_post(); 60 $template_id = get_post_meta( $post->ID, '_wp_page_template', true ); 61 62 if( $template == $template_id ) return false; 43 63 } 44 64 } … … 47 67 48 68 public function is_active_sidebar( $is_active_sidebar, $index ){ 49 $values = $this->values( 'cls_sidebars' ); 50 if( $is_active_sidebar && isset( $values[$index] ) ){ 51 $value = $values[$index]; 52 $is_active_sidebar = $this->can( $value ); 69 if( !is_admin() ){ 70 $values = $this->values( 'cls_sidebars' ); 71 72 if( $is_active_sidebar && isset( $values[$index] ) ){ 73 $value = $values[$index]; 74 $is_active_sidebar = $this->can( $value ); 75 } 53 76 } 54 77 return $is_active_sidebar; 55 78 } 56 79 57 public function widget_callback( $instance, $widget, $args ){ 58 $index = $widget->id; 59 $values = $this->values( 'cls_widgets' ); 60 61 if( isset( $values[$index] ) ){ 62 $value = $values[$index]; 63 $return = $this->can( $value ); 64 return !$return ? false : $instance; 65 } 80 public function widget_callback( $instance, $widget, $args ){ 81 82 if( !is_admin() ){ 83 $index = $widget->id; 84 $values = $this->values( 'cls_widgets' ); 85 if( isset( $values[$index] ) ){ 86 $value = $values[$index]; 87 $return = $this->can( $value ); 88 89 if( ! $return ) return false; 90 //return !$return ? false : $instance; 91 } 92 } 66 93 return $instance; 67 94 } … … 101 128 public function before_sidebar($index){ 102 129 printf('<div class="cls-sidebars" data-sidebar="%s"></div>', $index); 130 103 131 } 104 132 … … 131 159 'single' => __('Single Post'), 132 160 'page' => __('Pages'), 133 'archive' => __('Archive'), 134 'category' => __('Category'), 135 'tag' => __('Tag'), 136 '404' => __('404 Error Page'), 137 'search' => __('Search Template') 161 'archive' => __('Archives'), 162 'category' => __('Category Archives'), 163 'tag' => __('Tag Archives'), 164 '404' => __('404 (Not Found)'), 165 'search' => __('Search Results'), 166 'author' => __('Author Template'), 138 167 ) + wp_get_theme()->get_page_templates(); 139 168
Note: See TracChangeset
for help on using the changeset viewer.