I want to learn how to create a WordPress shortcode that checks for a user role.
If a WP user has user role 'member1', then show the content. Otherwise, show nothing.
This is the WordPress code I have to check for a user role:
$user = wp_get_current_user();
if ( in_array( 'member1', (array) $user->roles ) ) {
//The user has the "member1" role
}
I also know how to create a shortcode, like this:
add_shortcode( 'check-user-role', 'func_check_user_role' );
func_check_user_role() {
}
But how do I combine both into something that works like this (to check if a user has 'member1' user role:
[check-user-role='member1']show this content if the user has user role member1[/check-user-role]
Any suggestions?