• Hello!

    I need your help because i would like to know if it’s possible to display or not mextaboxes (into the edit post page, inside admin panel) depending on the author capabilities or role?

    Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    If you just want to hide them an easy way would be through CSS.

    You can add a function like this:

    function add_user_role_body_class( $userClass ) {
        global $current_user;
        foreach( $current_user->roles as $userRole )
            $userClass .= ' user-role-' . $userRole;
        return trim( $userClass);
    }
    add_filter( 'admin_body_class', 'add_user_role_body_class' );

    This will add the ex ‘user-role-administrator’ class to your admin body tag.

    Then you can add the appropriate CSS to hide anything you like example:

    body.user-role-administrator #myDiv {
       visibility:hidden !important;
       position:absolute !important;
    }

    About the CSS:

    With display: none, the form fields won’t be submitted, so instead you can use visibility:hidden .

    You could also go a bit more advanced by totally removing them with jQuery etc but that depends on what those metaboxes are used for etc if they are validated etc etc.

    Best regards,
    Konstantinos

    Hello @ximun144

    Yes, this is possible to display mextaboxes depending on the author capabilities or role.

    Please take a look at this plugin for concept…

    https://www.ads-software.com/plugins/user-specific-content/

    Hope this will help.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Metaboxes with conditionnal capability’ is closed to new replies.