Title: [PATCH] More undefined offsets
Last modified: August 21, 2016

---

# [PATCH] More undefined offsets

 *  [flynsarmy](https://wordpress.org/support/users/flynsarmy/)
 * (@flynsarmy)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/patch-more-undefined-offsets/)
 * I’m getting a bunch of warnings that break the widgets list page in admin and
   make all widgets below undraggable.
 * Because that’s a huge amount of change, here’s the updated version that you can
   do a diff on [http://pastebin.com/PxAMf0ss](http://pastebin.com/PxAMf0ss)
 * In /plugins/extended-categories-widget/3.3/class/avh-ec.widgets.php WP_Widget_AVH_ExtendedCategories_Normal::
   form() (around line 255):
 * Change
 *     ```
       $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : FALSE;
       ```
   
 * to
 *     ```
       $selected_cats = (isset($instance['post_category']) && $instance['post_category'] != '') ? unserialize($instance['post_category']) : FALSE;
       ```
   
 * Change all instances of
 *     ```
       (bool) $instance['...']
       ```
   
 * to
 *     ```
       !empty($instance['...'])
       ```
   
 * Change the 3 instances from
 *     ```
       ..., $options, $instance['...']);
       ```
   
 * to
 *     ```
       ..., $options, @$instance['...']);
       ```
   
 * or preferrably
 *     ```
       ..., $options, isset($instance['...']) ? $instance['...'] : '');
       ```
   
 * Now down in WP_Widget_AVH_ExtendedCategories_Category_Group::form() (around line
   748) do the same thing but also here’s an updated version of the ‘Prepare data
   for display’ section which had generated heaps of warnings:
 *     ```
       // Prepare data for display
       		$title = esc_attr($instance['title']);
       		$count = !empty($instance['count']);
       		$hierarchical = !empty($instance['hierarchical']);
       		$hide_empty = !empty($instance['hide_empty']);
       		$use_desc_for_title = !empty($instance['use_desc_for_title']);
       		$sort_id = (isset($instance['sort_column']) && $instance['sort_column'] == 'ID') ? ' SELECTED' : '';
       		$sort_name = (isset($instance['sort_column']) && $instance['sort_column'] == 'name') ? ' SELECTED' : '';
       		$sort_count = (isset($instance['sort_column']) && $instance['sort_column'] == 'count') ? ' SELECTED' : '';
       		$sort_order_a = (isset($instance['sort_order']) && $instance['sort_order'] == 'asc') ? ' SELECTED' : '';
       		$sort_order_d = (isset($instance['sort_order']) && $instance['sort_order'] == 'desc') ? ' SELECTED' : '';
       		$style_list = (isset($instance['sort_column']) && $instance['style'] == 'list') ? ' SELECTED' : '';
       		$style_drop = (isset($instance['sort_column']) && $instance['style'] == 'drop') ? ' SELECTED' : '';
       		$rssfeed = !empty($instance['rssfeed']);
       		$rssimage = esc_attr($instance['rssimage']);
   
       		$selected_cats = (isset($instance['post_group_category']) && $instance['post_group_category'] != '') ? unserialize($instance['post_group_category']) : FALSE;
       ```
   
 * Back up in WP_Widget_AVH_ExtendedCategories_Top::form (around line 457) same 
   thing again but also change
 *     ```
       if (! $amount = (int) $instance['amount']) {
       ```
   
 * to
 *     ```
       if (!isset($instance['amount']) || !($amount = (int) $instance['amount']) ) {
       ```
   
 * I would actually recommend you create a get_instance_var() method so you can 
   call
    $this->get_instance_var($instance, ‘hierarchical’, false) and it’ll handle
   isset() and stuff for you. something like:
 *     ```
       public function get_instance_var( $instance, $key, $default=NULL )
       {
       	if ( !is_array($instance) || !array_key_exists($instance, $key) )
       		return $default;
   
       	return $instance[$key];
       }
       ```
   
 * [http://wordpress.org/plugins/extended-categories-widget/](http://wordpress.org/plugins/extended-categories-widget/)

The topic ‘[PATCH] More undefined offsets’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/extended-categories-widget.svg)
 * [AVH Extended Categories Widgets](https://wordpress.org/plugins/extended-categories-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/extended-categories-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/extended-categories-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/extended-categories-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/extended-categories-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/extended-categories-widget/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [flynsarmy](https://wordpress.org/support/users/flynsarmy/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/patch-more-undefined-offsets/)
 * Status: not resolved