Home › Types Community Support › [Resolved] Hide Custom Fields Group for specific user role only – reloaded
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.
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
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
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.