How to protect content from public users and limit access to certain roles in WordPress 2023?
How to protect content from public users and limit access to certain roles in WordPress 2023?
How to protect content from public users and limit access to certain roles in WordPress 2023?
Any way to set user role permissions in the site editor?
function dashboard_redirect($url, $request, $user) { if (in_array(‘test_user_role’, (array) $user->roles)) { $url = admin_url(‘users.php’); }else{ $url = admin_url(‘index.php’); } return $url; } add_filter(‘login_redirect’, ‘dashboard_redirect’, 10, 3); The user can be passed into your function with a little more argument specificity.
How to redirect non admin user after login
As mentioned by Jacob Peattie: functions not loaded yet. You will need to use hooks/actions (init, wp etc) https://codex.wordpress.org/Plugin_API/Action_Reference e.g. function callMyMethod(){ $userLoggedIn = is_user_logged_in(); echo ‘INIT Action: User Logged in: ‘.var_export($userLoggedIn, true); if ( is_admin() ) { $canAccess = user_can_access_admin_page(); } } add_action(‘init’,’callMyMethod’); This answer is assuming you’re creating a plugin and calling the … Read more
Add the following code snippet to your WordPress theme’s functions.php file. Define the new user role and capabilities (you can customize this based on your needs) function add_custom_roles() { add_role( ‘corporate_customer’, ‘Corporate Customer’, array( ‘read’ => true, ‘edit_posts’ => true, ‘delete_posts’ => false, )); } add_action( ‘init’, ‘add_custom_roles’ ); A function to update the user … Read more
What is the difference between unmoderated and unapproved users?
Custom User Role not working
sorry but do not have enough reputation on stackoverflow to add a comment under yours. So my reply then here. I can list all my plugins but how I should reproduce it, because it happens randomly. And how should I put a error_log() in each function? I do not have the “Autorizer” so this should … Read more
Based on what you wrote, you should use instead : if ( ! is_admin() ) { function get_user_role() { global $wp_roles; $user = wp_get_current_user(); $roles = ( array ) $user->roles; foreach ( $roles as $role ) { $user_role=”<p>” . $wp_roles->roles[ $role ][‘name’] . ‘</p>’; } return $user_role; } add_shortcode( ‘display_user_role’, ‘get_user_role’ ); } It works … Read more