Plugin Directory

Changeset 1077464


Ignore:
Timestamp:
01/28/2015 12:47:38 PM (11 years ago)
Author:
irenem
Message:

Fixed widget visibility not showing at customizer page.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • conditional-logic-solution/trunk/lib/widgets.php

    r1075601 r1077464  
    22class cls_widgets extends class_cls {
    33        var $id = 'cls_widgets';
     4        var $template;
    45       
    56        public function __construct(){
     
    1213                add_filter( 'is_active_sidebar', array( $this, 'is_active_sidebar' ), 999, 2 );
    1314                add_action( 'widget_display_callback', array( $this, 'widget_callback' ), 999, 3);
     15                add_filter( 'template_include', array( $this, 'get_template') );
    1416               
    1517                parent::__construct();
     18        }
     19       
     20        public function get_template( $template ){
     21                $this->template = $template;
     22                return $template;
    1623        }
    1724       
     
    3138                        elseif( $type == 'template' ){
    3239                                $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;
    4363                        }
    4464                }
     
    4767       
    4868        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                        }
    5376                }
    5477                return $is_active_sidebar;
    5578        }
    5679       
    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                }
    6693                return $instance;
    6794        }
     
    101128        public function before_sidebar($index){
    102129                printf('<div class="cls-sidebars" data-sidebar="%s"></div>', $index);
     130               
    103131        }
    104132       
     
    131159                        'single' => __('Single Post'),
    132160                        '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'),
    138167                        ) + wp_get_theme()->get_page_templates();
    139168                       
Note: See TracChangeset for help on using the changeset viewer.