latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

EOT column not displaying data for users

Home Forums Community Forum EOT column not displaying data for users

Tagged: 

This topic contains 10 replies, has 5 voices. Last updated by  Bruce 4 years, 1 month ago.

Topic Author Topic
Posted: Wednesday Nov 7th, 2012 at 10:02 pm #30978

I pasted Bruce’s EOT column hack in my s2-hacks.php file. The column appears in my user list and looks sortable, but every user receives a long dash in the EOT column (even those with verified EOTs). Registration dates appear okay.

s2member Version: 121023
WP Version: 3.4.2

List Of Topic Replies

Viewing 10 replies - 1 through 10 (of 10 total)
Author Replies
Author Replies
Posted: Thursday Nov 8th, 2012 at 11:47 am #31039
Eduan
Username: Eduan
Moderator

Hello Quentin,

Could you please sow us an image of your problem? So that we may see what the problem is, better. Thanks. :)

– Eduan

Posted: Friday Nov 9th, 2012 at 12:13 pm #31143

The first image is from the Users panel in the Dashboard. The second image displays the EOT for the user with a transaction ID in the first image. Even when I modify Bruce’s hack in s2-hacks.php to change the output of the EOT column value when none exists, the column only contains instances of “–“.

Posted: Monday Nov 12th, 2012 at 4:53 pm #31349
Raam Dev
Username: Raam
Staff Member

Hi Quentin,

Thank you very much for the screenshot. Could you please also show us exactly what code you’re using for this hack? I would like to double-check that there are no bugs that might be causing this problem.

Posted: Monday Nov 12th, 2012 at 8:16 pm #31394

Yes. This is /wp-content/mu-plugins/s2-hacks.php

<?php

/*
* Code to order columns adopted from http://wordpress.org/support/topic/make-extra-columns-in-userphp-sortable#post-2810255
*
* Hack tested s2Member v120703; WordPress version 3.4.2; PHP v5.4 on September 25, 2012
*/

add_filter('manage_users_columns', 's2hack_eot_column_add');
function s2hack_eot_column_add($col)
	{
		$col['s2member_auto_eot_time'] = 'EOT'; # Set title for column
		return $col;
	}

add_filter('manage_users_custom_column', 's2hack_eot_column_edit_val', 10, 3);
function s2hack_eot_column_edit_val($val, $col_name, $id)
	{
		$user = get_userdata($id); # Get the user's info
		
		if($col_name === 's2member_auto_eot_time' && ($eot = get_user_field('s2member_auto_eot_time', $user->ID))) # If column is for EOT, and user's EOT date is not empty
			return date("D M dS, Y".'<\b\r /><\s\m\a\l\l>'."@\p\\r\\e\c\i\s\\e\l\y g:i a".'</\s\m\a\l\l>', $eot); # return the date user's membership expires (using same standards as s2Member registration date layout)
		
		elseif($col_name === 's2member_auto_eot_time') # Otherwise, if the user does not have an EOT date
			return '--'; # Just return -- as s2Member does normally
		
		else return $val; # Otherwise, we don't need to edit this
	}

add_action('pre_user_query', 's2hack_eot_column_query'); # This could also be changed from pre_user_query to query, but easier to work with an object (pre_user_query) than a string(query)
function s2hack_eot_column_query($query)
	{
		global $wpdb; # Get WordPress database class / for prefix
		$vars = $query->query_vars; # Query variables reassigned for easier access
		
		if($vars['orderby'] === 's2member_auto_eot_time') # If querying the s2Member Automatic EOT times
			{
				// Could var_dump($query) here if need to know the values within the $query Object
				$query->query_from .= " LEFT JOIN ".$wpdb->prefix."usermeta m ON (".$wpdb->prefix."users.ID = m.user_id  AND m.meta_key = '".$wpdb->prefix."$vars[orderby]')"; # Append meta values for s2Member EOT times...
				$query->query_orderby = "ORDER BY m.meta_value ".$vars['order']; # ...and order by these times by EOT in ASC or DESC order, depending on the query
			}
	}

add_filter('manage_users_sortable_columns', 's2hack_eot_column_add_sort');
function s2hack_eot_column_add_sort($columns)
	{
		$columns['s2member_auto_eot_time'] = 's2member_auto_eot_time'; # Add eot column to sortable columns
		return $columns; # Then return all sortable columns
	}

// hack to deliver paypal button with date based expiration
// no longer used now that club expires all memberships on 7/1
add_action("ws_plugin__s2member_before_sc_paypal_button", "s2_hacks_eot_by_date");
function s2_hacks_eot_by_date($vars = array())
{
	if ($vars["attr"]["expire"] && $vars["attr"]["cutoff"])	
	{
		$expire = strtotime($vars["attr"]["expire"] . "+1 day"); // Include all of the last day
		$cutoff = strtotime($vars["attr"]["cutoff"] . "+1 day"); // Include all of the last day
		$now = time();
		if($now > $cutoff) {
			$expire = strtotime(date("Y-m-d", $expire) . "+1 year"); // Add one year if after cutoff
		}
		$timeleft = $expire-$now;
		$daysleft = round((($timeleft/24)/60)/60) + 1; // Add one day to include the last day
		$vars["attr"]["rp"] = $daysleft; // Set the number of days
		$vars["attr"]["rt"] = "D"; // Set the rate term to days
		$vars["attr"]["custom"] .= "|" . date("Y-m-d", $expire); // Append computed EOT to the custom field
		unset($vars["attr"]["expire"]);
		unset($vars["attr"]["cutoff"]);
	}
	return;
}




