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.

Extracting variables from EOT demotion hook

Home Forums Community Forum Extracting variables from EOT demotion hook

This topic contains 3 replies, has 3 voices. Last updated by  Eduan 4 years, 3 months ago.

Topic Author Topic
Posted: Thursday Oct 4th, 2012 at 10:37 pm #27519
Mary May
Username: marymay

Note: This posting by Bob Easton, tech support for Mary May.

My very shallow PHP experience gets me ~almost~ where I want to be. I need a little help getting the rest of the way.

Goal: issue an email to a user when an EOT demotion occurs.

I’ve gotten as far as seeing the action occur and extracting all the variables available. Yet, I haven’t been successful in correctly addressing the ones I want. I’ve been doing this by trial and error, grabbing a little bit as people let memberships lapse. In between the infrequency of such activity and the inadequacy of my own PHP skill, progress is very slow. A little help please?

I’m using the following code to collect available variables:

?php
add_action("ws_plugin__s2member_during_auto_eot_system_during_demote", "my_eot_hook_function");
function my_eot_hook_function($vars = array())
	{
		extract($vars);
		$headers = "---intentionally obscure---";
		$subject = "---intentionally obscure---";
		$to = '---intentionally obscure---';
		$message = "Demotion role: $demotion_role\n";
		$message .= '<pre>' . print_r($vars, true) . '</pre>';
		wp_mail($to, $subject, $message, $headers);
	}
?>	

From that, I get a very long response (920 lines) in which I see a lot that interests me. In particular, I would like to use “display_name” and “user_email” but don’t know exactly how to address them.

For example, how would I correctly code the functional equivalent of: $to = $user_email;

Here’s a small part of that array:

[user_id] => 144
[user] => WP_User Object
    (
        [data] => stdClass Object
            (
                [ID] => 144
                [user_login] => dumbo
                [user_pass] => ---intentionally obscure---
                [user_nicename] => dumbo
                [user_email] => dumbo@someplace.com
                [user_url] =>
                [user_registered] => 2012-09-22 01:29:32
                [user_activation_key] =>
                [user_status] => 0
                [display_name] => Dumbo Elephante
                [user_level] => 0
            )

Advice?

Thanks, Bob

  • This topic was modified 4 years, 3 months ago by  Mary May.

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Thursday Oct 4th, 2012 at 11:41 pm #27523
Bruce
Username: Bruce
Staff Member

Hi Bob,

My very shallow PHP experience gets me ~almost~ where I want to be. I need a little help getting the rest of the way.

Goal: issue an email to a user when an EOT demotion occurs.

I’ve gotten as far as seeing the action occur and extracting all the variables available. Yet, I haven’t been successful in correctly addressing the ones I want. I’ve been doing this by trial and error, grabbing a little bit as people let memberships lapse. In between the infrequency of such activity and the inadequacy of my own PHP skill, progress is very slow. A little help please?

I would strongly recommend setting up a local server for development while you’re working with hacking s2Member (or any WordPress plugin or portion of the WordPress framework). I myself have seen first-hand what working on a live site can bring on, and (trust me) it’s not pretty. I would recommend checking into EasyPHP and setting up a WordPress site with just s2Member installed.


I’m using the following code to collect available variables:

<?php
add_action("ws_plugin__s2member_during_auto_eot_system_during_demote", "my_eot_hook_function");
function my_eot_hook_function($vars = array())
	{
		extract($vars);
		$headers = "---intentionally obscure---";
		$subject = "---intentionally obscure---";
		$to = '---intentionally obscure---';
		$message = "Demotion role: $demotion_role\n";
		$message .= '<pre>' . print_r($vars, true) . '</pre>';
		wp_mail($to, $subject, $message, $headers);
	}
?>

From that, I get a very long response (920 lines) in which I see a lot that interests me. In particular, I would like to use “display_name” and “user_email” but don’t know exactly how to address them.

For example, how would I correctly code the functional equivalent of: $to = $user_email;

Essentially what $vars is giving you is everything s2Member has access to at the point that you are hooking into in array format because s2Member sends get_defined_vars(). Therefore, when you extract() this array, you’re then getting back all of the variables as they were within s2Member.

So essentially what you’re looking to do is something like this (I recommend just creating a new user with $user_id):

<?php
add_action("ws_plugin__s2member_during_auto_eot_system_during_demote", "my_eot_hook_function");
function my_eot_hook_function($vars)
	{
		extract($vars);
		
		$user = new WP_User($user_id); # Get the user's data again
		
		$headers = ''; # You decide the appropriate headers
		$subject = 'Demoted from '.get_bloginfo('name');
		$to = '"'.$user->user_firstname.' '.$user->last_name.'" <'.$user->user_email.'>';
		$message = 'Uh-oh! You ran out of time! You were demoted from '.$existing_role.' to '.$demotion_role.'.';
		wp_mail($to, $subject, $message, $headers);
	}

Let me know if that helps you out.

Posted: Friday Oct 5th, 2012 at 9:09 am #27573
Mary May
Username: marymay

Thanks Bruce!
Your sample is just what I needed. It’s interesting how much PHP web page work one can do without needing to know much about array handling.

.$user->user_firstname. gave me exactly what I was looking for.

Sure, I agree about the hazards of working with live sites, and for anything that involved actually altering values or database contents I would use a non-production site. Now, that I have enough to work with, I probably will anyway just to be able to force demotions and move things along faster.

Much appreciated!

Posted: Friday Oct 5th, 2012 at 12:15 pm #27586
Eduan
Username: Eduan
Moderator

Just want to add something here, the $user->user_firstname is actually a variable inside a Object, created by a Class, not an array. Just so you don’t have that misunderstanding, if you ever had it of course. ;)

– Eduan

Viewing 3 replies - 1 through 3 (of 3 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.