WP-Members 2.8.2 User Table Column Error Patch

 

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;
}

Private

You do not have permission to view this forum.