Restrict Author to ONLY their post

Hi.

I am working with Membership Pro 2 and a membership site. I have 4 tiers. Admin, Author, member and guest. My site is located here: http://162.144.60.226/~taggedbyanangel/ .

I want to make it so the author of a given membership post can edit only their post. I have read two WPMU closed threads:

https://premium.wpmudev.org/blog/limit-access-to-your-wordpress-dashboard/

https://premium.wpmudev.org/blog/how-to-limit-the-wordpres-posts-screen-to-only-show-authors-their-own-posts/

There are leads to it but nothing concrete. Now I have installed: https://wordpress.org/plugins/manageview-your-posts-only/ which works BUT if an author logs in to my site and clicks settings (Not sure why the dashboard bar doesn't appear) and enters the dashboard they see more than Posts and Profile. They see media, comments, Visual Composer, Fusion slider, etc. I don't want that. They aren't admins. I only want them to be able to manage their own post(s)

How do I hide all but Posts?

Better yet can they be restricted to the front end with edit options?

IS there a WPMU plugin for this or an MU plugin for this.

  • Rupok

    Hi David, hope you had a wonderful day.

    You are close to your target. You said you are using this plugin (https://wordpress.org/plugins/admin-menu-editor/) for restricting authors only to their posts. Now use this plugin ( https://wordpress.org/plugins/admin-menu-editor/ ) for hiding all menu items which you don't want. You can hide those menu items by user roles, so you should hide those for Authors. This way you can achieve what you want.

    Please let us know if you have any confusion. We will be glad to help.

    Have a nice day. Cheers!
    Rupok

  • David

    Thank you for replying to the ticket.

    Note: I found a similar plugin that I put into use prior to opening his ticket:

    Adminimize Version 1.10.5 | By Frank Bültge

    It soes a good job but there are issues still in need to addressing that this and the other plugin does not address.

    Please review screen cast: http://screencast.com/t/4FgCcbYA5n5r

    As demonstrated, I have much of the functionality that I am looking for with exceptions.
    From the dashboard there seems to be no easy way to return to the front end. Visit Website is a missing option. I have to go to posts and visit post to get there and the typical dashboard menu bar (the grey one at the top) is missing when logged in as an author.

    When I edit a post I see options I do not want to have made available to an author such as Membership Access which shows all the memberships available to that author.

    It would also be nice to be able to hide Add New at the top of the page as I want to limit the author to just one post, his or her own. (The admin initially sets up the post for the author and assigns it to that author)

    Thank you for participating.

  • Kasia Swiderska

    Hello David,

    I have to go to posts and visit post to get there and the typical dashboard menu bar (the grey one at the top) is missing when logged in as an author.

    This is because there is Option in Membership 2 Pro Settings -> General "Hide admin toolbar " - that hides admin bar. You can turn it on and then with Ultimate branding plugin https://premium.wpmudev.org/project/ultimate-branding/ adjust it content for specific roles (hide elements you don't need for authors).

    As for the membership metabox Author role should have no access to it. It should look like that:

    Metabox is there but it has no content inside. So I suspect that you have some plugin to manage roles and capabilities that might give author role additions admin capabilities and that is why they see those. Or maybe you are using Capabilities add-on in Membership?

    kind regards,
    Kasia

  • David

    Hi.

    Thank you for your support. My apologies for the delayed reply. I was on July 4th vacation and then the client went on vacation.

    Please refer to the following screen cast: http://screencast.com/t/zvj6BN2w

    I'm focusing just on the membership metabox

    Metabox appears to always show the content inside. I went through the exercise of deactivating all plugins but membership 2 pro and WPMU Dev Dashboard and the problem persists.

    Also I do not appear to have the Capabilities add-on in Membership active.

    I do have 2 MU Plugins active that WPMU provided for fixing the registration and login process. I do not believe they are at play here.

    Any further advise you have to hide this is appreciated.

  • Kasia Swiderska

    Hello David,

    Would you mind allowing support access for me? Did you ever used plugin for changing capabilities or roles of users? Problem with some that plugins is when you disable them changes they made are still working.
    It looks like author role has more capabilities that are allowing users with it to see membership list in meta box - but I would like to check it more thoroughly.

    kind regards,
    Kasia

  • David

    Re. Dashboard support access.

    Sure. Please provide me instructions on how to provide it to you.

    Side note, I just provided the dashboard support to Sajid Javed in cousin ticket: https://premium.wpmudev.org/forums/topic/incompatibility-between-membership-pro-2-and-key-search-plugin#post-1110584

    Should I open another with him or with you?

    Please advise.

    Note: I do use an author restricting MU code called simplify-post-edit-list.php. This is the code.

    <?php
    /*
    Plugin Name: Simplify Post Edit List
    Description: Show only the author's posts in the edit list
    Version: 0.1
    License: GPL
    Author: Sarah Gooding
    Author URI: http://untame.net
    */
    
    function mypo_parse_query_useronly( $wp_query ) {
        if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
            if ( !current_user_can( 'update_core' ) ) {
                global $current_user;
                $wp_query->set( 'author', $current_user->id );
            }
        }
    }
    
    add_filter('parse_query', 'mypo_parse_query_useronly' );
    
    ?>

    I also use these plugins:

    Adminimize
    Change Author

    I toyed with but deactivated these plugins (still installed)

    Admin Menu Editor
    Front-end Editor
    Fusion Core
    Manage/View Your Posts Only
    Restrict Author Posting
    WP User Frontend

    All of the above deactivated plugins may be uninstalled and deleted from the Themes folder. I don't use them, in case they cause interference.

    Thanks. Please advise.

  • David

    Hi Kasia

    Thanks for this. Your code works.

    This is a finished issue but I do have one question.

    A member from wordpress.org was kind enough to provide this code. It breaks my page in the functions.php child theme file. Do you know why? (Does it clash with your code?)

    function hide_add_new_link() {
        if( is_admin() ) {
            if ( is_user_logged_in() ) {
                $user = wp_get_current_user();
                if ( !empty( $user ) ) {
                    // check if currently logged-in user has role: author
                    if ( in_array( 'author', (array) $user->roles ) ) {
                        global $pagenow;
                        if( 'post.php' == $pagenow ) {
                            $css = '<style>';
                            $css .= '#wpcontent .page-title-action {';
                            $css .= 'display: none;';
                            $css .= '}';
                            $css .= '#side-sortables #ms-membership-access {';
                            $css .= 'display: none;';
                            $css .= '}';
                            $css .= '</style>';
                            echo $css;
                        }
                    }
                }
            }
        }
    }
    add_action( 'init', 'hide_add_new_link');

    Just curious. Thanks.

  • Kasia Swiderska

    Hello David,

    No, it should not have effect on my change in the plugin - however in styles they wrote I can see duplicated one for hiding metabox.

    But no wonder that code breaks your page - it adds styles to the top of the page and this creates invalid html document.

    It is better to use that code:

    <style>#wpcontent .page-title-action {display: none;}</style>

    like that:

    add_action('admin_head', 'my_custom_fonts');
    
    function my_custom_fonts() {
            if( is_admin() ) {
            if ( is_user_logged_in() ) {
                $user = wp_get_current_user();
                if ( !empty( $user ) ) {
                    // check if currently logged-in user has role: author
                    if ( in_array( 'author', (array) $user->roles ) ) {
                        global $pagenow;
                        if( 'post.php' == $pagenow ) {
      echo '<style>#wpcontent .page-title-action {display: none;}</style>';
                          }
                    }
                }
            }
        }
    }

    kind regards,
    Kasia

  • David

    Hi

    It looks like I need to revisit this ticket in conjunction with a problem incurred in this ticket:

    https://premium.wpmudev.org/forums/topic/author-unable-to-preview-or-update-protected-post#post-1117104

    Turns out that the code I used to hide the "Add New" button on edit post for authors as provided by wp.org did indeed hide the button BUT if an author previews or presses update the author sees a blank window with no indication as to what the problem is. If the author presses update the revisions are applied but the author would not know that that the authors taken to a white screen.

    Note: The administrator of the same post does not incur this problem. This is limited to the authors.

    This is likely a php 500 error. That something is occurring before line 100 as I immediately get the white screen and that the php code was stopped before the command was given.

    If I remove the code below as provided by cedcommerce from this thread from the child theme's functions.php file the problem goes away. https://wordpress.org/support/topic/hide-admin-toolbar-new-menu-for-authors?replies=6#post-8649547.

    CODE:

    /* ---- DNOTE: wp.org Hide ADD NEW Button for authors ---- */
    
    function hide_add_new_link() {
    
        if( is_admin() ) {
    
            if ( is_user_logged_in() ) {
    
                $user = wp_get_current_user();
    
                if ( !empty( $user ) ) {
    
                    // check if currently logged-in user has role: author
    
                    if ( in_array( 'author', (array) $user->roles ) ) {
    
                        global $pagenow;
    
                        if( 'post.php' == $pagenow ) {
    
                            $css = '<style>';
    
                            $css .= '#wpcontent .page-title-action {';
    
                            $css .= 'display: none;';
    
                            $css .= '}';
    
                            $css .= '</style>';
    
                            echo $css;
    
                        }
    
                    }
    
                }
    
            }
    
        }
    
    }
    
    add_action( 'init', 'hide_add_new_link');

    Previously you were able to manipulate the Adminimize plugin to hide other element. Would you be able to do the same thing in order to hide the add new button?

    Please let me know. Clearly I cannot use the code posted in this reply.

    Thanks much.

  • Nithin

    Hi David,

    Hope you are doing good today. :slight_smile:

    You can make changes using the Adminimize plugin, under Settings > Adminimize > Write Options - Post. I have added a new option, which the selector class ID of the button.

    And then deactivated the new option for the Author role, this should hide the posts Add New button.

    Please do note this will only hide the Add New button in post, to hide the button for the Page section, please repeat the process for Pages, under Write Options - Page.

    Please let us know if you still need any further assistance. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • David

    Hi.

    Dp you know how to hide the Visual Composer sidebar menu link for authors?

    I was able to hide all other features Under Settings...Adminimize

    But I am unable to do the same under menu options even though I checked the boxes for Author for it and added my own custom code at the bottom of the section as you directed previously.

    Any assistance you may be able to provide would be appreciate.

    You have permission to enter my dashboard and have WPMU access for the next 7 days.

    Thank you in advance.

  • Rupok

    Hi David,

    Dp you know how to hide the Visual Composer sidebar menu link for authors?

    For hiding Visual Composer with Adminize, you have to add a custom entry, like:
    Left box: “My Visual Composer Item”
    Right box: "vc-welcome"
    It will give you a new row of options. Hide for Authors from there and it will serve your purpose.

    I applied on your site and now Visual Composer menu is not showing for Authors anymore. Can you please check and confirm?

    Have a nice day. Cheers!
    Rupok

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.