Actions and Filters in MemberPress

Covered in this article

What Are Hooks?

Hooks in WordPress allow you to change or add code without editing core files. They are used extensively throughout WordPress and MemberPress and are very useful for developers.

There are two types of hook: actions and filters.
  • Actions allow you to insert custom code wherever the hook is run
  • Filters allow you to manipulate and return a variable that it passes to filter
This documentation is a list of some of the most useful actions and filters in MemberPress.

Please note, that this is a Developer level documentation. Our support doesn't cover custom development. 
If you need any help with your customization you can contact one of the developers.

Using Hooks

If you want to use a hook to add or manipulate code, you can add your custom code in many ways:

  • You can add your code at the end of your theme's functions.php file
  • Use one of the plugins such as Code Snippets

Using action hooks

To execute your own code using action hook, you need to use your custom function like this:

add_action( 'action_name', 'your_function_name' );
function your_function_name() {
    // Your code
}

Using filter hooks

To manipulate the passed variable in filter hook, you need to use your custom function like this:

add_filter( 'filter_name', 'your_function_name' );
function your_function_name( $variable ) {
    // Your code
    return $variable;
}

Keep in mind that with filters, you must return a value.

Overview

Actions

Filters

mepr-above-checkout-form

Description

It is used on registration page and allows you to add custom code above the registration form

Parameters

$membership_id Number

Example

function mepr_content_above_registration_form($membership_id) {
    // Put your content here
}

add_action('mepr-above-checkout-form', 'mepr_content_above_registration_form');

mepr-checkout-before-name

Description

It is used on registration form above the first and last name

Parameters

$membership_id Number

Example

function mepr_content_above_name($membership_id) {
    // Put your content here
}

add_action('mepr-checkout-before-name', 'mepr_content_above_name');

mepr-checkout-after-email-field

Description

Add Email Validation Field to MemberPress checkout form

Parameters

$membership_id Number

Example

<?php
function display_validate_email_field($membership_id) {
    ?>
    <div class="mp-form-row mepr_validate_email">
        <div class="mp-form-label">
            <label><?php _ex('Verify Email:*', 'ui', 'memberpress'); ?</label>
            <span class="cc-error"><?php _ex('Invalid Email', 'ui', 'memberpress'); ?></span>
        </div>
        <input type="email" name="user_validate_email" id="user_validate_email" class="mepr-form-input" value="" required />
    </div>
    <?php
}
add_action('mepr-checkout-after-email-field', 'display_validate_email_field');

function check_validate_email($errors) {
    if(is_user_logged_in()) { return $errors; }

    if(!isset($_POST['user_validate_email']) || empty($_POST['user_validate_email'])) {
        $errors[] = "You must enter your email address twice to verify it.";
    }
    if(!is_email($_POST['user_validate_email'])) {
        $errors[] = "Invalid Verify Email. Email is not a real email address.";
    }
    if($_POST['user_validate_email'] != $_POST['user_email']) {
        $errors[] = "Your email addresses do not match.";
    }

    return $errors;
}
add_filter('mepr-validate-signup', 'check_validate_email');

mepr-signup-styles

Description

Add custom style to signup page

Parameters

$prereqs Array

Example

function mepr_signup_styles($prereqs) {
  // Do what you need
  return $prereqs;
}
add_filter('mepr-signup-styles', 'mepr_signup_styles');

mepr-signup-scripts

Description

Add custom script to signup or account page

Parameters

$prereqs Array
$is_product_page Boolean
$is_account_page Boolean

Example

function mepr_signup_scripts($prereqs, $is_product_page, $is_account_page) {
  // Do what you need
  return $prereqs;
}
add_filter('mepr-signup-scripts', 'mepr_signup_scripts', 10, 3);

mepr-checkout-after-password-fields

Description

It is used on registration form below password fields

Parameters

$membership_id Number

Example

add_action('mepr-checkout-after-password-fields', 'mepr_content_after_password');
function mepr_content_after_password($membership_id) {
    // Put your content here
}

mepr-checkout-before-coupon-field

Description

It is used on registration form above coupon

Parameters

$membership_id Number

Example

Add website field before coupon field (it requires more code for saving)

function mepr_add_website_field($membership_id) {
  ?>
    <div class="mp-form-row mepr_website_field">
      <div class="mp-form-label">
        <label>Website:*</label>
    </div>
      <input type="text" name="mepr_website_field" id="mepr_website_field" class="mepr-form-input" value="<?php echo (isset($_POST['mepr_website_field']))?stripslashes($_POST['mepr_website_field']):''; ?>" />
    </div>
    <?php
}
add_action('mepr-before-coupon-field', 'mepr_add_website_field');

mepr-checkout-before-submit

Description

It is used on registration form above submit button

Parameters

$membership_id Number

Example

Integrates MemberPress with https://wordpress.org/plugins/invisible-recaptcha/

function add_invisible_recaptcha_mepr_signup($membership_ID) { ?>
    <div class="mp-form-row mepr_invisible_recaptcha">
        <?php do_action('google_invre_render_widget_action'); ?>
    </div>
<?php
}
add_action('mepr-checkout-before-submit', 'add_invisible_recaptcha_mepr_signup');

function validate_invisible_recaptcha_mepr_signup($errors) {
    $is_valid = apply_filters('google_invre_is_valid_request_filter', true);
    if(!$is_valid) {
        $errors[] = "Failed Captcha";
    }
    return $errors;
}
add_filter('mepr-validate-signup', 'validate_invisible_recaptcha_mepr_signup');

mepr-signup

Description

It is used for processing the signup form before the logic progresses on to 'the_content'

Parameters

$txn Transaction Object

Example

Activates UPME profiles when a user signs up via MemberPress

function mepr_upme_activate($txn) {
  update_user_meta($txn->user_id, 'upme_activation_status', 'ACTIVE');
  update_user_meta($txn->user_id, 'upme_approval_status', 'ACTIVE');
  update_user_meta($txn->user_id, 'upme_user_profile_status', 'ACTIVE');
  upme_update_user_cache($txn->user_id);
}
add_action('mepr-signup', 'mepr_upme_activate'); //Use this if you don't want to wait for completed payment

