Show/hide admin columns by front-end input

Support MB Admin Columns Show/hide admin columns by front-end input

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38192
    kadotakadota
    Participant

    Hi, I'm trying to accomplish something but I'm not sure how to do it.

    I have a MB front-end submission in which users can make a selection (let's say "Dogs" or "Cats") for a custom post type created with Meta Box as well (let's say "Animals").

    Then I have editors who are "Dogs Reviewers" or "Cats Reviewers" and access the WordPress custom-type page to review the entries. Depending on that, I want to hide the entries unrelated to their position in the admin columns (so a "Dog Reviewer" only sees submissions that have "Dogs" selected by a user).

    Is there any filter or option that I can use to make this happen?

    Thanks a lot.

    #38197
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can hide an admin column for a user role/ID when registering the custom fields with code. For example:

    function your_prefix_function_name( $meta_boxes ) {
        $admin_columns = true;
    
        global $current_user;
        $user_roles = $current_user->roles;
        $user_role = array_shift($user_roles);
        if( $user_role != 'administrator' ) $admin_columns = false;
    
        $meta_boxes[] = [
            'title'  => __( 'My Custom Fields', 'your-text-domain' ),
            'id'     => 'my-custom-fields',
            'fields' => [
                [
                    'name'          => __( 'Text', 'your-text-domain' ),
                    'id'            => 'text_9wwu55lol0q12',
                    'type'          => 'text',
                    'admin_columns' => $admin_columns
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    This code will remove the admin columns of the text field if the logged in user is not an administrator.

    #38205
    kadotakadota
    Participant

    Hi Long,

    I need to make it happen the other way around: depending on the field's value, one role can see it or not. Let's say it's a select/radio button: if the Dog option is selected, the role Dog Reviewer can see that row in the admin column. Is that possible to achieve with MetaBox?

    #38220
    Long NguyenLong Nguyen
    Moderator

    Hi,

    No, the admin column is registered even whether the field has value or not. You can remove the admin column for a field if the user logged in has a specific role as I mentioned above.

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