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>