Linux 软件免费装
Banner图

PHP Constants Manager

开发者 cartpauj
更新时间 2026年4月16日 13:46
PHP版本: 7.4 及以上
WordPress版本: 6.9
版权: GPLv2 or later
版权网址: 版权信息

标签

admin php configuration constants defines

下载

1.1.4 1.1.5 1.2.0

详情介绍:

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! Key Features Understanding Predefined Constants The plugin intelligently detects when constants are already defined by WordPress core, other plugins, or your theme: Use Cases WP-CLI Commands When WP-CLI is available, the plugin registers a phpcm command suite that mirrors the admin UI: Run wp help phpcm <subcommand> for detailed usage, flags, and examples.

安装:

  1. Upload the php-constants-manager folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Navigate to 'PHP Constants' in the WordPress admin menu
  4. Start managing your constants!
The plugin will automatically create the necessary database table upon activation.

屏幕截图:

  • "All Constants" page displaying every constant in the WordPress installation
  • Add new constant form with data type selection and description field
  • Settings page with Early Loading option for must-use plugin creation
  • Import/Export page with CSV upload and download functionality
  • Screen Options panel for customizing table display preferences
  • Help page with comprehensive documentation and best practices

常见问题:

Is it safe to manage constants this way?

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

What's the difference between "My Constants" and "All Constants"?

"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.

What happens if a constant is already defined (shows as "Predefined")?

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.

Can I deactivate constants without deleting them?

Yes! Each constant has an active/inactive toggle. Inactive constants remain in the database but aren't loaded into PHP.

When are my constants available in my code?

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.

Can I customize how the tables are displayed?

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

How do I know if my constant is working?

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').

Why can't I override WordPress core constants?

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.

How do I import/export constants?

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.

What CSV format should I use for importing?

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

Will importing overwrite existing constants?

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.

How does value validation work?

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.

What happens if my CSV import has errors?

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.

Can I manage constants from WP-CLI?

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>.

What is Early Loading and when should I use it?

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.

更新日志:

1.2.0 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.0