0+
May 28, 2026
June 24, 2025
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=<type>] [--search=<term>] [--format=<format>] — list managed constantswp phpcm get <name> — show a single constant (supports --field=<field>)wp phpcm add <name> [<value>] [--type=<type>] [--description=<text>] [--inactive] [--porcelain] — create a constant (value can be - to read from stdin)wp phpcm update <name> [--value=<value>] [--type=<type>] [--description=<text>] [--active|--inactive] — update fieldswp phpcm delete <name>... [--yes] — delete one or more by namewp phpcm activate|deactivate|toggle <name>... — flip active statewp phpcm defined <name> — 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=<term>] — inspect every PHP constant present in the processwp phpcm status — plugin health summary (table, row counts, early-loading state)wp phpcm import <file|-> [--overwrite] — import CSV (file path or stdin)wp phpcm export [<file>] [--active] [--inactive] [--type=<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 <subcommand> 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
php-constants-manager folder to the /wp-content/plugins/ directoryThe plugin will automatically create the necessary database table upon activation.
Yes! The plugin includes multiple security measures:
– Only administrators can access the interface
– All inputs are sanitized and validated
– Nonce verification on all actions
– Constants are checked before defining to prevent conflicts
“My Constants” shows only the constants you’ve created through this plugin, with full management capabilities. “All Constants” displays every constant defined in your WordPress installation (core, plugins, themes) for auditing and reference purposes.
The plugin checks if constants are already defined before attempting to define them. If a constant exists, it will show as “Predefined” in the list. Your definition is saved but won’t take effect due to PHP’s rule that constants cannot be redefined. This commonly happens with WordPress core constants or those defined in wp-config.php.
Yes! Each constant has an active/inactive toggle. Inactive constants remain in the database but aren’t loaded into PHP.
By default, constants are loaded during the plugins_loaded action with priority 1, making them available to:
– All theme code (themes load after plugins)
– Most other plugins (unless they use higher priority)
– WordPress hooks like init, wp_loaded, etc.
For earlier loading, enable the “Early Loading” option in Settings, which creates a must-use plugin that loads constants before any regular plugins.
Yes! Use the “Screen Options” button in the top-right corner to:
– Control how many constants are displayed per page (5, 10, 20, 50, 100+)
– Show/hide specific columns in both tables
– Your preferences are saved automatically
Check the “Predefined” column in “My Constants”. If it shows “No” and the status is “Active”, your constant is working. You can also test it in your code using defined('MY_CONSTANT').
This is a PHP limitation, not a plugin restriction. Constants cannot be redefined once set. Since WordPress core constants are defined very early (in wp-config.php or during WordPress bootstrap), they cannot be overridden by plugins.
Go to the “Import/Export” page in the plugin menu. You can export all your constants to a CSV file for backup or migration purposes. To import, upload a CSV file with the required format. The CSV must include at minimum: Name, Value, Type columns. Optional columns are Active and Description.
Your CSV should have these columns:
– Name (required): Uppercase constant name, e.g., “MY_CONSTANT”
– Value (required): The constant value
– Type (required): One of: string, integer, float, boolean, null
– Active (optional): 1 for active, 0 for inactive (defaults to 1)
– Description (optional): Text description
Example CSV:
Name,Value,Type,Active,Description
MY_API_KEY,abc123,string,1,API key for service
MAX_POSTS,25,integer,1,Maximum posts per page
DEBUG_MODE,true,boolean,0,Enable debug output
No, the import process skips constants that already exist in your database. Only new constants are added. You’ll receive a detailed report showing what was imported, skipped, and any errors.
The plugin validates that constant values match their selected type:
– Integer: Must be whole numbers (42, -10, 0) – decimals are rejected
– Float: Must be valid numbers (3.14, -2.5, 10) – text is rejected
– Boolean: Must be true, false, 1, 0, yes, no, on, or off (case-insensitive)
– String: Any value accepted, including quotes and special characters
– NULL: Value field is automatically disabled and cleared
Both the form interface and CSV import perform this validation with detailed error messages.
The import will show exactly what went wrong with specific line numbers and error descriptions. For example:
– “Line 5: Missing required columns (need at least Name, Value, Type)”
– “Line 12: Invalid boolean value ‘maybe’ (Constant: DEBUG_MODE)”
– “Line 15: Invalid integer value ‘3.14’ (Constant: MAX_ITEMS)”
This helps you fix your CSV file and re-import successfully.
Yes. When WP-CLI is installed the plugin registers a wp phpcm command suite that covers every operation available in the admin UI — create/read/update/delete, toggle active state, CSV import/export, and the early-loading toggle. A few quick examples:
wp phpcm add MY_API_KEY "abc123" --description="External API key"
wp phpcm list --active --type=boolean --format=json
wp phpcm defined WP_DEBUG (reports whether it's defined by this plugin, early-load, or wp-config.php)
wp phpcm export backup.csv --active
cat constants.csv | wp phpcm import - --overwrite
wp phpcm early-loading enable
Commands accept stdin via - for add/update/import. The full list and per-command help is available via wp help phpcm and wp help phpcm <subcommand>.
Early Loading creates a must-use plugin file that loads your constants before any regular plugins. This ensures maximum compatibility when other plugins need your constants during their initialization.
Enable Early Loading if:
– Other plugins need to access your constants during their setup
– You’re defining configuration constants that affect plugin behavior
– You want maximum compatibility across all plugins
Normal loading is fine if:
– Your constants are only used by themes or late-loading code
– You’re not experiencing any compatibility issues
– You prefer to minimize files in the mu-plugins directory
The Early Loading option is available in the Settings page and automatically manages the must-use plugin file creation and removal.
wp phpcm list|get|add|update|delete|activate|deactivate|toggle|defined|all-defines|status|import|export|early-loadingincludes/phpcm-helpers.php — the generated must-use loader now reuses them instead of duplicating logicPHPCM_Import_Export so the admin UI and CLI share the same parser and writer