undefined array exclude on line 96

28 Views Asked by At

using comic easel plugin on wordpress specifically comic_drop_down_list getting a warning message for an undefined array 'exclude' I tried changing '$exclude = '';' to '= [];' or creating a variable in the function. I'm guessing that somewhere in the code the $instance variable isn't updating correctly. I vaguely understand code so I'm not sure how to fix it. I just want the error messages for exclude and title to go away.

here is the code

<?php


function ceo_list_jump_to_comic($exclude = '',
$return = false)

{
    
    global $post;
    ceo_protect();
    $output = '';
    $terms = wp_get_object_terms( $post->ID, 'chapters');
   
    if (!empty($terms)){
        $term = reset($terms); // only one chapter
        $output = '<form method="get" class="comic-list-dropdown-form">';
        $output .= '<select onchange="document.location.href=this.options[this.selectedIndex].value;">';
        $level = 0;
        $output .= '<option class="level-select" value="">'.__('Jump To','comiceasel').'</option>';
        $post_args = array( 
            'showposts' => -1,
            'post_type' => 'comic',
            'order' => 'ASC', 
            'post_status' => 'publish', 
            'chapters' => $term->slug, 
        );                  
        $qposts = get_posts( $post_args );
        foreach($qposts as $qpost) {
            $permalink = get_permalink($qpost->ID);
            if (!empty($permalink)) $output .='<option class="level-0" value="'.esc_url($permalink).'">'.$qpost->post_title.'</option>';
        }
        $output .= '</select>';
        $output .= '<noscript>';
        $output .= '<div><input type="submit" value="View" /></div>';
        $output .= '</noscript>';
        $output .= '</form>';
        if ($return) {
            return $output;
        } else echo $output;
    }
    ceo_unprotect();
}

class ceo_comic_list_dropdown_widget extends WP_Widget {

    /**
     * Register widget with WordPress.
     */
    function __construct() {
        parent::__construct(
            __CLASS__, // Base ID
            __( 'Comic Easel - Comic List Dropdown', 'comiceasel' ), // Name
            array( 'classname' => __CLASS__, 'description' => __( 'Display dropdown list of comics.', 'comiceasel' ), ) // Args
        );
    }
    
    function widget($args, $instance) {
        global $post;
        extract($args, EXTR_SKIP); 
        echo $before_widget;
        $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); 
        if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; 
        if ((is_home() || is_front_page()) && !is_paged() && !ceo_pluginfo('disable_comic_on_home_page')) {
            $chapter_on_home = '';
            $chapter_on_home = get_term_by( 'id', ceo_pluginfo('chapter_on_home'), 'chapters');
            $chapter_on_home = (!is_wp_error($chapter_on_home) && !empty($chapter_on_home)) ? '&chapters='.$chapter_on_home->slug : '';
            $order = (ceo_pluginfo('display_first_comic_on_home_page')) ?  'asc' : 'desc';
            $query_args = 'post_type=comic&showposts=1&order='.$order.$chapter_on_home;
            apply_filters('ceo_display_comic_mininav_home_query', $query_args);
            $comicFrontpage = new WP_Query(); $comicFrontpage->query($query_args);
            while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post();

            
        ceo_list_jump_to_comic($instance['exclude'], true);
        endwhile;
            
        } elseif (!empty($post)) {

       ceo_list_jump_to_comic($instance['exclude'], false);
            
        }
        echo $after_widget;
    
    }
    
    function update($new_instance, $old_instance) {   
    $instance = $old_instance;
    $instance['title'] = strip_tags($new_instance['title']);
    $instance['exclude'] = strip_tags($new_instance['exclude']);
    return $instance;
       
        
       
    } 
    
    function form($instance) {
        $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'exclude' => '', 'unhide' => 1, 'showcount' => 1) );
        $title = $instance['title'];
        $exclude = $instance['exclude'];
        ?> 
        <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','comiceasel'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
        </p>
        <?php
    }
}


near the end of the code the warning is for a strip_tag

 $instance['exclude'] = strip_tags($new_instance['exclude']);
    return $instance;
0

There are 0 best solutions below