Filters are functions that WordPress passes data through, at certain points in execution, just before taking some action with the data. MemberMouse defines its own set of filters that you can utilize to control the flow of execution in MemberMouse prior to certain actions being taken.


Here's a basic example:



function customContentProtection($data) 

{

return true;

}

add_filter('mm_bypass_content_protection', 'customContentProtection');



In this example, we're using the add_filter() method to indicate that the customContentProtection() method should be called when MemberMouse applies the mm_bypass_content_protection filter. To learn more about working with WordPress' Action API read this article.



MemberMouse Filter Reference


The following is a list of all of the MemberMouse filters, a description of when they're executed and what data will be passed to any function hooked into the filter.


mm_block_access


 

This filter is applied after MemberMouse has determined the current visitor has access to the content. Return true to indicate that MemberMouse should block access. Return false to indicate that MemberMouse should allow access.


 

The value passed to your function is what  MemberMouse will currently do if your function doesn't return anything.



 

mm_bypass_content_protection


 

This filter is applied after MemberMouse has determined the current visitor doesn't have access to the content and is now determining whether the current visitor should be able to view the requested content or not. Return true to indicate that MemberMouse should bypass its internal content protection and allow the visitor to view the content. Return false to indicate that MemberMouse should use its own internal rules for determining if the visitor should be able to access the content.


 

The value passed to your function is what  MemberMouse will currently do if your function doesn't return anything.




mm_login_redirect


 

This filter is applied prior to MemberMouse executing its default login redirect behavior which is configured in Member Homepage Settings. Return a URL to indicate that MemberMouse should redirect the user to that URL. Return an empty string to indicate that MemberMouse should use its own internal rules for determining where the user should be sent.


 

The object passed to your function contains the URL MemberMouse will redirect the user to if you don't return an override URL and a user object containing data about the logged in user.
If the name of the object in your function is $infoObj then you'll access the two data elements as follows:
$infoObj->currentUrl
$infoObj->user



 

mm_stripe_billing_statement_descriptor


 

This filter is applied right before MemberMouse is going to send a charge to Stripe. Along with this charge request MemberMouse passes some information about the order such as: Order# 1012. This meta data will be displayed within Stripe when reviewing the charge. Using this filter gives you the opportunity to customize what's sent to Stripe. 


The limit for the number of characters that can be passed in the descriptor is 22. Anything exceeding 22 characters will be truncated.


There will be two parameters passed to your function. The first, $descriptor, contains the current information MemberMouse will send unless modified. The second, $order, is a standard class object that contains data in relation to the order placed in MemberMouse.  The $order object is what you'll use to pass the data you want to Stripe. 


 

Here's an example:  



 add_filter('mm_stripe_billing_statement_descriptor', function($descriptor, $order
{ return "Order #: ".$order->orderNumber.", Price: ".$order->total; }, 1, 2);


In this case you'll see something like the following in Stripe: 

Order #: 10043, Price: 97.00


 

Here's another example where we're setting the custom description to include order number and the product description:


add_filter('mm_stripe_billing_statement_descriptor', function($descriptor, $order){
 $descriptor = "Order # ".$order->orderNumber;
 if(isset($order->orderProducts) && is_array($order->orderProducts)){
 $descriptor .= ", Description: ".array_pop($order->orderProducts)->description;
 }
 return $descriptor;
},1,2);



In this case you'll see something like the following in Stripe: 

Order #: 10043, Description: Basic Membership


To see all the data that's possible to access on the $order object, view this sample order object.




Default MemberMouse Filters


These are filters that are included in the plugin that can be overridden in your custom code using remove_filter to implement your own related filters. 


Available 2.2.9+


mm_password_strength_validator 


As of version 2.2.9, MemberMouse supports the addition of a custom password validation filter. This allows the password to be evaluated based on custom requirements. By default MemberMouse attaches a basic filter that checks to ensure the password is at least 8 characters. Developers have the option to add an additional filter that will be applied in conjunction with the default, or remove the default and replace it with a custom filter.


The example below shows the steps to remove the default filter and replace it with a custom filter. This can be added into the theme's function.php file, but we recommended that if you take this route, you use a Child Theme to avoid your code being lost in the event of a theme update. 


//remove the default filter 


remove_filter('mm_password_strength_validator',array('MM_UserHooks',"passwordStrengthValidator"));


//add a filter that enforces that passwords are at least 8 characters and contain an uppercase letter, a number, and a special character 


add_filter('mm_password_strength_validator',function($passwordData) {     
     if (is_object($passwordData) && isset($passwordData->data) && !preg_match('/^(?=.*[!@#$%^&*-])(?=.*[0-9])(?=.*[A-Z]).{8,20}$/',$passwordData->data))   
     {           
          $passwordData->type = "error";           
          $passwordData->errors[] = "Password must contain an uppercase character, a special character, and a number";     }     
return $passwordData; },10,1);