Home / Archive / MemberPress: Auto Approve Sub-Accounts with New User Approve Plugin
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Auto Approve Sub-Accounts with New User Approve Plugin

This code snippet can be used if the New User Approve plugin is set on the website to approve users before they are allowed to log in.

This verification step is also required on the sub-account registration when the MemberPress Corporate Accounts is used on the website.

By adding the code snippet, the verification step will be skipped for sub-accounts, resulting in the automatic approval of sub-account users. The code specifies the corporate memberships that should be affected by this code snippet.

The code should be adjusted by replacing the dummy array of membership IDs (123, 456, 789) with the array of the actual membership IDs on this line:

Code Preview
php
<?php
function mepr_newuser_approve_override($user_id) {
  // Define an array of membership IDs for which the verification step should be skipped.
  $auto_approve = array(123, 456, 789); 
  
  if(!class_exists('MeprOptions')) { 
    return; 
  }
  
  if(!isset($_POST['mepr_product_id']) && !isset($_POST['manage_sub_accounts_form'])) { 
    return $user_id; 
  }
  
  $product_id = isset($_POST['mepr_product_id'])?$_POST['mepr_product_id']:false;
  
  if(isset($_POST['manage_sub_accounts_form']) || ($product_id && in_array($product_id, $auto_approve))) {
    $_REQUEST['action'] = 'createuser';
  }
}
add_filter('user_register', 'mepr_newuser_approve_override', 8);

Comments

Add a Comment