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.

30 Days Free trial using code

Home Forums Community Forum 30 Days Free trial using code

This topic contains 3 replies, has 2 voices. Last updated by  Raam Dev 4 years, 5 months ago.

Topic Author Topic
Posted: Friday Aug 3rd, 2012 at 10:02 am #21111

I would like to create/register a user using my own form by passing $username, $password, $email and then assign user level 1 BUT only for 30 days then demote. Is there a way to add a date into user meta EOT?

here is my attempt below

<?php
$user_id = wp_create_user(username, password, email);
$user = new WP_User($user_id);
$user->set_role('s2member_level1'); // Give them level 1 Membership
add_user_meta( $user_id, 'last_name', $lastname);
add_user_meta( $user_id, '_s2member_auto_eot_time', $eot_date);
add_user_meta( $user_id, 's2member_notes', 'Administrative notation. Created this User via wp_create_user.');

Or could you shed some light onto how to use Pro API for Remote Operations, like where to put the code (i.e. In the template form, functions.php) more practical example than just saying look here.

Update

After having a look around, i added the code below in the page and suprise suprise it worked.

<?php
$op["op"] = "create_user"; /* The Remote Operation you're calling upon. */
/**/
$op["api_key"] = "1234567890"; /* Your Remote Ops API Key. */

/**/
$op["data"] = array (/**/
"user_login" => "johndoe22", /* Required. A unique Username. Lowercase alphanumerics/underscores. */
"user_email" => "johndoe22@example.com", /* Required. A valid/unique Email Address for the new User. */
"user_pass" => "456DkaIjsd!", /* Optional. Plain text Password. If empty, one will be generated. */
"first_name" => "John", /* Optional. First Name for the new User. */
"last_name" => "Doe", /* Optional. Last Name for the new User. */
"s2member_level" => "2", /* Optional. Defaults to Level #0 ( a Free Subscriber ). */
"s2member_ccaps" => "music,videos", /* Optional. Comma-delimited list of Custom Capabilities. */
"s2member_registration_ip" => "123.456.789.100", /* Optional. User's IP Address. If empty, s2Member will fill this upon first login. */
"s2member_subscr_gateway" => "paypal", /* Optional. User's Paid Subscr. Gateway Code. One of: (paypal|alipay|authnet|ccbill|clickbank|google). */
"s2member_subscr_id" => "I-DJASODJF8933J", /* Optional. User's Paid Subscr. ID. For PayPal®, use their Subscription ID, or Recurring Profile ID. */
"s2member_custom" => "wordpress.local.com", /* Optional. If provided, should always start with your installation domain name ( i.e. $_SERVER["HTTP_HOST"] ). */
"s2member_auto_eot_time" => "2030-12-25", /* Optional. Can be any value that PHP's ``strtotime()`` function will understand ( i.e. YYYY-MM-DD ). */
"opt_in" => "1", /* Optional. A non-zero value tells s2Member to attempt to process List Servers that you've configured in the Dashboard area. */
"custom_fields" => array ("my_field_id" => "Some value."), /* Optional. An array of Custom Registration Field ID's, with associative values. */
"s2member_notes" => "Administrative notation. Created this User via API call.", /* Optional. Administrative notations. */
"notification" => "1", /* Optional. A non-zero value tells s2Member to email the new User/Member their Username/Password. */
/* The "notification" parameter also tells s2Member to notify the site Administrator about this new account. */
);
/**/
$result = trim (file_get_contents ("http://wordpress.local.com/?s2member_pro_remote_op=1", false, stream_context_create (array ("http" => array ("method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded", "content" => "s2member_pro_remote_op=" . urlencode (serialize ($op)))))));
/**/
if (!empty ($result) && !preg_match ("/^Error\:/i", $result) && is_array ($user = @unserialize ($result)))
    {
        echo "Success. New User created with ID: " . $user["ID"];
    }
else
    echo "API error reads: " . $result;
?> 

Now, i’m trying to display the EOT using the short-code [EOT] but that’s not even processing. Ended up using the code to also calculate days remaining which was abit confusing at first. NB* Only supported in PHP 5.3+

<h3>Your free trial is due for renewal in 
	<?php

		$eotdate = get_user_field ("s2member_auto_eot_time");

		$today = date("Y-m-d");

		$datetime1 = new DateTime("@$eotdate");
		$datetime2 = new DateTime("$today");
		$interval = $datetime1->diff($datetime2);
		echo $interval->format('%a days');

	?>
</h3>

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Saturday Aug 4th, 2012 at 11:54 pm #21169
Raam Dev
Username: Raam
Staff Member

Hi Thomas,

I’m not sure if you’re saying there is still a problem or if you’ve solved it. Is there still a problem?

Posted: Monday Aug 6th, 2012 at 5:08 am #21210

Sorry Raam

I had a problem then found a fix to the original problem and the “Days left before renewal” calculation. This is now solved and just wanted to put it out there incase someone else may find it useful but didn’t know how to mark it as solved.

Thank you once again for a great plugin.

Posted: Tuesday Aug 7th, 2012 at 2:21 am #21321
Raam Dev
Username: Raam
Staff Member

Thank you for the update, Thomas, and for sharing the solution! :)

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.