
內容簡介
**總結**
PHP Constants Manager 為 WordPress 提供安全且使用者友善的界面,用以管理 PHP 常數。不再需編輯 wp-config.php 或主題檔案以新增或修改常數!
**問題與答案:**
1. PHP Constants Manager 提供了哪些主要功能?
- 完整的常數管理:從 WordPress 管理員中建立、讀取、更新和刪除 PHP 常數。
- 雙視圖系統:「我的常數」用於自定義常數,「所有常數」可查看 WordPress 安裝中的所有常數。
- 原生 WordPress 介面:使用 WP_List_Table 構建,具有排序、搜索和批次操作功能等。
- 多種數據類型:支援String、Integer、Float、Boolean和NULL等常數類型,具有嚴格的驗證。
- 即時驗證:表單字段與所選類型的值進行驗證,並提供即時反饋。
2. PHP Constants Manager 如何處理已定義的常數?
- 若常數是獨一無二的,將正常工作,稱為「未預先定義」。
- 若常數已在其他地方定義,儲存您的定義,但不會覆蓋現有值,遵守 PHP 常數規則。
3. 使用情境有哪些?
- 管理特定環境配置。
- 在不需編輯文件的情況下切換偵錯常數。
- 安全地儲存 API 密鑰和配置值。
- 為不同環境創建後備常數。
- 利用內建描述文件常數目的。
- 審核 WordPress 安裝中的所有常數。
- 備份常數至 CSV 檔案以在網站間遷移。
- 從格式良好的 CSV 檔案中批量導入常數。
這些問題及答案將幫助您更了解 PHP Constants Manager 外掛的功能和應用情境。
外掛標籤
開發者團隊
原文外掛簡介
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
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
Developer Information
Database Schema
The plugin creates a custom table {prefix}pcm_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
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
