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.

Remote User Status (Custom API)

Home Forums Community Forum Unofficial Extensions/Hacks Remote User Status (Custom API)

This topic contains 0 replies, has 1 voice. Last updated by  Jason (Lead Developer) 4 years, 10 months ago.

Topic Author Topic
Posted: Tuesday Mar 6th, 2012 at 4:17 am #7422
Staff Member

Hack Description

If you have a 3rd party application that needs to check if a particular Username is a paying Member of your site (i.e. to test the current status of their account), this hack might be for you. Of course, there are many other ways this could be used, but I'll let this serve as one example that you might follow.

Hack Instructions

Create this directory and file in your WordPress installation:
/wp-content/mu-plugins/s2-hacks.php
(these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins)

<?php
add_action("init", "s2_user_status"); function s2_user_status()
	{
		$my_secret_api_key = "my-secret-api-key";
		if(isset($_GET&#91;"s2_user_status_api_key"&#93;, $_GET&#91;"s2_username"&#93;) && $_GET&#91;"s2_user_status_api_key"&#93; === $my_secret_api_key)
			{
				$username = trim(stripslashes((string)$_GET&#91;"s2_username"&#93;));
				if(is_object($user = new WP_User($username)) && !empty($user->ID))
					if($user->has_cap("access_s2member_level1"))
						exit("1");
				/* Else exit with "0", NOT a paid Member. */
				exit("0");
			}
	}
?>

Now, you might create a script that calls upon this Custom API, and it might look something like this.

<?php
$username = "johndoe22";
if($is_paying_member = file_get_contents("http://www.example.com/?s2_user_status_api_key=my-secret-api-key&s2_username=".urlencode($username)))
	echo 'Yes, they ARE a paying Member of the site.';
?>

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.