Home / Disable / MemberPress: Disable the Unauthorized Redirection for Multiple Pages And/or Posts
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Disable the Unauthorized Redirection for Multiple Pages And/or Posts

Adding this code snippet will prevent unauthorized users from being redirected away from specific pages if the Redirect unauthorized visitors to a specific URL option is enabled at Dashboard > MemberPress > Settings > Pages.

Instead, users will see the unauthorized message set by the MemberPress rule protecting these pages.

The dummy post IDs 123, 456, and 789 within the code need to be replaced with IDs of all posts and pages for which the redirection should be disabled. The code needs to be adjusted by changing the post or page IDs on the following line:

if(in_array($post->ID, array( 123, 456, 789 ) ) ) {

More information about using this code can be found here: https://memberpress.com/docs/add-unauthorized-redirection-exclusions/

Code Preview
php
<?php
function mepr_stop_unauthorized_redirect( $redirect, $url, $delim ) {
	global $post;
	if(in_array($post->ID, array( 123, 456, 789 ) ) ) {
		$redirect = false;		
	}
	return $redirect;
}
add_filter( 'mepr-pre-run-rule-redirection', 'mepr_stop_unauthorized_redirect', 10, 3 );

Comments

Add a Comment