| 开发者 | cartpauj |
|---|---|
| 更新时间 | 2026年4月16日 13:46 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 6.9 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
wp phpcm ... — ideal for automation, CI/CD, and multi-site provisioningwp phpcm add MY_KEY ...)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 pluginswp help phpcm <subcommand> for detailed usage, flags, and examples.
php-constants-manager folder to the /wp-content/plugins/ directoryYes! The plugin includes multiple security measures:
"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:
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:
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,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:
The import will show exactly what went wrong with specific line numbers and error descriptions. For example:
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:
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