Change WordPress user roles and capabilities Forums How to or FAQ quick edit and permalink disable for role

Tagged: 

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #3076
    digitaliway
    Participant

    I have a role for people to edit pages, but I do not want them to edit the slug/permalink or do a quick edit. how can I prevent this?

    #3079
    Vladimir
    Keymaster
    #3122
    digitaliway
    Participant

    This did not work. can you please provide specific code or update plugin to have capability?

    I have a role called: page-editor

    I added this exact code to the functions file and QUICKEDIT and PERMALINK EDIT still remain.

    if (current_user_can(‘page-editor’)) {
    add_filter(‘post_row_actions’,’remove_quick_edit’,10,1);
    }
    function remove_quick_edit( $actions ) {

    unset($actions[‘inline hide-if-no-js’]);

    return $actions;
    }

    #3123
    Vladimir
    Keymaster

    This code is still actual to remove ‘Quick Edit’ link under a post line at the posts list. I re-tested it with theme 2017 functions.php, I just used the ‘editor’ role instead yours:

    
    if (current_user_can('editor')) {
        add_filter('post_row_actions','remove_quick_edit',10,1);
    }
    function remove_quick_edit( $actions ) {
        
        unset($actions['inline hide-if-no-js']);
        
        return $actions;    
    }
    

    Check if you inserted code to the active theme’s functions.php, if your test user really has ‘page-editor’ role.

    I’m ready to look at your site on-line if you send URL and admin login credentials to support [at-sign] role-editor.com

    #3132
    digitaliway
    Participant

    I was able to get this working with the below code. The code you posted does not contain “page_row_actions” and the code on https://www.role-editor.com/block-permalink-edit-button/ does not seem to work so I changed it to the filter “get_sample_permalink_html” below which seems more efficient unless you see a better solution?

    
    //remove quick edit functions for page and post
    function remove_quick_edit( $actions ) {
        unset($actions['inline hide-if-no-js']);
        return $actions;
    }
    if ( current_user_can('page-editor') ) {
        add_filter('page_row_actions','remove_quick_edit',10,1);
        add_filter('post_row_actions','remove_quick_edit',10,1);
    }
    
    //hide permalink edit buton on page for role
    function hide_permalink() {
        return '';
    }
    
    if ( current_user_can('page-editor') ) {
    	add_filter( 'get_sample_permalink_html', 'hide_permalink' );
    }
    
    
    
    
    #3133
    Vladimir
    Keymaster

    Yes, I did not tested with pages somehow :), just with posts. Thank You for the update.

    #4859
    jbgayet
    Participant

    Hi, when applying this in a mu-plugins I got a nice Fata error :

    `Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /wp-includes/capabilities.php:590

    any idea on how to fix ?
    Thank’s
    JB

    #4860
    Vladimir
    Keymaster

    Hi,

    You should not call current_user_can() directly from mu-plugin code. You have to enclose it into some function hooked to the action when WordPress will load it’s core code already, like this:

    
    add_action('admin_init', 'load_mu_plugin');
    function load_mu_plugin() {
      if ( current_user_can('page-editor') ) {
          add_filter('page_row_actions','remove_quick_edit',10,1);
          add_filter('post_row_actions','remove_quick_edit',10,1);
      }
    
    }
    
    #4861
    Vladimir
    Keymaster

    It’s better to use current_user_can() for checking if capability was granted to a user or it was not. To check if user has role it’s more correct to use this code:

    
    $user = wp_get_current_user();
    if (in_array('some_role_id', $user->roles)) {
      // do something
    }
    
    #4862
    jbgayet
    Participant

    well great, and what about hiding the Move to trash for the Publish Metabox on the edit post page ?

    #4863
    Vladimir
    Keymaster

    Revoke ‘delete_posts’, ‘delete_publish_posts’ capabilities from this role.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.