You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple [MU plugin](https://codex.wordpress.org/Must_Use_Plugins) for WordPress that adds functionality that I use on web site projects.
8
+
A simple [MU plugin](https://codex.wordpress.org/Must_Use_Plugins) for WordPress that adds functionality that I use on web site projects, including a [configuration registry](#getting-configuration-values).
9
+
10
+
-[Installation](#installation)
11
+
-[Configuration](#configuration)
12
+
-[Features](#features)
13
+
-[Environment Filter](#environment-filter)
14
+
-[Action Hook](#action-hook)
15
+
-[Shortcodes](#shortcodes)
9
16
10
17
## Installation
11
18
12
19
Simply copy the `common-toolkit.php` file to your `wp-content/mu-plugins` directory (create one if it does not exist).
|`environment`| Environment of current instance (ex: 'production', 'development', 'staging') | string | "production" |
24
-
|`disable_emojis`| Remove support for emojis | bool | false |
25
-
|`admin_bar_color`| Change admin bar color in current environment | string |_null_|
26
-
|`script_attributes`| Enable support for [additional attributes](#add-attributes-to-enqueued-scripts) to script tags via wp_enqueue_script() | bool | flase |
27
-
|`shortcodes`| Enable custom [shortcodes](#shortcodes) created by this class | bool | false |
|`feed_links`| Include RSS feed links in page head | bool | true |
41
+
|`heartbeat`| Modify or disable the WordPress heartbeat. Set to integer to change, `false` to disable | bool/int | null |
42
+
|`hide_login_errors`| Replaces login errors with generic "Login failed" text rather than specific reason | bool/string | null |
43
+
|`meta_generator`| Enable or change meta generator tags in page head and RSS feeds | bool/string | false |
44
+
|`script_attributes`| Enable support for [additional attributes](#add-attributes-to-enqueued-scripts) to script tags via wp_enqueue_script() | bool | flase |
45
+
|`shortcodes`| Enable custom [shortcodes](#shortcodes) created by this class | bool | false |
46
+
|`windows_live_writer`| Enable [Windows Live Writer](https://is.gd/Q6KjEQ) support | bool | true |
32
47
33
48
### Example
34
49
35
-
Add to your `wp-config.php`:
50
+
#### Via Configuration File (PHP 5.6 or higher)
51
+
52
+
This is the preferred method if you wish to avoid having a complex array in your `wp-config.php`:
53
+
54
+
```php
55
+
// Load configuration from a file in webroot.
56
+
define( 'CTK_CONFIG', 'sample-config.json' );
57
+
58
+
// Load configuration from a file off of the parent directory of webroot
If your WordPress Instance has caching enabled, you can configure this plugin to cache the contents of your configuration JSON file with a constant in `wp-config.php`:
75
+
76
+
```php
77
+
define( 'CTK_CACHE_EXPIRE', 120 ); // In seconds
78
+
```
79
+
80
+
### Getting Configuration Values
81
+
82
+
You can use the `ctk_config` filter to retrieve values from the config registry (including custom). Using [sample-config.json](https://github.com/dmhendricks/wordpress-mu-common-toolkit/blob/master/sample-config.json) as an example:
// Get entire config registry as associative array
95
+
$config = apply_filter( 'ctk_config', null );
96
+
```
97
+
98
+
You can add any variable you want to make available to your site's themes and plugins.
99
+
41
100
## Features
42
101
43
102
### WordPress Environment
44
103
104
+
You can set your instance environment using the following methods (in order of precedence; defaults to "production" if not set using any of the following methods):
105
+
106
+
#### 1. Define a Constant in `wp-config.php`
107
+
108
+
```php
109
+
define( 'WP_ENV', 'staging' );
110
+
```
111
+
112
+
If you wish to use a different constant name, you can set the `environment_constant` in the config:
You can also pass `is_production` to determine if we're currently in production more. It compares the value of your environment (defined above) with the value of `common_toolkit/environment_production` (which defaults to "production"). In this way, you can set your production label/string value to whatever you like.
205
+
206
+
Determining if in production mode using **defaults**:
As noted above, you can change the string comparison of what is considered production in config. For example, if you wanted to use "live" instead of "production":
This special filter value is provided solely for convenience. You may, of course, do a manual comparison:
231
+
232
+
```php
233
+
if( getenv( 'WP_ENV' ) == 'production' ) { // Replace variable with value of `environment_constant`, if set
234
+
// Do something intended only for production
235
+
} else {
236
+
// Do something else
237
+
}
238
+
```
239
+
240
+
241
+
## Action Hook
242
+
243
+
If you want to perform some logic only if this script is loaded, you can use the `common_toolkit_loaded` action hook (which executes during the [init](https://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request) phase).
244
+
245
+
```php
246
+
add_action( 'common_toolkit_loaded', function() {
247
+
// Do something if common toolkit is loaded ...
248
+
var_dump( apply_filters( 'ctk_config', null ) );
249
+
});
250
+
```
251
+
95
252
## Shortcodes
96
253
97
254
### `[get_datetime]`
@@ -111,23 +268,4 @@ Current date/time: [get_datetime]
111
268
112
269
See PHP's [`date()`](https://php.net/date) function for formatting options.
0 commit comments