Skip Navigation

[Resolved] Hide Custom Fields Group for specific user role only – reloaded

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 11 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by roniM 11 years, 1 month ago.

Assisted by: Caridad.

Author
Posts
#56978

Sorry for opening new ticket, but your system does not allow me to reply to previous topic!

How can I reference Fields group and hide it only for users that have certain role?

Something like this…

function admin_only_metabox() {
global $current_user;
if($current_user->roles[0] == 'custom_role') {
//HIDE SPECIFIC CUSTOM FIELDS GROUP
}
}
add_action('admin_init','admin_only_metabox');

Question here is not the hook to use, but that is nice help. My question is how to reference 'Fields group'? Code that should go here: //HIDE SPECIFIC CUSTOM FIELDS GROUP

#57707

Dear Roni,

The code needed to remove the metabox is this:

add_action('wpcf_admin_post_init', 'admin_only_metabox', 10, 4);
function admin_only_metabox( $post_type, $post, $groups, $wpcf_active ) {
global $current_user; 
if($current_user->roles[0] == 'custom_role' && $post_type == 'company') {
  //var_dump($groups);
  remove_meta_box('company-data', $post_type, 'high');
}
}

Replace 'company' with your custom post type and uncomment the var_dump() to see the slugs for the groups. In my case it was 'company-data'.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#69215

Thank you for the code.
Also working for me was this:

function custom_remove_post_widgets() {
    if( (current_user_can('update_core')) ) {
    	    return;
    } else {
    	    global $post_type;
    	    remove_meta_box( 'wpcf-marketing', $post_type, 'side' );
    	    remove_meta_box( 'payments-and-expiery', $post_type, 'normal' );
    }
}
add_action('admin_head', 'custom_remove_post_widgets' );

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.