定制 devgeniem/wp-readonly-options 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devgeniem/wp-readonly-options

最新稳定版本:1.2.2

Composer 安装命令:

composer require devgeniem/wp-readonly-options

包简介

Predefine WordPress options in your code and force get_option() results.

README 文档

README

geniem-github-banner

WP Plugin: Readonly Options

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

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:

Before

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:

After

Configuration

Disables readonly attribute setter Javascript hack. It might be incompatible with something.

define('WP_READONLY_OPTIONS_NO_JS',true);

License

GPLv2

Maintainers

@onnimonni

@villepietarinen

统计信息

  • 总下载量: 55.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 10
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2016-08-13