Exemple #1
0
 /**
  * The save options function
  */
 function update($new_instance, $old_instance)
 {
     /** Set the previous value */
     $instance = $old_instance;
     /** Extract the current values for shortcut */
     extract($new_instance);
     /** Sanitize the inputs properly */
     $instance['title'] = strip_tags($title);
     $instance['teaser'] = strip_tags($teaser);
     $instance['cat_id'] = (int) $cat_id;
     $instance['css_theme'] = $css_theme;
     $instance['show_feed'] = (bool) $show_feed;
     $instance['show_read_more'] = (bool) $show_read_more;
     $instance['feed_html'] = wp_kses_data($feed_html);
     $instance['read_more_html'] = wp_kses_data($read_more_html);
     $instance['is_thumb'] = (bool) $is_thumb;
     $instance['thumb_class'] = strip_tags($thumb_class);
     $instance['list_num'] = (int) $list_num;
     $instance['widget_class'] = strip_tags($widget_class);
     $instance['list_style'] = (bool) $list_style;
     $instance['show_comments'] = (bool) $show_comments;
     $instance['sort_using'] = (int) $sort_using;
     $instance['sort_order'] = (bool) $sort_order;
     $instance['before_main_widget'] = $before_main_widget;
     $instance['after_main_widget'] = $after_main_widget;
     $instance['before_link'] = $before_link;
     $instance['after_link'] = $after_link;
     $instance['exclude_post'] = strip_tags($exclude_post);
     $instance['sticky_post'] = strip_tags($sticky_post);
     $instance['open_in'] = (bool) $open_in;
     $instance['alternate_list_css'] = (bool) $alternate_list_css;
     $instance['show_date'] = (bool) $show_date;
     $instance['show_author'] = (bool) $show_author;
     $instance['show_excerpt'] = (bool) $show_excerpt;
     $instance['excerpt_length'] = (int) $excerpt_length;
     $instance['optional_excerpt'] = (bool) $optional_excerpt;
     $instance['title_hyper'] = (bool) $title_hyper;
     /**
      * Little negative fix for excerpt_length and list_num
      * @since 1.1.0
      */
     if ($instance['list_num'] < 0) {
         $instance['list_num'] = $instance['list_num'] * -1;
     }
     if ($instance['excerpt_length'] < 0) {
         $instance['excerpt_length'] = $instance['excerpt_length'] * -1;
     }
     /** Delete the previous cache */
     wp_cache_delete($this->id);
     /** Check for any error */
     /** Reset the error first */
     $instance['error'] = false;
     /** Now search for possibilities */
     if ($instance['title'] == '') {
         $instance_error .= '<li>&rarr;' . __('<strong style="color: red">Error</strong>: The Title field is empty', 'wp-cat-list-itg') . '</li>';
     }
     if ($instance['cat_id'] != -1 && !category_exists($instance['cat_id'])) {
         $instance_error .= '<li>&rarr;' . __('<strong style="color: red">Error</strong>: The category does not exists', 'wp-cat-list-itg') . '</li>';
     }
     $form_cat_count = itgdb_wp_cpl_loader::wp_get_postcount($instance['cat_id']);
     if ($instance['cat_id'] != -1 && 0 == $form_cat_count) {
         $instance_error .= '<li>&rarr;' . __('<strong style="color: red">Error</strong>: The category is empty', 'wp-cat-list-itg') . '</li>';
     } else {
         if ($instance['cat_id'] != -1 && $instance['list_num'] > $form_cat_count) {
             $instance_error .= '<li>&rarr;' . __('<strong style="color: #c3bc00">Warning</strong>: The number of posts is less than your entered number. No worries though! <em>Total number of posts', 'wp-cat-list-itg') . $form_cat_count . '</em></li>';
         }
     }
     if (isset($instance_error)) {
         $instance_error = '<ul style="font-style: italic">' . $instance_error . '</ul>';
         $instance['error'] = $instance_error;
     }
     /** Return it */
     return $instance;
 }