
內容簡介
PHP Constants Manager 提供安全且使用者友好的介面,讓使用者能夠在 WordPress 中輕鬆管理 PHP 常數,無需編輯 wp-config.php 或佈景主題檔案。
【主要功能】
• 完整的常數管理:可創建、讀取、更新及刪除 PHP 常數
• 雙視圖系統:自訂常數與所有常數的檢視
• 原生 WordPress UI:具排序、搜尋及批次操作功能
• 多種資料類型:支援字串、整數、浮點數、布林及 NULL
• 即時驗證:表單欄位即時驗證選擇的類型
• 衝突檢測:顯示常數已被定義的視覺指示
外掛標籤
開發者團隊
原文外掛簡介
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
Complete Constant Management: Create, read, update, and delete PHP constants from the WordPress admin
Dual View System: “My Constants” for your custom constants and “All Constants” to view every constant in your WordPress installation
Native WordPress UI: Built using WP_List_Table with sorting, searching, and bulk actions
Multiple Data Types: Support for String, Integer, Float, Boolean, and NULL constant types with strict validation
Real-time Validation: Form fields validate values against selected type with immediate feedback
Active/Inactive States: Toggle constants on/off without deleting them
Conflict Detection: Visual indicators show when constants are already defined elsewhere (predefined)
Screen Options: Customize table views with adjustable items per page and column visibility controls
Early Loading Option: Optional must-use plugin creation for loading constants before other plugins
Load Order Awareness: Constants loaded during plugins_loaded action (priority 1) for broad compatibility
Comprehensive Help: Built-in help system with detailed documentation and best practices
Administrator Only: Secure access restricted to users with manage_options capability
Database Storage: Constants stored safely in a custom database table with full audit trail
Import/Export: Backup and migrate constants using CSV files with detailed error reporting
WP-CLI Integration: Manage constants, import/export CSV, and toggle early loading from the terminal via wp phpcm ... — ideal for automation, CI/CD, and multi-site provisioning
Understanding Predefined Constants
The 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
Use Cases
Manage environment-specific configuration
Toggle debug constants without file editing
Store API keys and configuration values securely
Create fallback constants for different environments
Document constant purposes with built-in descriptions
Audit all constants in your WordPress installation
Backup constants to CSV files for migration between sites
Import constants in bulk from properly formatted CSV files
Automate site setup and deployment pipelines with WP-CLI (wp phpcm add MY_KEY ...)
WP-CLI Commands
When WP-CLI is available, the plugin registers a phpcm command suite that mirrors the admin UI:
wp phpcm list [--active] [--inactive] [--type=
wp phpcm get
wp phpcm add
wp phpcm update
wp phpcm delete
wp phpcm activate|deactivate|toggle
wp phpcm defined
wp phpcm all-defines [--user-defined] [--search=
wp phpcm status — plugin health summary (table, row counts, early-loading state)
wp phpcm import
wp phpcm export [
wp phpcm early-loading enable|disable|status — manage the must-use plugin that loads constants before all other plugins
Run wp help phpcm
Developer Information
Database Schema
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)
WordPress Hooks Used
plugins_loaded (priority 1) – Early constant loading for maximum compatibility
admin_menu – Menu registration
admin_post_* – Form submission handling
wp_ajax_* – AJAX operations
WP_CLI::add_command('phpcm', ...) – Registers the CLI command when WP-CLI is available
Load Order & Compatibility
Constants 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.
Security Implementation
Capability requirement: manage_options (administrators only)
Nonce verification on all form submissions and AJAX requests
SQL injection prevention with prepared statements
Input sanitization using WordPress core functions
Output escaping for all displayed data
Code Standards
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
