• Resolved danielwerner23

    (@danielwerner23)


    Hi there,

    i want to add a specified backend user to page access. This means: backend user a can only edit and changes puplish page foo, page bar, … user b can only access to page x,y… The problem with wordpress roles is the restriction to edit and puplishing pages is only set to the role member. Every member can view, edit und puplish every page, but not only specified for him.

    Is it possible with a plugin? Or can i get it with custom code?

    Thanks a lot.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ok so Author https://www.ads-software.com/documentation/article/roles-and-capabilities/#author would be restricted to their own posts.

    And Editor has access to all posts.

    I think you are asking can there be a role between?

    And some how you would specify groups of pages that related to a specific user beyond ‘author’ maybe using categories?

    And

    Is it possible with a plugin?
    Or can i get it with custom code?

    So yes it is possible with a plugin ( as a plugin is custom code and it is possible with custom code ).

    Thread Starter danielwerner23

    (@danielwerner23)

    Thank you for your answer. I am asking for page-permissions not for the posts. I’ve testet some plugins, but you can only edit the permissions. In wordpress itself you cant disable/edit which elements the backend user can have/see/use.

    So i’ve coded a snipped which allows only editing and puplishing pages (changes). Also it hides the new button, the meta boxes to prevent the change of parent page and the menu media item (its only css hiding, but i dont know a better solution). Thats solved my problem:

    /**
    
    ?* Add custom user roles for backend
    ?* notice: use remove_role('pageeditor') onchange!
     * you need it only once or on changes
    ?*/
    
    /*
    
    add_role('pageeditor', 'Editor (specific for pages)', array(
    
    ? ? 'read' => false,
    ? ? 'create_posts' => false,
    ? ? 'edit_posts' => false,
    ? ? 'edit_others_posts' => false,
    ? ? 'publish_posts' => false,
    ? ? 'manage_categories' => false,
    ? ? 'manage_links' => false,
    ? ? 'moderate_comments' => false,
    ? ? 'edit_comments' => false,
    ? ? 'moderate_comments' => false,
    ? ? 'create' => false,
    ? ? 'create_pages' => false,
    ? ? 'manage_options' => false,
    ? ? 'delete' => false,
    ? ? 'delete_pages' => false,
    ? ? 'delete_others_pages' => false,
    ? ? 'edit_other_pages' => false,
    ? ? 'edit_pages' => true,
    ? ? 'edit' => true,
    ? ? 'edit_published_pages' => true,
    ? ? 'publish_pages' => true,
    ? ? 'upload_files' => true,
    
    ));
    
    */
    
    /**
    
    ?* Modify backend view for role pageeditor
    
    ?*/
    
    if (current_user_can('pageeditor') && !current_user_can('manage_options')) {
    
    ? ? add_action('admin_init', function () {
    
    ? ? ? ? //remove meta box
    ? ? ? ? remove_post_type_support('page', 'page-attributes');
    
    ? ? ? ? //remove media nav item
    ? ? ? ? remove_menu_page('upload.php');
    
    ? ? });
    
    ? ? //add role-* class to backend body
    ? ? add_filter('admin_body_class', function ($classes) {
    
    ? ? ? ? global $current_user;
    ? ? ? ? foreach ($current_user->roles as $role)
    ? ? ? ? ? ? $classes .= ' role-' . $role;
    ? ? ? ? return trim($classes);
    
    ? ? });
    
    }
    Thread Starter danielwerner23

    (@danielwerner23)

    I mark it as solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘backend user to page restriction’ is closed to new replies.