devgeniem/wp-readonly-options
Composer 安装命令:
composer require devgeniem/wp-readonly-options
包简介
Predefine WordPress options in your code and force get_option() results.
README 文档
README
WP Plugin: Readonly Options
Have you ever wanted to set all your options as define('PLUGIN_OPTION','some_value') in wp_config.php?
Sometimes you need to use 3rd party plugins that only gives you those options in admin pages and GUI. And now you can't use git to version control your settings as you would love to do.
This plugin helps you to set all your settings in your code and doesn't force you to go over to admin pages.
How it works
It works by allowing you to force the results of get_option() to your predefined values.
This also adds tiny amount if javascript into admin pages so that it can set readonly attributes to your options: <input readonly>.
This makes it easier for the users to understand that these options can't be changed.
This only works in php7.0 version or better since we use arrays when defining constants. We also like to use scalar type hintings. Sorry legacy projects :(
Installation
Prefered installation is with composer:
{
"require": {
"devgeniem/wp-readonly-options": "^1.1"
},
"extra": {
"installer-paths": {
"web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
},
}
}
Code Example
My options page looks so empty and lonely:
I'll look up the keys from /wp-admin/options.php and I see that they are sm_bucket and sm_key_json.
You can also see the names by using Google Chrome inspector. Key name is same as input element ID.
I can use those keys with WP_READONLY_OPTIONS and I add the following code to my wp-config.php:
php7.0
define( 'WP_READONLY_OPTIONS', array( 'sm_bucket' => 'my-bucket.example.com' 'sm_key_json' => '{ "type": "service_account", "project_id": "XXXXXXXXXXXXXXXXXXXXXXX", "private_key_id": "XXXXXXXXXXXXXXXXXXXX", "private_key": "-----BEGIN PRIVATE KEY-----\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -----END PRIVATE KEY----- }' ));
php5.X
define( 'WP_READONLY_OPTIONS', serialize( array( 'sm_bucket' => 'my-bucket.example.com' 'sm_key_json' => '{ "type": "service_account", "project_id": "XXXXXXXXXXXXXXXXXXXXXXX", "private_key_id": "XXXXXXXXXXXXXXXXXXXX", "private_key": "-----BEGIN PRIVATE KEY-----\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -----END PRIVATE KEY----- }' )));
Afterwise I can see the values in readonly mode:
Configuration
Disables readonly attribute setter Javascript hack. It might be incompatible with something.
define('WP_READONLY_OPTIONS_NO_JS',true);
License
GPLv2
Maintainers
devgeniem/wp-readonly-options 适用场景与选型建议
devgeniem/wp-readonly-options 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60.65k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2016 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「wordpress」 「option」 「wp」 「force」 「must use」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 devgeniem/wp-readonly-options 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 devgeniem/wp-readonly-options 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 devgeniem/wp-readonly-options 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Console Configuration Helper implementation.
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Maybe for PHP
Rust like enum Result and Option.
统计信息
- 总下载量: 60.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 28
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2016-08-13


