• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Blog » WP-Members 2.8.2 User Table Column Error Patch

WP-Members 2.8.2 User Table Column Error Patch

Chad Butler · Apr 24, 2013 ·

This article is provided free. Find out how you can get full access to premium content, including how-to articles and support forums, as well as priority email support and member exclusive plugin extensions..

 

The first issue with WP-Members 2.8.2 seems to be in the new features in the Users Table (“All Users” in your WP Admin).  This new version allows you to add WP-Members custom fields as columns in the Users Table.  However, there seem to be a couple of issues with the new code.  

First, there are some users reporting an error “Invalid argument supplied for foreach()” found in the file /admin/users.php at line 643.  I believe this may be a result of an empty array value (although I haven’t been able to reproduce the error).

Second, if you have another plugin that adds to the Users Table columns, WP-Members doesn’t necessarily account for that, resulting in empty column values for the other plugin’s column.

I’ve rewritten the two functions that generate the columns and the column values to account for these two issues.  So if you are experiencing this problem, the fix is to replace them.  You will be replacing the function wpmem_add_user_column and wpmem_add_user_column_content which are lines 631-699 in /admin/users.php.  Replace with the following:

/**
 * Function to add custom user columns to the user table
 *
 * @since 2.8.2
 *
 * @param  array $columns
 * @return array $columns
 */
function wpmem_add_user_column( $columns ) 
{
	global $wpmem_user_columns;
	$wpmem_user_columns = get_option( 'wpmembers_utfields' );
	
	if( $wpmem_user_columns ) {
		foreach( $wpmem_user_columns as $key => $val ) {

			if( $key == 'active' ) {
			
				if( WPMEM_MOD_REG == 1 ) {
					$columns[$key] = $val;
				}
			
			} else {
				$columns[$key] = $val;
			}
		}
	}
	
	return $columns;
} 


/**
 * Function to add the user content to the custom column
 *
 * @since 2.8.2
 * 
 * @param $value
 * @param $column_name
 * @param $user_id
 * @return The user value for the custom column
 */
function wpmem_add_user_column_content( $value, $column_name, $user_id ) {

	// is the column a WP-Members column?
	global $wpmem_user_columns;
	$is_wpmem = ( array_key_exists( $column_name, $wpmem_user_columns ) ) ? true : false;
	
	if( $is_wpmem ) {
	
		switch( $column_name ) {
		
		case 'active':
			if( WPMEM_MOD_REG == 1 ) {
			/**
			 * If the column is "active", then return the value or empty.
			 * Returning in here keeps us from displaying another value.
			 */
				return ( get_user_meta( $user_id , 'active', 'true' ) != 1 ) ? __( 'No', 'wp-members' ) : '';
			} else {
				return;
			}
			break;

		case 'user_url':
		case 'user_registered':
			/**
			 * Unlike other fields, website/url is not a meta field
			 */
			$user_info = get_userdata( $user_id );
			return $user_info->$column_name;
			break;
			
		default:
			return get_user_meta( $user_id, $column_name, true );
			break;
		}
	
	}
	
	return $value;
}

Blog bug-fix

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy