44 * Plugin URI: https://github.com/WordPress-Phoenix/wordpress-rest-cache
55 * Description: A solution to caching REST data calls without relying on transients or wp_options tables. Note: for multisite "Network Activate", table may need manually created before activation.
66 * Author: scarstens, mlteal
7- * Version: 1.1.0
7+ * Version: 1.1.1
88 * Author URI: http://github.com/scarstens
99 * License: GPL V2
1010 * Text Domain: rest_cache
@@ -39,66 +39,65 @@ class WP_Rest_Cache {
3939 static $ table = 'rest_cache ' ; // the prefix is appended once we have access to the $wpdb global
4040 static $ columns = 'rest_md5,rest_domain,rest_path,rest_response,rest_expires,rest_last_requested,rest_tag,rest_to_update ' ;
4141 static $ default_expires = 600 ; // defaults to 10 minutes, this is always in seconds
42-
42+
4343 /**
4444 * Construct the plugin object
4545 *
4646 * @since 0.1
4747 */
4848 public function __construct () {
4949 $ this ->installed_dir = plugin_dir_path ( __FILE__ );
50-
50+
5151 // hook can be used by mu plugins to modify plugin behavior after plugin is setup
5252 do_action ( get_called_class () . '_preface ' , $ this );
53-
53+
5454 // configure and setup the plugin class variables
5555 $ this ->configure_defaults ();
56-
56+
5757 // define globals used by the plugin including bloginfo
5858 $ this ->defines_and_globals ();
59-
59+
6060 // Loads the /inc/ autoloader
6161 $ this ->load_classes ();
62-
62+
63+ if ( ! defined ( 'NO_WP_REST_CACHE ' ) ) {
64+ if ( class_exists ( 'WRC_Caching ' ) ) {
65+ WRC_Caching::init ();
66+ }
67+ }
6368 // initialize plugin during init
6469 add_action ( 'init ' , array ( $ this , 'init ' ), 5 );
65-
6670 // init for use with logged in users, see this::authenticated_init for more details
6771 add_action ( 'init ' , array ( $ this , 'authenticated_init ' ) );
68-
72+
6973 // hook can be used by mu plugins to modify plugin behavior after plugin is setup
7074 do_action ( get_called_class () . '_setup ' , $ this );
71-
75+
7276 } // END public function __construct
73-
77+
7478 /**
7579 * Initialize the plugin - for public (front end)
7680 *
7781 * @since 0.1
7882 * @return void
7983 */
8084 public function init () {
81-
85+
8286 do_action ( get_called_class () . '_before_init ' );
83- if ( ! defined ( 'NO_WP_REST_CACHE ' ) ) {
84- if ( class_exists ( 'WRC_Caching ' ) ) {
85- WRC_Caching::init ();
86- }
87-
88- if ( class_exists ( 'WRC_Cron ' ) ) {
89- WRC_Cron::init ();
90- }
87+
88+ if ( class_exists ( 'WRC_Cron ' ) ) {
89+ WRC_Cron::init ();
9190 }
92-
91+
9392 if ( class_exists ( 'WRC_Filters ' ) ) {
9493 WRC_Filters::init ();
9594 }
9695
9796 add_action ('wp_ajax_wrc-ajax-run ' , array ('WRC_Ajax ' , 'run ' ));
98-
97+
9998 do_action ( get_called_class () . '_after_init ' );
10099 }
101-
100+
102101 /**
103102 * Initialize the plugin - for admin (back end)
104103 * You would expected this to be handled on action admin_init, but it does not properly handle
@@ -114,17 +113,17 @@ public function authenticated_init() {
114113 WRC_Admin::init ();
115114 }
116115 }
117-
116+
118117 /**
119118 * Activate the plugin
120119 *
121120 * @since 0.1
122121 * @return void
123122 */
124123 public static function activate () {
125-
124+
126125 // create our table if it doesn't already exist
127-
126+
128127 $ sql = "CREATE TABLE " . REST_CACHE_TABLE . " (
129128 `rest_last_requested` date NOT NULL,
130129 `rest_expires` datetime DEFAULT NULL,
@@ -142,27 +141,27 @@ public static function activate() {
142141 KEY `rest_tag` (`rest_tag`(191)),
143142 KEY `rest_to_update` (`rest_to_update`)
144143) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; " ;
145-
144+
146145 require_once ( ABSPATH . 'wp-admin/includes/upgrade.php ' );
147146 dbDelta ( $ sql );
148-
147+
149148 } // END public static function activate
150-
149+
151150 /**
152151 * Deactivate the plugin
153152 *
154153 * @since 0.1
155154 * @return void
156155 */
157156 public static function deactivate () {
158-
157+
159158 /*
160159 * Do not delete site options on deactivate. Usually only things in here will be related to
161160 * cache clearing like updating permalinks since some may no longer exist
162161 */
163-
162+
164163 } // END public static function deactivate
165-
164+
166165 /**
167166 * Loads PHP files in the includes folder
168167 *
@@ -173,18 +172,18 @@ protected function load_classes() {
173172 // this class self-instantiates from within the file
174173 require_once ( 'class-wrc-autoloader.php ' );
175174 }
176-
175+
177176 protected function defines_and_globals () {
178177 global $ wpdb ;
179178 define ( 'REST_CACHE_DB_PREFIX ' , $ wpdb ->base_prefix );
180179 define ( 'REST_CACHE_TABLE ' , REST_CACHE_DB_PREFIX . static ::$ table );
181180 }
182-
181+
183182 protected function configure_defaults () {
184183 $ this ->installed_dir = dirname ( __FILE__ );
185184 $ this ->installed_url = plugins_url ( '/ ' , __FILE__ );
186185 }
187-
186+
188187 /**
189188 * This function is used to make it quick and easy to programatically do things only on your development
190189 * domains. Typical usage would be to change debugging options or configure sandbox connections to APIs.
@@ -193,7 +192,7 @@ public static function is_dev() {
193192 // catches dev.mydomain.com, mydomain.dev, wpengine staging domains and mydomain.staging
194193 return (bool ) ( stristr ( WP_NETWORKURL , '.dev ' ) || stristr ( WP_NETWORKURL , '.wpengine ' ) || stristr ( WP_NETWORKURL , 'dev. ' ) || stristr ( WP_NETWORKURL , '.staging ' ) );
195194 }
196-
195+
197196 } // END class
198197} // END if(!class_exists())
199198
@@ -204,7 +203,7 @@ public static function is_dev() {
204203 // Installation and un-installation hooks
205204 register_activation_hook ( __FILE__ , array ( 'WP_Rest_Cache ' , 'activate ' ) );
206205 register_deactivation_hook ( __FILE__ , array ( 'WP_Rest_Cache ' , 'deactivate ' ) );
207-
206+
208207 // instantiate the plugin class, which should never be instantiated more then once
209208 global $ WP_Rest_Cache ;
210209 $ WP_Rest_Cache = new WP_Rest_Cache ();
0 commit comments