Restrict Content Pro
RCP_Customer
Coming soon: Restrict Content Pro is becoming Kadence Memberships. You may see both names used while we update the product, documentation, and customer experience.
Note: This content is provided as a resource within our developer documentation. Because custom code requires highly specific implementation, we encourage you to work with a qualified developer if you need guidance. You can find our recommended consultants here: https://codeable.io/developers/restrict-content-pro
The RCP_Customer class was released in version 3.0. It is used for getting and updating customer data. A customer is 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 several ways.
By customer ID: If you know the customer’s ID number, use rcp_get_customer() and pass in the ID:
$customer = rcp_get_customer( 123 );
By user ID: If you know the customer’s WordPress user ID, use rcp_get_customer_by_user_id():
$customer = rcp_get_customer_by_user_id( 44 );
If a customer cannot be found, these functions return false.
rcp_get_customers can also return RCP_Customer objects when querying multiple customers.
Do not create a new instance of the RCP_Customer class manually.
Retrieving customer data
Once you have an RCP_Customer object, you can retrieve information about the customer. Helper methods include:
get_id()– Returns the customer’s ID number.get_user_id()– Returns the ID of the customer’s associated user account.get_ips()– Returns an array of all known IP addresses for this customer.get_notes()– Returns a string of notes associated with this customer.get_memberships( $args = array() )– Returns an array of memberships for this customer. You can pass query arguments fromrcp_get_memberships()to filter results.get_payments( $args = array() )– Returns an array of payments this customer submitted.is_pending_verification()– Returns true if the customer is pending email verification.has_trialed()– Returns true if the customer has used a free trial, false if not.has_active_membership()– Returns true if the customer has at least one active membership.has_paid_membership()– Returns true if the customer has at least one active, paid membership.can_access( $post_id )– Pass a post ID to determine whether the customer can view that post.has_access_level( $access_level_needed = 0 )– Pass an access level (integer from 0 to 10) to determine whether the customer has that access level or higher.add_ip( $ip )– Adds an IP address to the customer’s known IPs.add_note( $note )– Adds a new customer note.verify_email()– Marks the customer as having verified their email address.
Updating a customer
You can update customer data with the update() method by passing an array of data. Supported arguments:
user_id(int) – ID of the associated user account.date_registered(string) – Date the customer registered, in MySQL format.email_verification(string) – Email verification status. Accepted values: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.
Example:
$customer = rcp_get_customer( 123 );
$customer->update( array(
'last_login' => current_time( 'mysql' )
) );
Although notes is supported when updating a customer, doing so replaces any existing notes. To append a note, use $customer->add_note( 'Your new note' ) instead.