Created
January 2, 2024 07:11
-
-
Save MarkKevin08/b62324bf0f9060f62e6e0b49eaa79f7b to your computer and use it in GitHub Desktop.
WPUM Content Restriction Redirection sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function restrict_access_for_specific_page() { | |
// Specify the page ID where you want to apply the restriction | |
$restricted_page_id = 123; // Replace 123 with the actual page ID | |
// Check if the current page is the restricted page | |
if (is_page($restricted_page_id)) { | |
// Specify the URL that users must come from to access the page | |
$allowed_url = 'https://example.com/allowed-url'; | |
// Get the referring URL | |
$referring_url = wp_get_referer(); | |
// Check if the referring URL matches the allowed URL | |
if ($referring_url !== $allowed_url) { | |
// Redirect users to another page if they come from an unauthorized source | |
wp_redirect(home_url('/unauthorized-page')); | |
exit; | |
} | |
} | |
} | |
add_action('template_redirect', 'restrict_access_for_specific_page'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment