Table of Contents
This is a non-comprehensive list of functions from the plugin that might be useful.
This hook can be used to add custom validation to the registration process:
add_action( 'pms_register_form_validation', 'pmsc_add_custom_register_form_validation' );
function pmsc_add_custom_register_form_validation(){
if( $some_condition === false ){
pms_errors()->add( 'user_login', __( 'Your username is invalid', 'paid-member-subscriptions' ) ); // user_login specifies on which field the error should appear.
}
}
The hook is executed before the user is created.
You can run custom functions using these two actions:
do_action( 'pms_register_form_before_create_user', $user_data );
And:
do_action( 'pms_register_form_after_create_user', $user_data );
This hook can be used to add custom validation to Subscription Plans. It can be used both for the registration process but also for the logged in subscribe process.
add_action( 'pms_process_checkout_validations', 'pmsc_add_custom_subscription_plans_validation' );
function pmsc_add_custom_subscription_plans_validation(){
if( $some_condition === false ){
pms_errors()->add( 'subscription_plans', __( 'Something went wrong.', 'paid-member-subscriptions' ) );
}
}
This hook runs when a subscription is created for the first time:
/**
* Fires right after the Member Subscription db entry was inserted into the db
*
* @param int $id - the id of the new member subscription
* @param array $data - the provided data for the current member subscription
*
*/
do_action( 'pms_member_subscription_insert', $this->id, $data );
The first parameter represents the ID of the subscription that was just inserted and $data is an array that contains subscription information.
For example, inside the $data array you can look at $data[‘status’] to check if the subscription was activated or not. There are different situations and the subscription does not get the active status instantly when it’s created, so to fully target subscription activations, you need to also use the update hook from below.
Each time a subscription is updated a different hook runs:
/**
* Fires right after the Member Subscription db entry was updated
*
* @param int $id - the id of the subscription that has been updated
* @param array $data - the array of values to be updated for the subscription
* @param array $old_data - the array of values representing the subscription before the update
*
*/
do_action( 'pms_member_subscription_update', $this->id, $data, $this->to_array() );
This hook can be used to run some code after various actions performed by the plugin. Here is an example function with multiple use cases:
add_action( 'pms_member_subscription_update', 'pmsc_run_actions_on_member_subscription_update', 20, 3 );
function pmsc_run_actions_on_member_subscription_update( $subscription_id, $new_data, $old_data ){
if ( $new_data['status'] != $old_data['status'] && $new_data['status'] == 'active' ){
// run some code when a subscription is activated
}
if ( $new_data['status'] != $old_data['status'] && $new_data['status'] == 'active' && $old_data['status'] == 'pending' ){
// run some code when a subscription is activated for the first time
}
if ( $new_data['status'] != $old_data['status'] && $new_data['status'] == 'expired' ){
// run some code when a subscription is expired
}
if ( $new_data['status'] != $old_data['status'] && $new_data['status'] == 'canceled' ){
// run some code when a subscription is canceled
}
}
You can look at the data inside the two arrays to check for other things as well, like subscription plan id change, expiration date change etc.
This hook runs when a payment is inserted into the database:
/**
* Fires right after the Payment db entry was inserted
*
* @param int $id - the id of the new payment
* @param array $data - the provided data for the current payment
*
*/
do_action( 'pms_payment_insert', $this->id, $data );
The first parameter represents the ID of the payment that was just inserted and $data is an array that contains payment information.
As an example, inside the $data array you could look at the $data[‘status’] key to determine if the payment is completed or not. Usually, payments are completed after the initial insertion so you should use the following hook to properly look at completion.
Each time a payment is updated a different hook runs:
/**
* Fires right after the Payment db entry was updated
*
* @param int $id - the id of the payment that was updated
* @param array $data - the provided data to be changed for the payment
* @param array $old_data - the array of values representing the payment before the update
*
*/
do_action( 'pms_payment_update', $this->id, $data, $this->to_array() );
This hook can be used to run some code after the plugin updates a payment. Here is an example function with some use cases:
add_action( 'pms_payment_update', 'pmsc_run_actions_on_payment_update', 20, 3 );
function pmsc_run_actions_on_payment_update( $payment_id, $new_data, $old_data ){
if( isset( $new_data['status'] ) && $new_data['status'] != $old_data['status'] && $new_data['status'] == 'completed' ){
// run some code when a payment is completed
}
if( isset( $new_data['status'] ) && $new_data['status'] != $old_data['status'] && $new_data['status'] == 'failed' ){
// run some code when a payment fails
}
}
You can look at the data inside the two arrays to perform other checks as well, for example, executing an action only when the payment refers to a certain subscription plan.
The $new_data array will only contain the data that is being changed in the current request. Inside the $old_data array you will find all of the other data that remained the same.
Accept (recurring) payments, create subscription plans and restrict content on your website. Easily setup a WordPress membership site using Paid Member Subscriptions.
Get Paid Member SubscriptionsCombine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.
Get 25% off with the bundle