Title: foreach() on non-array warning, needs if( is_array() ) check
Last modified: November 20, 2017

---

# foreach() on non-array warning, needs if( is_array() ) check

 *  [pressupinc](https://wordpress.org/support/users/pressupinc/)
 * (@pressupinc)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/empty-array-warning-needs-if-is_array-check/)
 * When I allow the plugin to be used by _non-logged-in_ users, I get an “Invalid
   argument supplied for foreach” PHP warning pointing to line 383 of /inc/class-
   comment-popularity.php.
 * Rest of the plugin seems to work fine, so the following on 383 should fix (and
   does on my install):
 *     ```
       if( is_array( $votes ) ) {
       	foreach ( $votes as $key => $vote ) {
       		$comment_ids_voted_on[ str_replace( 'comment_id_', '', $key ) ] = $vote['last_action'];
       	}
       }
       ```
   
    -  This topic was modified 8 years, 6 months ago by [pressupinc](https://wordpress.org/support/users/pressupinc/).
    -  This topic was modified 8 years, 6 months ago by [pressupinc](https://wordpress.org/support/users/pressupinc/).

The topic ‘foreach() on non-array warning, needs if( is_array() ) check’ is closed
to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/comment-popularity_f8f8f8.svg)
 * [Comment Popularity](https://wordpress.org/plugins/comment-popularity/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/comment-popularity/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/comment-popularity/)
 * [Active Topics](https://wordpress.org/support/plugin/comment-popularity/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/comment-popularity/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/comment-popularity/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [pressupinc](https://wordpress.org/support/users/pressupinc/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/empty-array-warning-needs-if-is_array-check/)
 * Status: not resolved