Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/d308efccf02e7376c59eecabb922970b to your computer and use it in GitHub Desktop.
Save Garconis/d308efccf02e7376c59eecabb922970b to your computer and use it in GitHub Desktop.
WordPress | Hide (remove) a column in the in the admin plugin list
<?php
// Remove the Plugin Notes Plus column for all users other than the ones we approve below
// based on their user email domain, or their user ID
// manipulate the Plugins admin page columns
// https://www.role-editor.com/remove-column-from-wordpress-users-list/
add_filter('manage_plugins_columns','fs_remove_plugin_notes_columns_for_most_users');
function fs_remove_plugin_notes_columns_for_most_users($column_headers) {
// get current user data
$current_user = wp_get_current_user();
// get their email address
$email = $current_user->user_email;
// ** SET ALLOWED EMAIL DOMAIN HERE **
// domain to check in the email address
$domain = 'example.com';
// check if user's email address matches the one we check against
// we check to see if it returns false, and if so, they are deemed a user with $banned_user_email
// because otherwise, it would return the position of the first occurrence of the $domain string within the $email string... but if it returns FALSE, then the string was not found
$banned_user_email = strpos($email, $domain) === false;
// ** SET LIST OF ALLOWED USER IDs HERE **
// list of allowed user IDs (add more within the array, as a comma separated list) e.g., array(3, 345, 995, 6);
$allowed_user_ids = array();
// if the current user ID is not withinout list of $allowed_user_ids, then they are deemed a user with $banned_user_id
$banned_user_id = !in_array($current_user->ID, $allowed_user_ids);
// if the current user is both a banned email and a banned user ID, then hide the plugin column
// otherwise, if not BOTH of these, they are at least either an allowed email or an allowed user ID, so we want to let them through
// that's why we need to check if BOTH banned options are true, so that if only one is true, and the other is false, it will still show for that user
if ( $banned_user_email && $banned_user_id) {
// then hide the Plugin Notes Plus column
unset($column_headers['pnp_plugin_notes_col']);
}
// return the set of columns
return $column_headers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment