Wordpress Different User, Different CSS How ???

Meenakshi Sandle

Active member
Banned User
Apr 9, 2020
162
38
28
31
Chandigarh
www.trendingmantra.com
@Meenakshi Sandle my approach for this is refer to user id that is unique not admin role. WP has core function for this : wp_get_current_user()->ID = 1 (e.g. you want to catch user that has id of 1)
Let say you are user 1, to hide something in backend to others you have to declare
wp_get_current_user()->ID != 1 and use WP hook as 'admin_menu' :

Code:
 function remove_menus(){

if ( wp_get_current_user()->ID != 1 ) {
remove_menu_page( 'index.php' );
remove_menu_page( 'tools.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'edit.php?post_type=page' );
remove_menu_page( 'wpcf7' );
remove_menu_page( 'woocommerce' );
remove_menu_page('edit.php');
remove_menu_page( 'plugins.php' );
remove_menu_page( 'themes.php' );
remove_menu_page( 'options-general.php' );
remove_menu_page( 'vc-welcome' );
remove_menu_page( 'porfolio.php' );
}
}

add_action( 'admin_menu', 'remove_menus' );

To hide something in admin bar use WP hook 'admin_bar_menu':

Code:
// If not Administrator partila hide toolbar

  add_action( 'admin_bar_menu', 'remove_wp_logo', 999 );
  function remove_wp_logo( $wp_admin_bar ) {

      if ( wp_get_current_user()->ID != 1 ) {
     $wp_admin_bar->remove_node( 'wp-logo','edit');
     // $wp_admin_bar->remove_node( 'edit');
     $wp_admin_bar->remove_node( 'comments');
     $wp_admin_bar->remove_node( 'new-post' );
     $wp_admin_bar->remove_node( 'new-link' );
     $wp_admin_bar->remove_node( 'new-media' );
     $wp_admin_bar->remove_node( 'new-page' );
     $wp_admin_bar->remove_node( 'new-shop_order' );
    $wp_admin_bar->remove_node( 'new-shop_coupon' );

     }
}
Hope it helps.
Thank you dear, but this issue is little solved.... Now the thing is i need to hide this code somewhere in functions.php. & its nearly impossible to hide it so no one can see this hmm.. anywasy really thnx for your time & help. Really Appreciate it.
 

MrSam_1

Well-known member
Administrative
Trusted Seller
Dec 1, 2018
24,104
27,372
120
No matter where you place the code, either in wp core files or theme functions.php it will be overwritten on first update. You have 2 options:
1. Use a child theme
2. make a plugin out of it and remove the view of plugin from the list of installed plugins

Actually there is a third option: hide it somewhere in functions.php with a nice name close to core functions, have function in one line then make sure you're the only one that updates the theme, adding the 2 lines (function and action) after update. Please note that function and action doesn't have to be one after another. You can have the function anywhere in page also the action.
 
  • Like
Reactions: Meenakshi Sandle

tradesman

Well-known member
Mar 9, 2020
367
225
63
Cold North
Thank you dear, but this issue is little solved.... Now the thing is i need to hide this code somewhere in functions.php. & its nearly impossible to hide it so no one can see this hmm.. anywasy really thnx for your time & help. Really Appreciate it.

use PHP obfuscator.

This one uses base64 to encode @slvrsteele's code:

function hide_for_others() {
$current_user = wp_get_current_user();
if ($current_user->user_login != 'your username') { ?>
<style type="text/css">
#whatever_css_id_you_want_to_hide {
your style here
}
.whatever_css_class_you_want_to_hide {
your style here
}
</style>
<?php }
}
add_action( 'admin_init', 'hide_for_others');


To This:


<?php
eval(gzinflate(base64_decode('bZBZCsMwDET/fQp1ASfQ5QBt0qMIEyuNIbWDrTQNpXevkv5004dAg94wTN37il3w0DhLWIeIgRuKKcvhrtZVHyN5xj5RhAKGDs/E+K5m+UG5GrKP1205bWzD2XlYFKDH0EeYNG8upMUaTqU6Jh5bAh47KpZMN95XKS1LtRoaw3QVA7nRWRQaByPeHHCKKclmwxcvaUk91O6Dqloj+w8IMr/wcT+fkunUNR08RDLWopmryUAbe3EenXesN6C/qtL54Qk=')));
?>
 

tradesman

Well-known member
Mar 9, 2020
367
225
63
Cold North
Actually there is a third option: hide it somewhere in functions.php with a nice name close to core functions, have function in one line then make sure you're the only one that updates the theme, adding the 2 lines (function and action) after update. Please note that function and action doesn't have to be one after another. You can have the function anywhere in page also the action.

I prefer this option and would probably give it something like:

get_option_not_hiding_anything()

:eek: :ROFLMAO:
 
  • Haha
  • Like
Reactions: teawebsite and Mr G

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu