0
X
Add Snippet To Project
New Project
Add To Existing Project
<?php
/**
* Plugin Name: WP Turbo Plugin
* Description: Shortcode to display current user's roles.
* Version: 1.0
* Author: WP Turbo
* Author URI: https://wpturbo.dev
* Text Domain: wpturbo
*/
function wpturbo_get_current_user_roles() {
$current_user = wp_get_current_user();
$roles = $current_user->roles;
$output = '<ul>';
foreach ($roles as $role) {
$output .= '<li>' . translate_user_role($role) . '</li>';
}
$output .= '</ul>';
return $output;
}
add_shortcode('current_user_roles', 'wpturbo_get_current_user_roles');
Explanation:
You can now use the [current_user_roles] shortcode to display the list of roles assigned to the current user.