Add Slug Metabox to posts for contributors

I am trying to enable slug Metabox for contributors.
Find a code to remove slug Metabox try to change it in way to work around my problem but nothing happens.

function add_contributor_post_meta_box() {
    global $post;
    if ( current_user_can( 'edit_post', $post->ID )) {
    add_meta_box('slugdiv', 'post', 'normal');
    }
   }
add_action('admin_menu', 'add_contributor_post_meta_box');

Anyone can help to solve this problem?

My main problem coming from, when a contributor sends a post and enters the title and permalink after sending it for review the permalink automatically changes to the main title, I don’t want this to happen, also need to know how to fix this problem any help?

1 Answer
1

I approached by doing the opposite with using remove_meta_box() for the Slug metabox if the user is not an administrator or contributor:

add_action( 'admin_menu', 'wpse_237291_remove_slug_metabox' );
function wpse_237291_remove_slug_metabox() {
    $user = wp_get_current_user();
    $allowed_roles = array( 'administrator', 'contributor' );

    if ( !array_intersect( $allowed_roles, $user -> roles ) ) {
        remove_meta_box( 'slugdiv', 'post', 'normal' );
    }
}

Leave a Comment