I would also like to do this. Would appreciate any help.
So far I know how to add a new option title and where its meant to hook in, but I’m a bit unsure what to put in the conditions field to hide the content if they are a shopkeeper.
add_filter( 'if_menu_conditions', 'wpb_new_menu_conditions' );
function wpb_new_menu_conditions( $conditions ) {
$conditions[] = array(
'name' => 'shopkeeper', // name of the condition
'condition' => function($item) { // callback - must return TRUE or FALSE
return is_post_type_archive();
}
);
return $conditions;
}
Plugin Author
Andrei
(@andreiigna)
Hi,
Please take a look at how the default conditions are added https://github.com/AndreiZzz/if-menu/blob/master/conditions.php conditions for custom roles are added in the same way.
Example for ‘shopkeeper’:
add_filter('if_menu_conditions', 'wpb_new_menu_conditions_shopkeeper');
function wpb_new_menu_conditions_shopkeeper($conditions) {
$conditions[] = array(
'name' => 'Shopkeeper', // name of the condition
'condition' => function($item) { // callback - must return TRUE or FALSE
global $current_user;
return is_user_logged_in() && in_array('shopkeeper', $current_user->roles);
}
);
return $conditions;
}