2017 © Pedro Peláez
 

wordpress-muplugin wp-readonly-options

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

image

devgeniem/wp-readonly-options

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

  • Sunday, January 22, 2017
  • by devgeniem
  • Repository
  • 8 Watchers
  • 5 Stars
  • 1,873 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 5 Versions
  • 7 % Grown

The README.md

geniem-github-banner, (*1)

WP Plugin: Readonly Options

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Have you ever wanted to set all your options as define('PLUGIN_OPTION','some_value') in wp_config.php?, (*3)

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., (*4)

This plugin helps you to set all your settings in your code and doesn't force you to go over to admin pages., (*5)

How it works

It works by allowing you to force the results of get_option() to your predefined values., (*6)

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., (*7)

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 :(, (*8)

Installation

Prefered installation is with composer:, (*9)

{
    "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:, (*10)

Before, (*11)

I'll look up the keys from /wp-admin/options.php and I see that they are sm_bucket and sm_key_json., (*12)

You can also see the names by using Google Chrome inspector. Key name is same as input element ID., (*13)

I can use those keys with WP_READONLY_OPTIONS and I add the following code to my wp-config.php:, (*14)

php7.0, (*15)

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, (*16)

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:, (*17)

After, (*18)

Configuration

Disables readonly attribute setter Javascript hack. It might be incompatible with something., (*19)

define('WP_READONLY_OPTIONS_NO_JS',true);

License

GPLv2, (*20)

Maintainers

@onnimonni, (*21)

@villepietarinen, (*22)

The Versions

22/01 2017

dev-master

9999999-dev https://github.com/devgeniem/wp-must-use-options

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

  Sources   Download

GPL-2.0

The Requires

 

wordpress database wp option force must use

22/01 2017

1.2.1

1.2.1.0 https://github.com/devgeniem/wp-must-use-options

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

  Sources   Download

GPL-2.0

The Requires

 

wordpress database wp option force must use

19/09 2016

1.2.0

1.2.0.0 https://github.com/devgeniem/wp-must-use-options

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

  Sources   Download

GPL-2.0

The Requires

 

wordpress database wp option force must use

14/08 2016

1.1.1

1.1.1.0 https://github.com/devgeniem/wp-must-use-options

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

  Sources   Download

GPL-2.0

The Requires

 

wordpress database wp option force must use

13/08 2016

1.1

1.1.0.0 https://github.com/devgeniem/wp-must-use-options

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

  Sources   Download

GPL-2.0

The Requires

 

wordpress database wp option force must use