mepr-save-account

Description

It is used on saving of the main Account page on front-end

Parameters

$user User Object

Example

Save new display name on Account page

function mpdn_save_account($user) {
  $display_name = stripslashes($_POST['mepr_user_display_name']);
  $user->display_name = $display_name;
  $user->store();

  //Set the nickname to the display name also, why not?
  update_user_meta($user->ID, 'nickname', $display_name);
}
add_action('mepr-save-account', 'mpdn_save_account');

mepr-event-create

Description

Do things when a user becomes active on a membership, and when they become inactive on a membership

Parameters

$event Event Object

Example

function listen_to_mepr_events($event) {
  $obj = $event->get_data();
  //$obj might be a MeprTransaction object or a MeprSubscription object

  if(!($obj instanceof MeprTransaction) && !($obj instanceof MeprSubscription)) {
    return; // nothing here to do if we're not dealing with a txn or sub
  }

  $member = $obj->user();

  if($member->is_active_on_membership($obj)) {
    //member is active on membership
  }
  else {
    //member is no longer active on this membership
  }
}
add_action('mepr-event-create', 'listen_to_mepr_events');

mepr-event-login

Description

Remove State Field from MemberPress Signup Forms

Parameters

$event Event Object

Example

//Remove the State Field completely
function trim_down_address_fields($options) {
  foreach($options->address_fields as $i => $o) {
    if($o->field_key == 'mepr-address-state') {
      unset($options->address_fields[$i]);
    }
  }

  return $options;
}
add_filter('mepr_fetch_options', 'trim_down_address_fields');

//Add a fake state value to each user
function populate_state_field($event) {
  $user = $event->get_data();
  update_user_meta($user->ID, 'mepr-address-state', 'fake');
}
add_action('mepr-event-login', 'populate_state_field');

mepr-event-member-signup-completed

Description

Capture a new member signup. Only ever triggers once for each new member. Does not trigger for exising members who have subscribed to a Membership before. The user may not be logged in when this is called as it is triggered when a user is added over the REST API, and also when a user is added from the dashboard (MemberPress -> Members -> Add New)

Parameters

$event Event Object

Example

function mepr_capture_new_member_signup_completed($event) {
  $user = $event->get_data();
  $txn_data = json_decode($event->args);
  //Do what you need
}
add_action('mepr-event-member-signup-completed', 'mepr_capture_new_member_signup_completed');

mepr-event-transaction-completed

Description

Example

Capture first normal payment after trial period on MemberPress Transaction

Parameters

$event Event Object

function catch_first_payment_after_trial($event) {
  $transaction = $event->get_data();
  $subscription = $transaction->subscription();
  $is_first_real_payment = false;

  if($subscription !== false) {
    if($subscription->trial && $subscription->trial_amount <= 0.00 && $subscription->txn_count == 1) {
      $is_first_real_payment = true;
    }
    elseif($subscription->trial && $subscription->trial_amount > 0.00 && $subscription->txn_count == 2) {
      $is_first_real_payment = true;
    }
  }

  if($is_first_real_payment) {
    // This is the first real payment after a paid or free trial period
    // So do what you will in here
  }
}
add_action('mepr-event-transaction-completed', 'catch_first_payment_after_trial');

mepr-event-recurring-transaction-failed

Description

Capture a failed Transaction event

Parameters

$event Event Object

Example

function mepr_capture_failed_transaction($event) {
  $transaction = $event->get_data();
  $subscription = $transaction->subscription();
  $user = $transaction->user();
  //Do what you need
}
add_action('mepr-event-recurring-transaction-failed', 'mepr_capture_failed_transaction');

mepr-event-non-recurring-transaction-completed

Description

Capture a new One-Time Subscription created event

Parameters

$event Event Object

Example

function mepr_capture_new_one_time_sub($event) {
  $transaction = $event->get_data();
  $user = $transaction->user();
  //Do what you need
}
add_action('mepr-event-non-recurring-transaction-completed', 'mepr_capture_new_one_time_sub');

mepr-event-transaction-refunded

Description

Capture a refunded Transaction event

Parameters

$event Event Object

Example

function mepr_capture_refunded_transaction($event) {
  $transaction = $event->get_data();
  $subscription = $transaction->subscription(); //This may return false if it's a one-time transaction that was refunded
  $user = $transaction->user();
  //Do what you need
}
add_action('mepr-event-transaction-refunded', 'mepr_capture_refunded_transaction');

mepr-event-transaction-expired

Description

Capture a Transaction expired event

Parameters

$event Event Object

Example

function mepr_capture_expired_transaction($event) {
  //BE CAREFUL WITH THIS ONE
  //This could be a prior recurring transaction that has expired
  //So the user might still be active on the subscription with a new transaction
  //So you might check
  // - if the $subscription exists
  // - if so, then is $subscription->status = 'active' still
  // - if so, then it's possible the user is not really expired on it
  //   - to check this use the $user->is_already_subscribed_to($transaction->product_id) method
  $transaction = $event->get_data();
  $subscription = $transaction->subscription(); //This may return false if it's a one-time transaction that has expired
  $user = $transaction->user();
  //Do what you need
}
add_action('mepr-event-transaction-expired', 'mepr_capture_expired_transaction');

mepr-event-subscription-created

Description

Capture a new Recurring Subscription created event

Parameters

$event Event Object

Example

function mepr_capture_new_recurring_sub($event) {
  $subscription = $event->get_data();
  $user = $subscription->user();
  //Do what you need
}
add_action('mepr-event-subscription-created', 'mepr_capture_new_recurring_sub');

mepr-event-subscription-paused

Description

Capture a Recurring Subscription paused event

Parameters

$event Event Object

Example

function mepr_capture_paused_sub($event) {
  $subscription = $event->get_data();
  $user = $subscription->user();
  //Do what you need
}
add_action('mepr-event-subscription-paused', 'mepr_capture_paused_sub');

