Skip to content

Instantly share code, notes, and snippets.

@Lonsdale201
Created March 18, 2025 21:24
Show Gist options
  • Save Lonsdale201/6c3cf624aeeb5e5a1678134cce14f8ec to your computer and use it in GitHub Desktop.
Save Lonsdale201/6c3cf624aeeb5e5a1678134cce14f8ec to your computer and use it in GitHub Desktop.
JetEngine Custom macro- Current user role
// place the code in the child theme functions.php or a custom code snippets plugin like FluentSnippets
// Query builder example image: https://prnt.sc/68m85yjVSLYE
// Always return the current user role slug
add_action( 'jet-engine/register-macros', function() {
class Current_User_Role_Macro extends \Jet_Engine_Base_Macros {
public function macros_tag() {
return 'current_user_role';
}
public function macros_name() {
return 'Current User Role';
}
public function macros_args() {
return array();
}
public function macros_callback( $args = array() ) {
$current_user = wp_get_current_user();
if ( empty( $current_user->ID ) ) {
return 'No logged in user';
}
if ( empty( $current_user->roles ) ) {
return 'No role assigned';
}
return sanitize_text_field( $current_user->roles[0] );
}
}
new Current_User_Role_Macro();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment