3
3
* Plugin Name: Common Toolkit
4
4
* Plugin URI: https://github.com/dmhendricks/wordpress-mu-common-toolkit/
5
5
* Description: A must use (MU) plugin for WordPress that contains helper functions and snippets.
6
- * Version: 0.8 .0
6
+ * Version: 0.9 .0
7
7
* Author: Daniel M. Hendricks
8
8
* Author URI: https://www.danhendricks.com/
9
9
*/
12
12
class CommonToolkit {
13
13
14
14
private static $ instance ;
15
- private static $ version = '0.8 .0 ' ;
15
+ private static $ version = '0.9 .0 ' ;
16
16
private static $ cache = [ 'key ' => 'config_registry ' , 'group ' => 'common_toolkit ' ];
17
17
protected static $ config = [];
18
18
protected static $ environment = [];
@@ -31,7 +31,7 @@ final public static function init() {
31
31
if ( is_array ( CTK_CONFIG ) ) {
32
32
self ::$ config ['common_toolkit ' ] = CTK_CONFIG ;
33
33
} else if ( is_string ( CTK_CONFIG ) ) {
34
- self ::$ config = self ::get_cache_object ( $ cache [ 'key ' ], function () {
34
+ self ::$ config = self ::get_cache_object ( self :: $ cache [ 'key ' ], function () {
35
35
return @json_decode ( file_get_contents ( realpath ( ABSPATH . CTK_CONFIG ) ), true ) ?: [];
36
36
});
37
37
}
@@ -240,7 +240,7 @@ public static function ctk_environment_filter( $key = null ) {
240
240
*
241
241
* @since 0.8.0
242
242
*/
243
- public function disable_emojis () {
243
+ public static function disable_emojis () {
244
244
245
245
remove_action ( 'admin_print_styles ' , 'print_emoji_styles ' );
246
246
remove_action ( 'wp_head ' , 'print_emoji_detection_script ' , 7 );
@@ -262,7 +262,7 @@ public function disable_emojis() {
262
262
*
263
263
* @since 0.9.0
264
264
*/
265
- public function disable_updates () {
265
+ public static function disable_updates () {
266
266
267
267
global $ wp_version ;
268
268
return (object ) array ( 'last_checked ' => time (), 'version_checked ' => $ wp_version );
@@ -274,7 +274,7 @@ public function disable_updates() {
274
274
*
275
275
* @since 0.9.0
276
276
*/
277
- public function disable_search ( $ query , $ error = true ) {
277
+ public static function disable_search ( $ query , $ error = true ) {
278
278
279
279
if ( is_search () ) {
280
280
@@ -294,7 +294,7 @@ public function disable_search( $query, $error = true ) {
294
294
*
295
295
* @since 0.8.0
296
296
*/
297
- public function change_admin_bar_color () {
297
+ public static function change_admin_bar_color () {
298
298
299
299
printf ( '<style type="text/css">#wpadminbar { background: %s; ?> !important; }</style> ' , CTK_CONFIG ['admin_bar_color ' ] );
300
300
@@ -310,7 +310,7 @@ public function change_admin_bar_color() {
310
310
* @see http://php.net/manual/en/domdocument.loadhtml.php
311
311
* @see http://php.net/manual/en/domelement.setattribute.php
312
312
*/
313
- public function defer_async_scripts ( $ tag , $ handle , $ src ) {
313
+ public static function defer_async_scripts ( $ tag , $ handle , $ src ) {
314
314
315
315
// Return if no modification needed
316
316
if ( !strpos ( $ src , '#async ' ) && !strpos ( $ src , '#defer ' ) && !strpos ( $ src , 'custom_attribute ' ) ) return $ tag ;
@@ -419,7 +419,7 @@ public static function set_default_atts( $pairs, $atts ) {
419
419
* @since 0.9.0
420
420
* @see https://codex.wordpress.org/Function_Reference/wp_heartbeat_settings
421
421
*/
422
- public function modify_heartbeat ( $ settings ) {
422
+ public static function modify_heartbeat ( $ settings ) {
423
423
424
424
$ heartbeat = intval ( self ::get_config ( 'common_toolkit/heartbeat ' ) );
425
425
if ( !$ heartbeat ) return $ settings ;
@@ -435,7 +435,7 @@ public function modify_heartbeat( $settings ) {
435
435
* @since 0.9.0
436
436
* @see https://codex.wordpress.org/Plugin_API/Filter_Reference/login_errors#Example
437
437
*/
438
- public function set_login_errors ( $ error ) {
438
+ public static function set_login_errors ( $ error ) {
439
439
440
440
global $ errors ;
441
441
$ err_codes = $ errors ->get_error_codes ();
@@ -463,7 +463,7 @@ public function set_login_errors( $error ) {
463
463
*
464
464
* @since 0.9.0
465
465
*/
466
- public function admin_bar_howdy ( $ wp_admin_bar ) {
466
+ public static function admin_bar_howdy ( $ wp_admin_bar ) {
467
467
468
468
$ message = trim ( self ::get_config ( 'common_toolkit/howdy_message ' ) ) ?: '' ;
469
469
$ my_account = $ wp_admin_bar ->get_node ( 'my-account ' );
@@ -479,7 +479,7 @@ public function admin_bar_howdy( $wp_admin_bar ) {
479
479
*
480
480
* @since 0.8.0
481
481
*/
482
- public function modify_meta_generator_tags ( $ current , $ type ) {
482
+ public static function modify_meta_generator_tags ( $ current , $ type ) {
483
483
484
484
$ meta_generator = self ::get_config ( 'common_toolkit/meta_generator ' );
485
485
switch ( true ) {
@@ -506,7 +506,7 @@ public function modify_meta_generator_tags( $current, $type ) {
506
506
* @since 0.8.0
507
507
* @see https://php.net/date
508
508
*/
509
- public function shortcode_get_datetime ( $ atts ) {
509
+ public static function shortcode_get_datetime ( $ atts ) {
510
510
511
511
$ atts = shortcode_atts ( [
512
512
'format ' => get_option ( 'date_format ' ) . ' ' . get_option ( 'time_format ' )
@@ -536,19 +536,19 @@ private function strip_extra_dom_elements( $element ) {
536
536
* @return mixed
537
537
* @since 0.9.0
538
538
*/
539
- public function get_cache_object ( $ key , $ callback , $ force = false ) {
539
+ public static function get_cache_object ( $ key , $ callback , $ force = false ) {
540
540
541
541
if ( $ force ) return $ callback ();
542
542
543
543
$ cache_expire = defined ( 'CTK_CACHE_EXPIRE ' ) && is_int ( CTK_CACHE_EXPIRE ) ? intval ( CTK_CACHE_EXPIRE ) : false ;
544
544
if ( !is_int ( $ cache_expire ) ) return $ callback ();
545
545
546
- $ result = unserialize ( wp_cache_get ( $ key , $ cache [ 'group ' ], false , $ cache_hit ) );
546
+ $ result = unserialize ( wp_cache_get ( $ key , self :: $ cache [ 'group ' ], false , $ cache_hit ) );
547
547
548
548
if ( !$ cache_hit ) {
549
549
550
550
$ result = $ callback ();
551
- wp_cache_set ( $ key , serialize ( $ result ), $ cache [ 'group ' ], $ cache_expire );
551
+ wp_cache_set ( $ key , serialize ( $ result ), self :: $ cache [ 'group ' ], $ cache_expire );
552
552
553
553
} else {
554
554
@@ -565,9 +565,9 @@ public function get_cache_object( $key, $callback, $force = false ) {
565
565
*
566
566
* @since 0.8.0
567
567
*/
568
- public function delete_config_cache () {
568
+ public static function delete_config_cache () {
569
569
570
- wp_cache_delete ( $ cache [ 'group ' ], $ cache [ 'group ' ] );
570
+ wp_cache_delete ( self :: $ cache [ 'group ' ], self :: $ cache [ 'group ' ] );
571
571
572
572
}
573
573
@@ -582,4 +582,4 @@ public function __toString() {
582
582
583
583
}
584
584
585
- CommonToolkit::init ();
585
+ CommonToolkit::init ();
0 commit comments