Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thegulshankumar/e6457f5f472d36979c91fea1e6df4866 to your computer and use it in GitHub Desktop.
Save thegulshankumar/e6457f5f472d36979c91fea1e6df4866 to your computer and use it in GitHub Desktop.
Enhancing Dashboard User Experience for Contributors and Non-Admins
<?php
/**
* By default, users with the Contributor role cannot upload images.
* The following snippet overrides this restriction, allowing them to upload images.
*/
function allow_contributor_uploads() {
$role = get_role( 'contributor' );
if ( $role && ! $role->has_cap( 'upload_files' ) ) {
$role->add_cap( 'upload_files' ); // Add upload capability
}
}
add_action( 'admin_init', 'allow_contributor_uploads' );
// Remove Litespeed Page Options for non-admin
function remove_ols_metabox() {
if ( is_admin() && ! current_user_can( 'administrator' ) ) {
$args = array(
'public' => true,
);
$post_types = get_post_types( $args );
foreach ( $post_types as $post_type ) {
remove_meta_box( 'litespeed_meta_boxes', $post_type, 'side' );
}
}
}
add_action( 'add_meta_boxes', 'remove_ols_metabox', 999 );
// Remove Feedify Meta Box for Non-Admins
function remove_feedify_meta_box_for_non_admins() {
if ( ! current_user_can( 'manage_options' ) ) {
remove_meta_box( 'feedify-meta-box-id', 'post', 'side' ); // Adjust post type if needed
remove_meta_box( 'feedify-meta-box-id', 'page', 'side' ); // For pages, if applicable
}
}
add_action( 'add_meta_boxes', 'remove_feedify_meta_box_for_non_admins', 99 );
// All these snippets should be added using the Code Snippets plugin.
@thegulshankumar
Copy link
Author

If you use the Rank Math plugin, you should enable these features for Contributors.

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment