hi Christian
Many thanks for picking this one up for me ????
I understand how this would work but implementing it is another story! I've learnt loads since using Toolset but my coding skills are desperately lacking. Nevertheless I had a look at your linked page but to be honest am out of my depth on this one. I've spent a couple of hours googling generally and trying out a few things but not quite achieving the desired results.
For example, I found this but it only looks at the site/blog the user is currently visiting:-
add_shortcode('user_role', 'show_user_role');
function show_user_role() {
global $wp_roles;
$current_user = wp_get_current_user();
$roles = $current_user->roles;
$role = array_shift( $roles );
return isset( $wp_roles->role_names[ $role ] ) ? translate_user_role( $wp_roles->role_names[ $role ] ) : FALSE;
}
I also tried these shortcodes as I thought this might actually be a 'shorter' route to the required output:-
add_shortcode('blog_4', 'show_content_4');
function show_content_4() {
if (current_user_can_for_blog('4', 'edit_others_posts')) {
return 'ABC';
}
}
add_shortcode('blog_5', 'show_content_5');
function show_content_5() {
if (current_user_can_for_blog('5', 'edit_others_posts')) {
return 'XYZ';
}
}
but when I tested it on the frontend as a User (with Editor-based custom role) , I can see ABC and XYZ even though the User has only been added to Blog #4. A bit odd.
I did submit this thread at this point and after a bit more detective work I came up with this:-
add_shortcode('blog_4', 'show_content_4');
function show_content_4() {
$user_id = get_current_user_id();
$blog_id = 4;
if ( is_user_member_of_blog( $user_id, $blog_id ) ) {
return 'ABC';
}
}
add_shortcode('blog_5', 'show_content_5');
function show_content_5() {
$user_id = get_current_user_id();
$blog_id = 5;
if ( is_user_member_of_blog( $user_id, $blog_id ) ) {
return 'XYZ';
}
}
This is producing the correct output according to the sites the User belongs to. As you're the expert here, would you say this approach is an acceptable one ?
Many thanks Christian