Last active
February 3, 2025 10:54
-
-
Save thegulshankumar/e6457f5f472d36979c91fea1e6df4866 to your computer and use it in GitHub Desktop.
Enhancing Dashboard User Experience for Contributors and Non-Admins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use the Rank Math plugin, you should enable these features for Contributors.