Skip to content

The Digi Life

Learning Life

  • Home
  • WP-Plugins
    • WordPress SMS Plugin – WP-SendSMS
  • Opencart Extensions
    • Simple Age Verification PopUp
    • Shopping cart in Pop Up and Buy Now Button
    • Auto Add Reward Points
    • Options Mouse Hover ToolTip Help
    • Category Carousel of Product
    • Show Reward Points of Customer In Header
  • Hire Developer..!

Recent Posts

  • SOLID Principles in PHP
  • Repository pattern in PHP and its use cases
  • Setup Docker on your PHP, MySql and Ngnix web application
  • Building Web Applications with PHP Frameworks and Libraries
  • Exploring Advanced Concepts in PHP: Multithreading, Event-Driven Programming, and Functional Programming | PHP Beginner to Advance

Categories

  • Android
  • Business
  • C Programming
  • C Programs Example
  • CMS
  • Javascript
  • Linux
  • MySQL
  • Netbeans
  • Opencart
  • PHP
  • PHP Beginner to advance
  • SEO
  • Teamsite
  • Ubuntu
  • Wordpress

Subscribe

Please Subscribe Here to Get Updates


 

WordPress Redirect User to Custom Page based on User Role

Now a days many Websites and Web application are using WordPress as their back-end. With increasing users of WordPress requires many more functionality to implement. Many Web Application / Websites requires to redirect users based on User’s role to particular or custom page.

Today Here I will let you know how can we implement to redirect user by user’s role in your WordPress Website. We will use hook “wp_login” and add one function to check current user role and then based on role we will redirect the user to predefined page (Custom Page).

To implement this you need to create one plugin and add below code to that

<?php 
/*
Plugin Name: My Login Redirect By Role
Plugin URI:
Description: Redirects users based on their role
Version: 1.0
Author: TheDigiLife
Author URI: http://thedigilife.com
License: GPLv2 or later

*/

add_action('wp_login','my_redirect_user_by_role', 10, 3);
function my_redirect_user_by_role($user_login, $user)
{		
	global $user;
	echo $role_name      = $user->roles[0];	
	// redirection for subscriber 
	if ( 'subscriber' === $role_name ) {
		wp_redirect( 'http://localhost/wordpress/?p=39');
		exit;
	} 
	// redirect for editor
	if ( 'editor' === $role_name ) {
		wp_redirect('http://yourdomain.com/path/to/page-post');				
		exit;
	} 
	// you can add more roles if conditions here
	wp_redirect( 'http://yourdomain.com/path/to/page-post');
	exit;
}

exit is used after wp-redirect so that it will not be overridden.

Please add your comment and queries below.

 

 

Posted on November 18, 2013Author TheDigiLifeCategories PHP, WordpressTags Login Redirect, PHP, WordPress, WP Login

Post navigation

Previous Previous post: Faceted Search (Layered Search) on MySQL database with example.
Next Next post: WordPress – Add Retina Image Support to Your Theme
Proudly powered by WordPress