mepr-event-subscription-resumed

Description

Capture a Recurring Subscription resumed event

Parameters

$event Event Object

Example

function mepr_capture_resumed_sub($event) {
  $subscription = $event->get_data();
  $user = $subscription->user();
  //Do what you need
}
add_action('mepr-event-subscription-resumed', 'mepr_capture_resumed_sub');

mepr-event-subscription-stopped

Description

Capture a Recurring Subscription cancelled event (and detect who did it)

Parameters

$event Event Object

Example

function mepr_capture_stopped_sub($event) {
  $subscription = $event->get_data();
  $user = $subscription->user();

  if(is_user_logged_in()) {
    if(current_user_can('manage_options')) {
      //An admin cancelled this from the dashboard
    }
    else {
      //User cancelled from their account page or upgraded to a new plan
    }
  }
  else {
    //Cancelled from a gateway Webhook or IPN notification
    //Not really a way to tell why but it could have been an
    // - admin cancelling it at the gateway instead of in the dashboard
    // - or the gateway could have cancelled it because of too many failed payments
    // - or the gateway could have cancelled it because the max billing cycles was reached
    // - or in the case of PayPal a user might have cancelled their recurring profile from in their PayPal account
  }
}
add_action('mepr-event-subscription-stopped', 'mepr_capture_stopped_sub');

mepr-event-member-added

Description

