functions php if admin not visible

Solutions on MaxInterview for functions php if admin not visible by the best coders in the world

showing results for - "functions php if admin not visible"
Vincenzo
09 Sep 2018
1Removing the Admin Bar for Non-Admins
2Removing the admin bar is a simple code snippet. I’ve shown before how you can hide the admin bar conditionally for users. In there I’ve not mentioned how you can hide it for everyone but admins, so thats where this code snippet comes in;
3
4<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
5
6/**
7 * Hide admin bar for non-admins
8 */
9function js_hide_admin_bar( $show ) {
10	if ( ! current_user_can( 'administrator' ) ) {
11		return false;
12	}
13
14	return $show;
15}
16add_filter( 'show_admin_bar', 'js_hide_admin_bar' );
17view rawhide-admin-bar-non-admin-wordpress.php hosted with ❤ by GitHub
18 
19
20Block Dashboard Access for Non-Admins
21The best way to handle someone trying to access the dashboard is to redirect them to another page. You can consider redirecting them back to the primary landing page of your site, their front-end profile (if there’s any) or just redirect them back to the page they came from.
22
23<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
24
25/**
26 * Block wp-admin access for non-admins
27 */
28function ace_block_wp_admin() {
29	if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
30		wp_safe_redirect( home_url() );
31		exit;
32	}
33}
34add_action( 'admin_init', 'ace_block_wp_admin' );
35view rawblock-dashboard-access-non-admins.php hosted with ❤ by GitHub
36You can change the home_url() to something else if you want to redirect them somewhere else. For example, to redirect them to the shop page you can use home_url( '/shop' ) or if you have a profile page home_url( '/profile' ).
37
38 
39
40Redirecting users after login
41A quick sample to redirect user after theyve logged into your site;
42
43<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
44
45/**
46 * Redirect users after login
47 */
48function js_login_redirect( $url ) {
49    return home_url( '/profile' );
50}
51add_filter( 'login_redirect', 'js_login_redirect' );
52view rawlogin-redirect-wordpress.php hosted with ❤ by GitHub
53Redirecting users after logout
54Same as the above, you can also use it for the logout redirect;
55
56<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
57
58/**
59 * Redirect users after logout
60 */
61function js_logout_redirect( $url ) {
62    return home_url( '/profile' );
63}
64add_filter( 'logout_redirect', 'js_logout_redirect' );
65view rawlogout-redirect-url-wordpress.php hosted with ❤ by GitHub