Note: This is part of the developer docs and is considered custom code.
Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.
If you need assistance with this, please reach out to our list of consultants for further assistance:
Table of Contents
The RCP_Customer class was released in version 3.0. It is used for getting and updating customer data. A customer is defined as a user who has (or has had) a Restrict Content Pro membership on your site.
Getting a customer
A customer object can be retrieved in a variety of ways.
By customer ID:
If you know the customer's ID number, you can use the
rcp_get_customer() function and pass in the ID number, like so:
$customer = rcp_get_customer( 123 );
By user ID number:
If you know the customer's user ID number, you can use the
rcp_get_customer_by_user_id() function and pass in the user ID number, like so:
$customer = rcp_get_customer_by_user_id( 44 );
If a customer cannot be found, the functions will return
Do not create a new instance of the RCP_Customer class manually.
Retrieving customer data
Once you have an RCP_Customer object, you can use it to retrieve information about the customer. Here's a list of helper methods:
Returns the customer's ID number.
Returns the ID number of the customer's associated user account.
Returns an array of all known IP addresses of this customer.
Returns a string of notes associated with this customer.
- get_memberships( $args = array() )
Returns an array of all memberships the customer has. Optionally, you can pass in an array of arguments to further filter the results. Any arguments from the rcp_get_memberships() function are permitted.
Returns an array of payments this customer submitted (payment objects).
Returns true if the customer is pending email verification.
Other helper methods
Returns true if the customer has used a free trial, false if not
Returns true if the customer has at least one active membership.
Returns true if the customer has at least one active and paid membership
- can_access( $post_id )
Pass in a post ID to determine if the customer has permission to view that post.
- has_access_level( $access_level_needed = 0 )
Pass in an access level number (integer from 0 to 10) to determine if the customer has that access level or higher.
- add_ip( $ip )
Use this method to add an IP address to the customer's known IPs.
- add_note( $note )
Add a new customer note.
Marks the customer as having verified their email address.
Updating a customer
You can also update customer data using the update() method and passing in an array of data to update. The following arguments are supported:
user_id(int) - ID of the associated user account.
date_registered(string) - Date the customer registered, in MySQL format.
email_verification(string) - Status of the user's email verification. Accepted values are:
none(verification was never required),
pending(verification is required and not yet done),
verified(verification was required and has been completed).
last_login(string) - Date the customer last logged in, in MySQL format.
ips(array) - Array of known IP addresses for this customer.
notes(string) - Notes about this customer.
$customer = rcp_get_customer( 123 ); $customer->update( array( 'last_login' => current_time( 'mysql' ) ) );