Home / Disable / MemberPress: Disable Unauthorized Redirection on a Specific Page or Post
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Disable Unauthorized Redirection on a Specific Page or Post

Adding this code snippet will prevent unauthorized users from being redirected away from the specific page 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 this page.

The dummy page ID 123 within the code needs to be replaced with the ID of the page or post for which the redirection should be disabled. The code needs to be adjusted by changing the page or post ID on the following line:

if( $post->ID === 123 ) {

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( $post->ID === 123 ) {
    $redirect = false;
  }
  return $redirect;
}
add_filter( 'mepr-pre-run-rule-redirection', 'mepr_stop_unauthorized_redirect', 10, 3) ;

Comments

Add a Comment