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 executes 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: Payment for 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. 


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.