Capture a signup (user completed step 1, but hasn't necessarily paid yet)

Parameters

$event Event Object

Example

function mepr_capture_new_member_added($event) {
  $user = $event->get_data();
  //Do what you need
}
add_action('mepr-event-member-added', 'mepr_capture_new_member_added');

mepr_subscription_transition_status

Description

Capture when the status of subscription is changed during signup or updating subscription

Parameters

$old_status String
$new_status String
$sub Subscription Object

Example

function mepr_subscription_transition_status_fn($old_status, $new_status, $sub) {
  // Do what you need
}
add_action('mepr_subscription_transition_status', 'mepr_subscription_transition_status_fn', 10, 3);

mepr-txn-transition-status

Description

Capture after transaction is done processing

Parameters

$old_status String
$new_status String
$txn Transaction Object

Example

function mepr_txn_transition_status_fn($old_status, $new_status, $txv) {
  // Do what you need
}
add_action('mepr-txn-transition-status', 'mepr_txn_transition_status_fn', 10, 3);

mepr-txn-status-complete

Description

Called after completed payment

Parameters

$event Transaction Object

Example

Activate UPME profile when a user signs up via MemberPress

function mepr_upme_activate($txn) {
  update_user_meta($txn->user_id, 'upme_activation_status', 'ACTIVE');
  update_user_meta($txn->user_id, 'upme_approval_status', 'ACTIVE');
  update_user_meta($txn->user_id, 'upme_user_profile_status', 'ACTIVE');
  upme_update_user_cache($txn->user_id);
}
add_action('mepr-txn-status-complete', 'mepr_upme_activate');

mepr-txn-store

Description

Called after transaction is done processing including the subscr txn_count

Parameters

$txn Transaction Object
$old_txn Transaction Object

Example

function mepr_txn_store_fn($txn, $old_txn) {
  // Do what you need
}
add_action('mepr-txn-store', 'mepr_txn_store_fn', 10, 2);

mepr-transaction-expired

Description

Called when transaction expires

Parameters

$txn Transaction Object
$status Boolean

Example

Show or hide UserPro profile based on subscription status

function mepr_sync_user_pro_visibility($txn, $status = false) {
  global $userpro;

  if(class_exists('MeprUser')) {
    $user = new MeprUser($txn->user_id);

    //Make sure it's a valid user still
    if(!isset($user->ID) || !$user->ID) { return; }

    $subs = $user->active_product_subscriptions();

    if(!empty($subs)) {
      $userpro->unblock_account($user->ID);
    }
    else {
      $userpro->block_account($user->ID);
    }
  }
}
add_action('mepr-txn-expired', 'mepr_sync_user_pro_visibility', 10, 2);

mepr-account-home-before-name

Description

Add content to the Home tab of the Account page before First Name field

Parameters

$user User Object

Example

function mepr_account_home_before_name($user) {
  // Do what you need
}
 add_action('mepr-account-home-before-name', 'mepr_account_home_before_name');

mepr-account-home-fields

Description

Add content to the Home tab of the Account page before Save Profile button

Parameters

$user User Object

Example

(it requires more code to function properly)

function mpdn_show_on_account($user) {
  ?>
    <div class="mp-form-row">
      <div class="mp-form-label">
        <label>Display Name Publically As:*<br/><small>Must be different than your username and email address</small></label>
      </div>
      <input type="text" name="mepr_user_display_name" id="mepr_user_display_name" class="mepr-form-input mepr-display-name" value="<?php echo $user->display_name; ?>" />
    </div>
    <?php
}
add_action('mepr-account-home-fields', 'mpdn_show_on_account');

mepr_account_home

Description

Add content at the end of the Home tab of the Account page

Parameters

$user User Object

Example

function mepr_account_home($user) {
  // Do what you need
}
 add_action('mepr_account_home', 'mepr_account_home');

mepr-admin-subscriptions-cell

Description

It is used to add column to Subscriptions page on admin side

Parameters

$column_name String
$rec Transaction Object
$table Subscription Table Object
$attributes String

Example

(it requires more code to function properly)

function mepr_add_admin_subscriptions_cell($column_name, $rec, $table, $attributes) {
  $user = new MeprUser($rec->user_id);

  if(strpos($column_name, '_site') !== false && (int)$user->ID > 0) {
    $website = 'None';
    $website_fields = get_user_meta($user->ID, 'mepr_custom_website_fields', true);

    if($website_fields) {
      foreach($website_fields as $f) {
        if(!$table->lifetime && $rec->ID == $f['sub_id']) {
          $website = $f['website'];
          break;
        }
        elseif($table->lifetime && $rec->ID == $f['txn_id']) {
          $website = $f['website'];
          break;
        }
      }
    } ?>
      <td <?php echo $attributes; ?>><?php echo $website; ?></td>
    <?php
  }
}
add_action('mepr-admin-subscriptions-cell', 'mepr_add_admin_subscriptions_cell', 10, 4);

mepr_account_nav

Description

It is used to add navigation item to the navigation of Account page

Parameters

$action String

Example

function mepr_add_some_tabs($action) {
  $support_active = (isset($_GET['action']) && $_GET['action'] == 'premium-support')?'mepr-active-nav-tab':'';
  ?>
    <span class="mepr-nav-item premium-support <?php echo $support_active; ?>">
      <a href="/account/?action=premium-support">Premium Support</a>
    </span>
    <?php
}
add_action('mepr_account_nav', 'mepr_add_some_tabs');

mepr_account_nav_content

Description

It is used to add the content to the new tab on the Account page

Parameters

$action String

Example

function mepr_add_tabs_content($action) {
  if($action == 'premium-support'): //Update this 'premium-support' to match what you put above (?action=premium-support)
  ?>
    <div id="custom-support-form">
      <form action="" method="post">
        <label for="subject">Enter Subject:</label><br/>
        <input type="text" name="subject" id="subject" />

        <br/><br/>

        <label for="content">Enter Content:</label><br/>
        <input type="text" name="content" id="content" />

        <br/><br/>

        <input type="submit" name="premium-support-submit" value="Submit" />
      </form>
    </div>
    <?php
  endif;
}
add_action('mepr_account_nav_content', 'mepr_add_tabs_content');

mepr-account-after-password-fields

Description

Add content to the Change password form of the Account page before Submit button

Parameters

$user User Object

Example

function mepr_account_after_password_fields($user) {
  // Add HTML code here
}
add_action('mepr-account-after-password-fields', 'mepr_account_after_password_fields');

mepr_account_password

Description

Add content at the end of the Change password form on the Account page

Parameters

$user User Object

Example

function mepr_account_password($user) {
  // Add HTML code here
}
add_action('mepr_account_password', 'mepr_account_password');

mepr_account_payments_table_header

Description

Add column at the end of the Payments tab of the Account page

Example

function mepr_account_payments_table_header() {
  ?>
  <th><?php _ex('Custom Info', 'ui', 'memberpress'); ?></th>
  <?php
}
add_action('mepr_account_payments_table_header', 'mepr_account_payments_table_header');

mepr_account_payments_table_row

Description

Add additional field at the end of the Payments tab of the Account page

Parameters

$txn Transaction Object

Example

function mepr_account_payments_table_row($txn) {
  // Do what you need
}
add_action('mepr_account_payments_table_row', 'mepr_account_payments_table_row');

mepr_account_payments

Description

Add content at the end of the Payments tab of the Account page

Parameters

$user User Object

Example

function mepr_account_payments($user) {
  // Do what you need
}
add_action('mepr_account_payments', 'mepr_account_payments');

mepr_before_account_subscriptions

Description

Add content at the beginning of the Subscriptions tab on the Account page

Parameters

$user User Object

Example

function mepr_before_account_subscriptions($user) {
  // Add HTML code here
}
add_action('mepr_before_account_subscriptions', 'mepr_before_account_subscriptions');

mepr-account-subscriptions-th

Description

It is used to display label in a new column in Subscriptions tab of the Account page

Example

(it requires more code to function properly)

function mepr_add_subscriptions_th($user, $subs) {
  ?>
    <th>Site</th>
    <?php
}
add_action('mepr-account-subscriptions-th', 'mepr_add_subscriptions_th', 10, 2);

mepr_account_subscriptions_sub_account_auto_rebill

Description

Add content to the Sub Account in the Subscription field of the Subscriptions tab on the Account page

Parameters

$txn Transaction Object

Example

function mepr_account_subscriptions_sub_account_auto_rebill_fn($txn) {
  // Add HTML code here
}
add_action('mepr_account_subscriptions_sub_account_auto_rebill', 'mepr_account_subscriptions_sub_account_auto_rebill_fn');

mepr_account_subscriptions_sub_account_terms

Description

Add content below the Subscription field of the Subscriptions tab on the Account page

Parameters

$txn Transaction Object

Example

function mepr_account_subscriptions_sub_account_terms_fn($txn) {
  // Add HTML code here
}
add_action('mepr_account_subscriptions_sub_account_terms', 'mepr_account_subscriptions_sub_account_terms_fn');

mepr-account-subscriptions-actions

Description

Add content below actions columns in the Subscriptions tab on the Account page

Parameters

$user User Object
$sub Subscription Object
$txn Transaction Object
$is_sub Boolean

Example

function mepr_account_subscriptions_actions($user, $sub, $txn, $is_sub) {
  // Add HTML code here
}
add_action('mepr-account-subscriptions-actions', 'mepr_account_subscriptions_actions', 10, 4);

mepr-account-subscriptions-td

Description

It is used to populate field in a new column in Subscriptions tab of the Account page

Example

(it requires more code to function properly)

function mepr_add_subscriptions_td($user, $sub, $txn, $is_recurring) {
  $website = 'None';
  $website_fields = get_user_meta($user->ID, 'mepr_custom_website_fields', true);

  if($website_fields) {
    foreach($website_fields as $f) {
      if($is_recurring && $sub->ID == $f['sub_id']) {
        $website = $f['website'];
        break;
      }
      elseif(!$is_recurring && $txn->id == $f['txn_id']) {
        $website = $f['website'];
        break;
      }
    }
  } ?>
    <td data-label="Website">
      <div class="mepr-account-website"><?php echo $website; ?></div>
    </td>
    <?php
}
add_action('mepr-account-subscriptions-td', 'mepr_add_subscriptions_td', 10, 4);

mepr-account-subscriptions-table

Description

Add row at the end of the Subscriptions table on the Account page

Parameters

$user User Object
$subscription Subscription Object

Example

function mepr_account_subscriptions_table($user, $subscription) {
  // Add HTML code here
}
add_action('mepr-account-subscriptions-table', 'mepr_account_subscriptions_table', 10, 2);

mepr_account_subscriptions

Description

Add content at the end of the Subscriptions tab on the Account page

Parameters

$user User Object

Example

function mepr_account_subscriptions($user) {
  // Add HTML code here
}
add_action('mepr_account_subscriptions', 'mepr_account_subscriptions');

mepr-login-form-before-submit

Description

Add content before Remember Me checkbox on the Login page

Example

function mepr_login_form_before_submit() {
  // Add HTML code here
}
add_action('mepr-login-form-before-submit', 'mepr_login_form_before_submit');

mepr-forgot-password-form

Description

Add content before Submit button on the Forgot Login Password page

Example

function mepr_forgot_password_form() {
  // Add HTML code here
}
add_action('mepr-forgot-password-form', 'mepr_forgot_password_form');

mepr-reset-password-after-password-fields

Description

Add content after Password field on the Reset Login Password page

Example

function mepr_reset_password_after_password_fields() {
  // Add HTML code here
}
add_action('mepr-reset-password-after-password-fields', 'mepr_reset_password_after_password_fields');

mepr-account-is-active

Description

Do what you need when new transaction comes and is active

Parameters

$txn Transaction Object

Example

function mepr_account_is_active($txn) {
  // Do what you need
}
add_action('mepr-account-is-active', 'mepr_account_is_active');

mepr-account-is-inactive

Description

Do what you need when new transaction comes and is inactive

Parameters

$txn Transaction Object

Example

function mepr_account_is_inactive($txn) {
  // Do what you need
}
add_action('mepr-account-is-inactive', 'mepr_account_is_inactive');

mepr_menu

Description

Add submenu after Analytics submenu in the Dashboard

Example

function mepr_menu_fn() {
  // Add HTML code here
}
add_action('mepr_menu', 'mepr_menu_fn');

mepr_enqueue_scripts

Description

Enqueue custom script on MemberPress front-end pages like Membership page, Group page or Account page

Parameters

$is_product_page Boolean
$is_group_page Boolean
$is_account_page Boolean

Example

function mepr_enqueue_scripts($is_product_page, $is_group_page, $is_account_page) {
  // Do what you need
}
add_action('mepr_enqueue_scripts', 'mepr_enqueue_scripts', 10, 3);

mepr_payment_failure

Description

Do what you need when payment fails and error comes up

Parameters

$txn Transaction Object

Example

function mepr_payment_failure_fn($txn) {
  // Do what you need
}
add_action('mepr_payment_failure', 'mepr_payment_failure_fn');

mepr-membership-meta-boxes

Description

Add meta box to the Membership

Parameters

$membership Membership Object

Example

function mepr_membership_meta_boxes_fn($membership) {
  // Do what you need
}
add_action('mepr-membership-meta-boxes', 'mepr_membership_meta_boxes_fn');

mepr-membership-save-meta

Description

Do what you need once membership is saving

Parameters

$txn Membership Object

Example

function mepr_membership_save_meta_fn($membership) {
  // Do what you need
}
add_action('mepr-membership-save-meta', 'mepr_membership_save_meta_fn');

mepr_members_list_table_row

Description

Display custom column in Members table

Parameters

$attributes String
$rec Object
$column_name String
$column_display_name String

Example

function mepr_members_list_table_row_fn($attributes, $rec, $column_name, $column_display_name) {
  // Display content
}
add_action('mepr_members_list_table_row', 'mepr_members_list_table_row_fn', 10, 4);

mepr-coupon-meta-boxes

Description

Add meta box to the Coupon edit page

Parameters

$coupon Coupon Object

Example

function mepr_coupon_meta_boxes_fn($coupon) {
  // Do what you need
}
add_action('mepr-coupon-meta-boxes', 'mepr_coupon_meta_boxes_fn');

mepr-coupon-save-meta

Description

Do what you need once coupon is saving

Parameters

$coupon Coupon Object

Example

function mepr_coupon_save_meta_fn($coupon) {
  // Do what you need
}
add_action('mepr-coupon-save-meta', 'mepr_coupon_save_meta_fn');

mepr-coupon-admin-enqueue-script

Description

Enqueue custom script on the Coupon edit page

Parameters

$hook String

Example

function mepr_coupon_admin_enqueue_script_fn($hook) {
  // Do what you need
}
add_action('mepr-coupon-admin-enqueue-script', 'mepr_coupon_admin_enqueue_script_fn');

mepr-pre-run-rule-content

Description

Add this filter to allow external resources to control whether to show or hide this content if the resource sets the filter to FALSE then it will not be protected
It is used inside the function to replace content for unauthorized visitors if redirect_on_unauthorized is not selected in MeprOptions.

Parameters

$value Boolean
$current_post WP_Post
$uri String

Example

Unprotect MemberPress posts if they have a certain category

add_filter('mepr-pre-run-rule-content', 'mepr_override_content_protection', 11, 3);
function mepr_override_content_protection($protect, $post, $uri) {
    if(has_category('category_slug_here', $post)) { $protect = false; }
    return $protect;
}

mepr-pre-run-rule-redirection

Description

Add this filter to allow external resources to control whether to redirect away from this content. If the resource sets the filter to FALSE then no redirect will occur
It is used inside the function to redirect unauthorized visitors if redirect_on_unauthorized is selected in MeprOptions or if we're protecting a WP controlled-URI

Parameters

$protect Boolean
$uri String   
$delim String

Example

Unprotect MemberPress posts if they have a certain category

add_filter('mepr-pre-run-rule-redirection', 'mepr_override_redirection_protection', 11, 3);
function mepr_override_redirection_protection($protect, $uri, $delim) {
    global $post; //$post - may not be availble here if not using "template_redirect" as the redirect action in MemberPress Options
    if(!isset($post) || !($post instanceof WP_Post)) { return $protect; }
    $user = MeprUtils::get_currentuserinfo();
    if($user === false) { return $protect; }

    $registration_date = strtotime(MeprUser::get_user_registration_date($user->ID)) - MeprUtils::months(1);
    $post_date = strtotime($post->post_date);
    $active_product_subscriptions = $user->active_product_subscriptions();
    if(!empty($active_product_subscriptions) && $post_date >= $registration_date) {
        return false; // Don't protect the content
    }
    return $protect;
}

mepr-last-chance-to-block-content

Description

The user is allowed to see this content, but it gives developers one last chance to block it if necessary. It will be very helpful for magazine style membership sites. It returns TRUE here to block the content from this user.
It is used inside the function to replace content for unauthorized visitors if redirect_on_unauthorized is not selected in MeprOptions.

Parameters

$value Boolean
$current_post WP_Post
$uri String

mepr-validate-signup

Description

It is used to validate signup fields

Parameters

$errors Array

Example

Limit Signups to USA only

function limit_signups_to_one_country($errors) {
  if(!isset($_POST['mepr-address-country']) || $_POST['mepr-address-country'] != 'US') {
    $errors[] = 'Sorry, signups are currently limited to USA only.';
  }

  return $errors;
}
add_filter('mepr-validate-signup', 'limit_signups_to_one_country');

mepr-validate-account

Description

It is used to validate fields on the Account page

Parameters

$errors Array
$user User object

Example

Validate Display Name field to MemberPresss account page

function mpdn_validate_on_account($errors, $user) {
  if(!isset($_POST['mepr_user_display_name']) || empty($_POST['mepr_user_display_name'])) {
    $errors[] = "You must enter a Public Display Name";
    return $errors;
  }

  $display_name = stripslashes($_POST['mepr_user_display_name']);
  $new_email    = stripslashes($_POST['user_email']);
  $old_email    = $user->user_email;
  $username     = $user->user_login;

  if($display_name == $new_email || $display_name == $old_email) {
    $errors[] = "Your Public Display Name cannot be the same as your Email Address";
  }
  if($display_name == $username) {
    $errors[] = "Your Public Display Name cannot be the same as your Username";
  }

  return $errors;
}
add_filter('mepr-validate-account', 'mpdn_validate_on_account', 11, 2);

mepr-signup-checkout-url

Description

It is used to change signup checkout URL

Parameters

$url String
$txn Transaction object

Example

function mepr_signup_checkout_url($url, $txn) {
  // Do what you need
  return $url;
}
add_filter('mepr-signup-checkout-url', 'mepr_signup_checkout_url', 11, 2);

mepr_fetch_options

Description

It is used to filter fetched MemberPress options

Parameters

$options MemberPress Options Object

Example

Remove the State Field completely (it requires more code to function properly)

function trim_down_address_fields($options) {
  foreach($options->address_fields as $i => $o) {
    if($o->field_key == 'mepr-address-state') {
      unset($options->address_fields[$i]);
    }
  }

  return $options;
}
add_filter('mepr_fetch_options', 'trim_down_address_fields');

mepr_checkout_show_terms

Description

Show price terms in the Signup form

Parameters

$show_price Boolean

Example

Hide price terms on Signup pages

function mepr_checkout_show_terms_fn($show_price) {
  return false;
}
add_filter('mepr_checkout_show_terms', 'mepr_checkout_show_terms_fn');

Description

It is used to change MemberPress Cancel URL in Actions column of the Accout page

Parameters

$html String
$sub Subscription object

Example

Hijack MemberPress Cancel URL (it requires more code to function properly)

function cspf_custom_cancel_link($html, $sub) {
  ob_start();
  ?>
    <a href="?action=upsell&sub=<?php echo $sub->id; ?>">Cancel</a>
    <?php
  return ob_get_clean();
}
add_action('mepr_custom_cancel_link', 'cspf_custom_cancel_link', 10, 2);

mepr-admin-members-cols

Description

It allows you to add a custom column to MemberPress → Members page.

Parameters

$cols Array

Example

function mepr_admin_members_cols($cols) {
  // Do what you need
  return $cols;
}
add_filter('mepr-admin-members-cols', 'mepr_admin_members_cols');

mepr-admin-subscriptions-cols

Description

Add column to the Admin site

Parameters

$cols Array
$prefix String
$lifetime String

Example

function mepr_add_admin_subscriptions_cols($cols, $prefix, $lifetime) {
  $cols[$prefix.'site'] = 'Site';
  return $cols;
}
 add_filter('mepr-admin-subscriptions-cols', 'mepr_add_admin_subscriptions_cols', 10, 3);

mepr_user_subscriptions_query_cols

Description

It is used to fetch additional columns from user's subscription

Parameters

$cols Array

Example

function mepr_user_subscriptions_query_cols($cols) {
  //Do what you need
  return $cols;
}
add_filter('mepr_user_subscriptions_query_cols', 'mepr_user_subscriptions_query_cols');

mepr_nonrecurring_subscriptions_table_joins

Description

It is used to modify join query to fetch from non-recurring subscriptions table

Parameters

$joins Array

Example

function mepr_nonrecurring_subscriptions_table_joins($joins) {
  //Do what you need
  return $joins;
}
add_filter('mepr_nonrecurring_subscriptions_table_joins', 'mepr_nonrecurring_subscriptions_table_joins');

mepr_nonrecurring_subscriptions_table_cols

Description

It is used to modify columns fetched from non-recurring subscriptions table

Parameters

$cols Array

Example

function mepr_nonrecurring_subscriptions_table_cols($cols) {
  //Do what you need
  return $cols;
}
add_filter('mepr_nonrecurring_subscriptions_table_cols', 'mepr_nonrecurring_subscriptions_table_cols');

mepr_recurring_subscriptions_table_joins

Description

It is used to modify join query to fetch from recurring subscriptions table

Parameters

$joins Array

Example

function mepr_recurring_subscriptions_table_joins($joins) {
  //Do what you need
  return $joins;
}
add_filter('mepr_recurring_subscriptions_table_joins', 'mepr_recurring_subscriptions_table_joins');

mepr_recurring_subscriptions_table_cols

Description

It is used to modify columns fetched from subscriptions table

Parameters

$cols Array

Example

function mepr_recurring_subscriptions_table_cols($cols) {
  //Do what you need
  return $cols;
}
add_filter('mepr_recurring_subscriptions_table_cols', 'mepr_recurring_subscriptions_table_cols');

mepr_import_subscription_pre_store

Description

It is used to modify subscription in Importer before it is stored

Parameters

$sub Subscription object

Example

function mepr_import_subscription_pre_store($sub_id) {
  //Do what you need
}
add_filter('mepr_import_subscription_pre_store', 'mepr_import_subscription_pre_store');

mepr_import_subscription_post_store

Description

It is used to modify subscription in Importer after it is stored

Parameters

$sub_id Integer

Example

function mepr_import_subscription_post_store($sub_id) {
  //Do what you need
}
add_filter('mepr_import_subscription_post_store', 'mepr_import_subscription_post_store');

mepr_user_subscriptions_customize_subscription

Description

It is used to filter through the subscriptions. It is called inside foreach loop.

Parameters

$sub Subscription or Transaction object
$row Subscription for each item in the loop
$user User object

Example

function mepr_customize_subscription($sub, $row, $user) {
  //Do what you need
}
add_filter('mepr_user_subscriptions_customize_subscription', 'mepr_customize_subscription', 10, 3);

mepr-account-welcome-message

Description

Change welcome message on the Account page

Parameters

$message String
$user User Object

Example

function mepr_account_welcome_message($message, $user) {
  // Do what you need
  return message;
}
 add_filter('mepr-account-welcome-message', 'mepr_account_welcome_message', 10, 2);

mepr-user-message

Description

Change user message on the Account page

Parameters

$message String
$user User Object

Example

function mepr_account_user_message($message, $user) {
  // Do what you need
  return message;
}
add_filter('mepr-user-message', 'mepr_account_user_message');

Description

Change the link of the Home tab of the Account page

Example

function mepr_account_nav_home_link() {
  // Return your link
}
 add_filter('mepr-account-nav-home-link', 'mepr_account_nav_home_link');

Description

Change the link of the Subscriptions tab of the Account page

Example

function mepr_account_nav_subscriptions_link() {
  // Return your link
}
 add_filter('mepr-account-nav-subscriptions-link', 'mepr_account_nav_subscriptions_link');

Description

Change the link of the Payments tab of the Account page

Example

function mepr_account_nav_payments_link() {
  // Return your link
}
 add_filter('mepr-account-nav-payments-link', 'mepr_account_nav_payments_link');

mepr-account-nav-home-label

Description

Change the label of the Subscriptions tab of the Account page

Example

function mepr_account_nav_home_label() {
  // Return a new label
}
 add_filter('mepr-account-nav-home-label', 'mepr_account_nav_home_label');

mepr-account-nav-subscriptions-label

Description

Change the label of the Subscriptions tab of the Account page and the Subscriptions label in the message that appears on this page if there are any issues with user subscriptions

Example

function mepr_account_nav_subscriptions_label() {
  // Return a new label
}
 add_filter('mepr-account-nav-subscriptions-label', 'mepr_account_nav_subscriptions_label');

mepr-account-nav-payments-label

Description

Change the label of the Payments tab of the Account page

Example

function mepr_account_nav_payments_label() {
  // Return a new label
}
 add_filter('mepr-account-nav-payments-label', 'mepr_account_nav_payments_label');

mepr-account-payment-product-name

Description

Change Membersip Title in the Membership column. It is in the Payments tab of the Account page

Parameters

$membership_title String
$txn Transaction Object

Example

function mepr_account_payment_product_name($membership_title, $txn) {
  // Do what you need
  return $membership_title;
}
add_filter('mepr-account-payment-product-name', 'mepr_account_payment_product_name');

mepr-account-subscr-product-name

Description

Change Membersip Title in the Membership column. It is in the Subscriptions tab of the Account page

Parameters

$membership_title String
$txn Transaction Object

Example

function mepr_account_subscr_product_name($membership_title, $txn) {
  // Do what you need
  return $membership_title;
}
add_filter('mepr-account-subscr-product-name', 'mepr_account_subscr_product_name');

mepr-login-redirect-url

Description

Change URL to redirect member after login. This redirect will be overwritten with per membership redirect URL settings

Parameters

$url String

Example

function mepr_login_redirect_url($url) {
  // Do what you need
  return $url;
}
add_filter('mepr-login-redirect-url', 'mepr_login_redirect_url');

mepr-process-login-redirect-url

Description

Change URL to redirect member after login. It replaces global and per membership Login URL settings

Parameters

$url String
$user User Object

Example

Redirect member to URL after login

function mepr_process_login_redirect_url_fn($url, $user) {
  $roles = $user->roles;
  if($roles && false !== array_search('author', $roles)) {
    $url = 'https://your_domain.com';
  }
  return $url;
}
add_filter('mepr-process-login-redirect-url', 'mepr_process_login_redirect_url_fn');

mepr-login-uname-or-email-str

Description

Change Username or E-mail label on the Login page that is displaying when "Members must use their email address for their Username" option is enabled

Example

function mepr_login_uname_or_email_str() {
  return 'New Username or E-mail Label';
}
add_filter('mepr-login-uname-or-email-str', 'mepr_login_uname_or_email_str');

mepr-login-uname-str

Description

Change Username label on the Login page

Example

function mepr_login_uname_str() {
  return 'New Username Label';
}
add_filter('mepr-login-uname-str', 'mepr_login_uname_str');

Description

Change Login link text in unauthorized message

Example

function mepr-unauthorized-login-link-text() {
  return 'New Login Link';
}
add_filter('mepr-unauthorized-login-link-text', 'mepr-unauthorized-login-link-text');

mepr-active-nav-tab

Description

Change navigation class of tabs on the Account page

Parameters

$class String
$tab String
$active_class String

Example

function mepr_active_nav_tab($class, $tab, $active_class) {
  // Do what you need
  return $class;
}
add_filter('mepr-active-nav-tab', 'mepr_active_nav_tab', 10, 3);

Description

Add content after Change Plan of Subscriptions tab of the Account page

Parameters

$html String
$txn Transaction Object

Example

function mepr_custom_upgrade_link_txn_fn($html, $txn) {
  // Do what you need
  return $html;
}
add_filter('mepr_custom_upgrade_link_txn', 'mepr_custom_upgrade_link_txn_fn', 10, 2);

mepr-currency-symbols

Description

Change the list of "Currency Symbol" in the MemberPress General settings

Parameters

$codes Array

Example

function mepr_currency_symbols($codes) {
  $new_code = array('৳');
  array_splice( $codes, 4, 0, $new_code );
  return $codes;
}
add_filter('mepr-currency-symbols', 'mepr_currency_symbols');

mepr-currency-codes

Description

Change the list of "Currency Code" in the MemberPress General settings

Parameters

$codes Array

Example

function mepr_currency_codes($codes) {
  $new_code = array('BDT');
  array_splice( $codes, 4, 0, $new_code );
  return $codes;
}
add_filter('mepr-currency-codes', 'mepr_currency_codes');

mepr-language-codes

Description

Change the list of "Language Code" in the MemberPress General settings

Parameters

$codes Array

Example

function mepr_language_codes($codes) {
  $new_code = array('BN');
  array_splice( $codes, 4, 0, $new_code );
  return $codes;
}
add_filter('mepr-language-codes', 'mepr_language_codes');

mepr_countries

Description

Change the list of countries in the singup page

Parameters

$countries Array
$prioritize_my_country Boolean

Example

Leave Germany as the only country in the dropdown list on the signup page

function mepr_countries_fn($countries, $prioritize_my_country) {
  return array(
    'DE' => _x('Germany', 'ui', 'memberpress')
  );
}
add_filter('mepr_countries', 'mepr_countries_fn');

mepr_render_custom_fields

Description

Re-order custom fields on the signup page

Parameters

$custom_fields Array

Example

function moveElement(&$array, $a, $b) {
  $out = array_splice($array, $a, 1);
  array_splice($array, $b, 0, $out);
}
function mepr_render_custom_fields_fn($custom_fields) {
  moveElement($custom_fields, 5, 2);
  return $custom_fields;
}
add_filter('mepr_render_custom_fields', 'mepr_render_custom_fields_fn');

mepr-jobs-config

Description

Change default WP Cron job configuration object

Parameters

$config Object

Example

function mepr_jobs_config($config) {
  $config['worker']['interval'] = MeprUtils::minutes(30);
  return (object)$config;
}
add_filter('mepr-jobs-config', 'mepr_jobs_config');

mepr-admin-capability

Description

Change default MemberPress capability to display MemberPress menu items

Parameters

$cap String

Example

function mepr_admin_capability($cap) {
  // Do what you need
  return $cap;
}
add_filter('mepr-admin-capability', 'mepr_admin_capability');

mepr_price_box_benefit

Description

Change item in the list of Group benefits

Parameters

$element String
$index Number

Example

function mepr_price_box_benefit_fn($element, $index) {
  // Do what you need
  return $element;
}
add_filter('mepr_price_box_benefit', 'mepr_price_box_benefit_fn', 10, 2);

mepr-group-css-classes-string

Description

Change class of the Group price box

Parameters

$classes String
$product Membership Object
$group Group Object
$preview Boolean

Example

function mepr_group_css_classes_string($classes, $product, $group, $preview) {
  // Do what you need
  return $classes;
}
add_filter('mepr-group-css-classes-string', 'mepr_group_css_classes_string', 10, 4);

mepr-group-page-item-output

Description

Change the Group box item

Parameters

$output String
$product Membership Object
$group Group Object
$preview Boolean

Example

function mepr_group_page_item_output($output, $product, $group, $preview) {
  // Do what you need
  return $output;
}
add_filter('mepr-group-page-item-output', 'mepr_group_page_item_output', 10, 4);

mepr_custom_thankyou_message

Description

Change custom Thank You page message

Parameters

$message String

Example

function mepr_custom_thankyou_message_fn($message) {
  // Do what you need
  return $message;
}
add_filter('mepr_custom_thankyou_message', 'mepr_custom_thankyou_message_fn');

mepr-wp-mail-recipients

Description

Change email recipients

Parameters

$recipients Array
$subject String
$message String
$headers Array

Example

function mepr_wp_mail_recipients($recipients, $subject, $message, $headers) {
  // Do what you need
  return $recipients;
}
add_filter('mepr-wp-mail-recipients', 'mepr_wp_mail_recipients', 10, 4);

mepr-wp-mail-subject

Description

Change email subject

Parameters

$subject String
$recipients Array
$message String
$headers Array

Example

function mepr_wp_mail_subject($subject, $recipients, $message, $headers) {
  // Do what you need
  return $subject;
}
add_filter('mepr-wp-mail-subject', 'mepr_wp_mail_subject', 10, 4);

mepr-wp-mail-message

Description

Change email message

Parameters

$message String
$recipients Array
$subject String
$headers Array

Example

function mepr_wp_mail_message($message, $recipients, $subject, $headers) {
  // Do what you need
  return $message;
}
add_filter('mepr-wp-mail-message', 'mepr_wp_mail_message', 10, 4);

mepr-wp-mail-headers

Description

Change email header

Parameters

$headers Array
$recipients Array
$subject String
$message String
$attachments Array

Example

Add CC to all emails

function mepr_wp_mail_headers($headers, $recipients, $subject, $message, $attachments) {
  $cc_email = sanitize_email('[email protected]');
  $headers[] = 'Cc: ' . $cc_email;
  return $headers;
}
add_filter('mepr-wp-mail-headers', 'mepr_wp_mail_headers', 10, 5);
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.