?>
Posted: Tuesday Nov 13th, 2012 at 3:21 am #31430

I tried this code just now at my site, and it’s working fine..

Posted: Tuesday Nov 13th, 2012 at 8:20 am #31439
Eduan
Username: Eduan
Moderator

I compared the code against Bruce’s, and I noticed that you changed some things… Could you please try the original hack Bruce made, without the changes?

I suppose the following code is your own correct?

// hack to deliver paypal button with date based expiration
// no longer used now that club expires all memberships on 7/1
add_action("ws_plugin__s2member_before_sc_paypal_button", "s2_hacks_eot_by_date");
function s2_hacks_eot_by_date($vars = array()) {
	if ($vars["attr"]["expire"] && $vars["attr"]["cutoff"]) {
		$expire = strtotime($vars["attr"]["expire"] . "+1 day"); // Include all of the last day
		$cutoff = strtotime($vars["attr"]["cutoff"] . "+1 day"); // Include all of the last day
		$now = time();
		if($now > $cutoff) {
			$expire = strtotime(date("Y-m-d", $expire) . "+1 year"); // Add one year if after cutoff
		}
		$timeleft = $expire-$now;
		$daysleft = round((($timeleft/24)/60)/60) + 1; // Add one day to include the last day
		$vars["attr"]["rp"] = $daysleft; // Set the number of days
		$vars["attr"]["rt"] = "D"; // Set the rate term to days
		$vars["attr"]["custom"] .= "|" . date("Y-m-d", $expire); // Append computed EOT to the custom field
		unset($vars["attr"]["expire"]);
		unset($vars["attr"]["cutoff"]);
	}
	return;
}

– Eduan

Posted: Tuesday Nov 13th, 2012 at 12:11 pm #31456

I replaced the entirety of my s2-hacks.php file with just Bruce’s code, and the result is the same. I’m going to deactivate other plugins until this works to see if I have a plugin conflict.

Posted: Tuesday Nov 13th, 2012 at 6:46 pm #31499
Eduan
Username: Eduan
Moderator

OK, yes I was gonna suggest that next. Make sure you follow the instructions in this article fully (for finding conflicts):
Knowledge Base » Common Troubleshooting Tips

– Eduan

Posted: Monday Nov 26th, 2012 at 11:20 am #32596

The incompatibility is with Ajax Event Calendar. When Ajax Event Calendar is disabled, the EOT column displays properly.

The plugin functionality that may cause this issue is:

Track the number of events created by each user in the Users menu

A quick fix is to disable the functionality by editing ajax-event-calendar.php like so:

// wordpress overrides
//add_filter('manage_users_columns', array($this, 'add_events_column'));
//add_filter('manage_users_custom_column', array($this, 'add_events_column_data'), 10, 3);

Of course, the edit doesn’t fix the cause of incompatibility. If anyone sees the reason for incompatibility in the Ajax Event Calendar plugin code, please chime in:

// CUSTOMIZE WORDPRESS
// adds column field label to WordPress users page
function add_events_column($columns) {
	$columns['calendar_events'] = __('Events', AEC_NAME);
	return $columns;
}

// adds column field value to WordPress users page
function add_events_column_data($empty='', $column_name, $user_id) {
	if ($column_name == 'calendar_events') {
		return $this->db_query_events_by_user($user_id);
	}
}
function db_query_events_by_user($user_id) {
	global $wpdb;
	$result = $wpdb->get_var($wpdb->prepare('SELECT count(id)
		 FROM ' . $wpdb->prefix . AEC_EVENT_TABLE . '
		 WHERE user_id = %d;', $user_id));
	return $this->return_result($result);
}
function return_result($result) {
	if ($result === false) {
		global $wpdb;
		$this->log($wpdb->print_error());
		return false;
	}
	return $result;
}
function log($message) {
	if (is_array($message) || is_object($message)) {
		error_log(print_r($message, true));
	} else {
		error_log($message);
	}
	return;
}
  • This reply was modified 4 years, 1 month ago by  Quentin Algood.
  • This reply was modified 4 years, 1 month ago by  Quentin Algood. Reason: code
  • This reply was modified 4 years, 1 month ago by  Quentin Algood. Reason: more code
  • This reply was modified 4 years, 1 month ago by  Quentin Algood.
Posted: Saturday Dec 1st, 2012 at 3:30 pm #33117
Bruce
Username: Bruce
Staff Member

Hi Quentin,

Thanks for all the information

Just scanning over this, I see the greatest probability for this incompatibility within this code:

function db_query_events_by_user($user_id) {
	global $wpdb;
	$result = $wpdb->get_var($wpdb->prepare('SELECT count(id)
		 FROM ' . $wpdb->prefix . AEC_EVENT_TABLE . '
		 WHERE user_id = %d;', $user_id));
	return $this->return_result($result);
}

I will, however, take a look at the plugin and find out what the incompatibility and either contact the plugin’s creator, or fix the incompatibility within the hack to prevent this from happening in the future.

Thank-you!

Viewing 10 replies - 1 through 10 (of 10 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.