RCP_Customer

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 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 false.

Do not create a new instance of the RCP_Customer class manually.

Retrieving customer data

Once you have a RCP_Customer object, you can use it to retrieve information about the customer. Here's a list of helper methods:

  • get_id()
    Returns the customer's ID number.
  • get_user_id()
    Returns the ID number of the customer's associated user account.
  • get_ips()
    Returns an array of all known IP addresses of this customer.
  • get_notes()
    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.
  • get_payments()
    Returns an array of payments this customer submitted (payment objects).
  • is_pending_verification()
    Returns true if the customer is pending email verification.

Other helper methods

  • 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 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.
  • verify_email()
    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.

Example:

$customer = rcp_get_customer( 123 );
$customer->update( array(
    'last_login' => current_time( 'mysql' )
) );
Note: Although "notes" is supported when updating a customer, this will wipe out any existing notes. It's recommended you use the $customer->add_note( 'Your new note' ) method if you wish to add a new note.