My goal is to hide specific tables with CSS on WordPress dashboard, from all users except super admin.
<?php is_super_admin( $user_id ); ?>
add_action( 'admin_head', 'my_custom_function' );
function my_custom_function() {
if ( ! current_user_can( 'update_core' ) ) {
echo '<style>p.smush-status {
display: none;
}
button.button.wp-smush-send {
display: none;
}
#smushit {
display:none;
}</style>';
}
});
But, when I'm adding this code to mu-plugins, I got the following error:
Fatal error: Call to undefined function wp_get_current_user() in /home/.../public_html/domain.com/wp-includes/capabilities.php on line 1614
capabilities.php it's WordPress core file.
Would you please have a look and tell me how can I improve this code?
Thank you
Do not use css to hide part of the admin dashboard, this is a security breach. You must to unset it using a function added in your theme functions.php:
// Create the function to use in the action hook
function remove_dashboard_widgets() {
global $wp_meta_boxes;
// Remove the quickpress widget
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
// Remove the incomming links widget
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
}
// Hoook into the 'wp_dashboard_setup' action to register our function
if(!is_admin()){
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
}
Edit: and dont edit wordpress core files aswell, you will lost everything because of update.