AI Verified

Name

Redirect user role on specific page

About

This code will redirect a specific page based on the user role NOT being met.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Drop the snippet in to your functions file and change the 'page-slug' to the page slug you want to redirect roles from and change the 'role_type' to your desired role.Finally change "https://www.secretstates.com" to the URL you wish to redirect to. NOTE the 'administrator' is added so the administrator can still view the page.

Codevault

Thrive

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

05/12/2022

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Redirect user role on specific page

 
                    
1function nonWholesaleRedirect() {
2 if (is_page( 'page-slug' )) {
3 if( !current_user_can( 'role_type' || 'administrator' ) ) {
4 wp_redirect( "https://www.secretstates.com", 301 );
5 }
6 }
7}
8add_action('wp', 'nonWholesaleRedirect');
9 
10?>

0

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

2

Disable admin notices by text string

Added: 1 year ago

Last Updated: 1 year ago

In $forbidden_message_strings array, provide a list of keywords or phrases that you want to disable. Provide a longer phrase to increase specificity

WordPress Admin

AI Verified

0

CLOUD Meister: Hide PlugIns from List

Added: 1 year ago

Last Updated: 1 year ago

WordPress Admin

AI Verified

0

Display snippet line numbers

Added: 1 year ago

Last Updated: 1 year ago

Based on work by platypus424 and germankiwi, this snippet will allow you to see code on a particular line number from all of your snippets, allowing you to track down exactly where an error might be o...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

0

Redirect user role on specific page

Added: 1 year ago

Last Updated: 1 year ago

This code will redirect a specific page based on the user role NOT being met.

WordPress Admin

AI Verified

0

Redirect by page ID

Added: 1 year ago

Last Updated: 1 year ago

Wordpress function to redirect one page id to another page id

WooCommerce

AI Verified

0

Redirect product category to page ID

Added: 1 year ago

Last Updated: 1 year ago

Redirect a product category to a page ID