Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MarkKevin08/b62324bf0f9060f62e6e0b49eaa79f7b to your computer and use it in GitHub Desktop.
Save MarkKevin08/b62324bf0f9060f62e6e0b49eaa79f7b to your computer and use it in GitHub Desktop.
WPUM Content Restriction Redirection sample
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