
"My Constants" page showing custom constants with full management capabilities
PHP Constants Manager provides a secure and user-friendly interface for managing PHP constants in WordPress. No more editing wp-config.php or theme files to add or modify constants!
wp phpcm ... — ideal for automation, CI/CD, and multi-site provisioningThe plugin intelligently detects when constants are already defined by WordPress core, other plugins, or your theme:
* Not Predefined: Your constant is unique and will work normally
* Predefined: The constant exists elsewhere – your definition is saved but won’t override the existing value due to PHP’s constant rules
wp phpcm add MY_KEY ...)When WP-CLI is available, the plugin registers a phpcm command suite that mirrors the admin UI:
wp phpcm list [--active] [--inactive] [--type=] [--search=] [--format=] — list managed constantswp phpcm get — show a single constant (supports --field=)wp phpcm add [] [--type=] [--description=] [--inactive] [--porcelain] — create a constant (value can be - to read from stdin)wp phpcm update [--value=] [--type=] [--description=] [--active|--inactive] — update fieldswp phpcm delete ... [--yes] — delete one or more by namewp phpcm activate|deactivate|toggle ... — flip active statewp phpcm defined — report whether the constant is currently defined and by whom (this plugin, early-load, or elsewhere like wp-config.php)wp phpcm all-defines [--user-defined] [--search=] — inspect every PHP constant present in the processwp phpcm status — plugin health summary (table, row counts, early-loading state)wp phpcm import [--overwrite] — import CSV (file path or stdin)wp phpcm export [] [--active] [--inactive] [--type=] — write CSV to a file or stdoutwp phpcm early-loading enable|disable|status — manage the must-use plugin that loads constants before all other pluginsRun wp help phpcm for detailed usage, flags, and examples.
The plugin creates a custom table {prefix}phpcm_constants with the following structure:
* id – Primary key (auto-increment)
* name – Constant name (unique, varchar 191)
* value – Constant value (longtext)
* type – Data type (enum: string, integer, float, boolean, null)
* is_active – Whether the constant is loaded (tinyint)
* description – Optional description (text)
* created_at – Creation timestamp (datetime)
* updated_at – Last update timestamp (datetime)
plugins_loaded (priority 1) – Early constant loading for maximum compatibilityadmin_menu – Menu registrationadmin_post_* – Form submission handlingwp_ajax_* – AJAX operationsWP_CLI::add_command('phpcm', ...) – Registers the CLI command when WP-CLI is availableConstants are defined during plugins_loaded with priority 1, ensuring they are available to:
* All theme functions and templates
* Other plugins (unless using higher priority)
* WordPress core hooks like init, wp_loaded, etc.
manage_options (administrators only)This plugin follows WordPress coding standards and best practices:
* PSR-4 autoloading structure
* WordPress database abstraction layer
* Internationalization ready
* WP_List_Table implementation
* Standard WordPress admin UI patterns