WP Manifestindependent plugin directory
manifest / themes / body-state

Body State

WordPress plugin to expose user state and user role via the body element's CSS classes.

by John Kawakami · github.com/johnkawakami/body-state

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/johnkawakami/body-state/archive/refs/heads/main.zip

A lightweight WordPress plugin that adds dynamic CSS classes to the body element based on the user's login state and role. This plugin helps developers target specific user states and roles with CSS styles, making it easier to customize the user experience.

Key Features:

* Adds ustate-loggedin or ustate-loggedout class to the body element based on the user's login state
* Adds urole-<role> class to the body element for each user role (e.g. urole-administrator, urole-subscriber, etc.)
* Lightweight and easy to use, with no settings or configuration required

Example Use Cases:

* .urole-administrator { background-color: #f0f0f0; } to style the body differently for administrators.
* .urole-subscriber .premium-content { display: block; } to show premium content only to subscribers.
* .ustate-loggedin .login-link { display: none; } to hide the login link when the user is logged in.

Common User Roles:

administrator
editor
author
contributor
subscriber
customer (WooCommerce)
shop_manager (WooCommerce)

You can use these role names to target specific user roles in your CSS. Note that custom roles will also be added as classes, so you can target those as well.