A WordPress plugin to help developers test user roles and capabilities in non-production environments.
Role Test Helper is designed to simplify WordPress role testing by providing:
-
Role-Based Login: Log in with any WordPress role name as the username (e.g., "administrator", "editor", "author") and any password. The plugin will create users with appropriate permissions if they don't exist.
-
Safe Environment Detection: The plugin automatically disables itself in production environments to prevent security risks, only functioning in development, staging, or local environments.
- Easy Role Testing: Log in as any WordPress role without creating test users manually
- Production Safety: Automatically disabled in production environments using
wp_get_environment_type()
- Local Development Support: Always enabled on localhost and .local domains
- Extensibility: Provides filter hooks for customizing plugin behavior
- Clone this repository
- Run
composer install
to install PHP dependencies - Activate the plugin through the WordPress admin interface
composer require aaronjorbin/role-test-helper
- Make sure you have Docker installed
- Install Node.js dependencies with
npm install
- Run
npm run start
to start a local WordPress environment using wp-env - The site will be available at http://localhost:15734 (admin: http://localhost:15734/wp-admin/)
- Username: admin
- Password: password
Once activated, you can log in with any WordPress role name as the username:
- Go to your WordPress login page (wp-login.php)
- Enter a role name (e.g., "editor", "author", "contributor") as the username
- Enter any password
- Click "Log In"
The plugin will either:
- Log you in as an existing user with that username, or
- Create a new user with the appropriate role and log you in
The default WordPress roles you can use are:
- administrator
- editor
- author
- contributor
- subscriber
Plus any custom roles defined by themes or plugins.
The plugin adds an admin page under "Tools > Role Test Helper" that shows:
- Current plugin status
- Available roles for testing
- Usage instructions
By default, the plugin is:
- Disabled in production environments
- Enabled in development, staging, and local environments
- Always enabled on localhost and .local domains
Control whether the plugin should be active:
// Force the plugin to be inactive
add_filter( 'role_test_helper_is_active', '__return_false' );
// Custom logic for determining if the plugin should be active
add_filter( 'role_test_helper_is_active', function( $is_allowed, $environment_type, $site_url ) {
// Your custom logic here
return $is_allowed;
}, 10, 3 );
# Install PHP dependencies
composer install
# Install Node.js dependencies and git hooks
npm install
This project uses git hooks to ensure code quality:
- Pre-commit Hook: Automatically runs PHP CodeSniffer, PHPStan, and PHPUnit tests before each commit
- Prevents commits if linting or tests fail
- Runs PHPUnit tests if the wp-env environment is running (otherwise skips tests)
- Ensures only quality code is committed to the repository
Note: For full test coverage in the pre-commit hook, make sure to start the WordPress environment with
npm run start
before committing.
If the git hooks are not working, you can manually set them up:
# Manually set up git hooks
./bin/setup-hooks.sh
# Run PHPUnit tests
composer phpunit
# Run PHP CodeSniffer
composer phpcs
# Run PHP Code Beautifier
composer phpcbf
# Run PHPStan static analysis
composer phpstan
# Run all checks (same as pre-commit hook)
npm run lint && composer phpunit
# Start the development environment
npm run start
This plugin follows the WordPress Coding Standards and uses PHP_CodeSniffer to enforce them.
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-new-feature
- Make your changes and commit them:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature/my-new-feature
- Submit a pull request
Before submitting, please:
- Ensure your code follows WordPress Coding Standards (
composer phpcs
) - Add unit tests for any new functionality
- Update documentation as needed
IMPORTANT: This plugin is intended for development and testing environments only. It will automatically disable itself in production environments to prevent security risks.
GPL-2.0-or-later