W3 Total Cache - Version 0.10.2

Version Description

  • Fixed compatibility with wpdb::prepare in WordPress 5.3
Download this release

Release Info

Developer fredericktownes
Plugin Icon 128x128 W3 Total Cache
Version 0.10.2
Comparing to
See all releases

Code changes from version 0.10.1 to 0.10.2

DbCache_Wpdb.php CHANGED
@@ -36,8 +36,12 @@ class DbCache_Wpdb extends DbCache_WpdbBase {
36
 
37
  $processors[] = new DbCache_WpdbInjection();
38
 
39
- $class = __CLASS__;
40
- $o = new $class( $processors );
 
 
 
 
41
 
42
  $next_injection = new _CallUnderlying( $o );
43
 
@@ -53,505 +57,4 @@ class DbCache_Wpdb extends DbCache_WpdbBase {
53
 
54
  return $instance;
55
  }
56
-
57
- private $active_processor_number;
58
- private $active_processor;
59
- private $processors;
60
-
61
- private $debug;
62
- private $request_time_start = 0;
63
-
64
- /*
65
- * @param boolean $call_default_constructor
66
- */
67
- public function __construct( $processors = null ) {
68
- // required to initialize $use_mysqli which is private
69
- parent::__construct( '', '', '', '' );
70
-
71
- // cant force empty parameter list due to wp requirements
72
- if ( !is_array( $processors ) )
73
- throw new Exception( 'called incorrectly, use instance()' );
74
-
75
- $this->processors = $processors;
76
- $this->active_processor = $processors[0];
77
- $this->active_processor_number = 0;
78
-
79
- $c = Dispatcher::config();
80
- $this->debug = $c->get_boolean( 'dbcache.debug' );
81
-
82
- if ( $this->debug )
83
- $this->_request_time_start = microtime( true );
84
- }
85
-
86
- /**
87
- * Called by Root_Loader when all w3tc plugins loaded,
88
- * i.e. later that object instantiated
89
- */
90
- public function on_w3tc_plugins_loaded() {
91
- $o = $this;
92
-
93
- if ( $this->debug ) {
94
- add_action( 'shutdown', array( $o, 'debug_shutdown' ) );
95
- }
96
-
97
- add_filter( 'w3tc_footer_comment', array(
98
- $o, 'w3tc_footer_comment' ) );
99
- add_action( 'w3tc_usage_statistics_of_request', array(
100
- $o, 'w3tc_usage_statistics_of_request' ), 10, 1 );
101
-
102
- }
103
-
104
- public function w3tc_footer_comment( $strings ) {
105
- foreach ( $this->processors as $processor )
106
- $strings = $processor->w3tc_footer_comment( $strings );
107
-
108
- return $strings;
109
- }
110
-
111
- public function debug_shutdown() {
112
- $strings = array();
113
- foreach ( $this->processors as $processor )
114
- $strings = $processor->w3tc_footer_comment( $strings );
115
-
116
- $request_time_total = microtime( true ) - $this->request_time_start;
117
-
118
- $data = sprintf( "\n[%s] [%s] [%s]\n", date( 'r' ),
119
- $_SERVER['REQUEST_URI'], round( $request_time_total, 4 ) ) .
120
- implode( "\n", $strings ) . "\n";
121
- $data = strtr( $data, '<>', '..' );
122
-
123
- $filename = Util_Debug::log_filename( 'dbcache' );
124
- @file_put_contents( $filename, $data, FILE_APPEND );
125
- }
126
-
127
- public function w3tc_usage_statistics_of_request( $storage ) {
128
- foreach ( $this->processors as $processor )
129
- $processor->w3tc_usage_statistics_of_request( $storage );
130
- }
131
-
132
- public function flush_cache( $extras = array() ) {
133
- $v = true;
134
-
135
- foreach ( $this->processors as $processor )
136
- $v &= $processor->flush_cache( $extras );
137
-
138
- return $v;
139
- }
140
-
141
- public function db_connect( $allow_bail = true ) {
142
- if ( empty( $this->dbuser ) ) {
143
- // skip connection - called from constructor
144
- } else
145
- return parent::db_connect( $allow_bail );
146
- }
147
-
148
- /**
149
- * Initializes object after processors configured. Called from instance() only
150
- */
151
- public function initialize() {
152
- return $this->active_processor->initialize();
153
- }
154
-
155
- /**
156
- * Overriten logic of wp_db by processor.
157
- */
158
- public function insert( $table, $data, $format = null ) {
159
- do_action( 'w3tc_db_insert', $table, $data, $format );
160
- return $this->active_processor->insert( $table, $data, $format );
161
- }
162
-
163
- /**
164
- * Overriten logic of wp_db by processor.
165
- */
166
- public function query( $query ) {
167
- return $this->active_processor->query( $query );
168
- }
169
-
170
- public function _escape( $data ) {
171
- return $this->active_processor->_escape( $data );
172
- }
173
-
174
- /**
175
- * Overriten logic of wp_db by processor.
176
- */
177
- public function prepare( $query, $args ) {
178
- $args = func_get_args();
179
- array_shift( $args );
180
-
181
- // If args were passed as an array (as in vsprintf), move them up
182
- if ( isset( $args[0] ) && is_array($args[0]) ) {
183
- $args = $args[0];
184
- }
185
-
186
- return $this->active_processor->prepare( $query, $args );
187
- }
188
-
189
- /**
190
- * Overriten logic of wp_db by processor.
191
- */
192
- public function replace( $table, $data, $format = null ) {
193
- do_action( 'w3tc_db_replace', $table, $data, $format );
194
- return $this->active_processor->replace( $table, $data, $format );
195
- }
196
-
197
- /**
198
- * Overriten logic of wp_db by processor.
199
- */
200
- public function update( $table, $data, $where, $format = null, $where_format = null ) {
201
- do_action( 'w3tc_db_update', $table, $data, $where, $format,
202
- $where_format );
203
- return $this->active_processor->update( $table, $data, $where, $format, $where_format );
204
- }
205
-
206
- /**
207
- * Overriten logic of wp_db by processor.
208
- */
209
- public function delete( $table, $where, $where_format = null ) {
210
- do_action( 'w3tc_db_delete', $table, $where, $where_format );
211
- return $this->active_processor->delete( $table, $where, $where_format );
212
- }
213
-
214
- /**
215
- * Overriten logic of wp_db by processor.
216
- */
217
- public function init_charset() {
218
- return $this->active_processor->init_charset();
219
- }
220
-
221
- /**
222
- * Overriten logic of wp_db by processor.
223
- */
224
- public function set_charset( $dbh, $charset = null, $collate = null ) {
225
- return $this->active_processor->set_charset( $dbh, $charset, $collate );
226
- }
227
-
228
- /**
229
- * Overriten logic of wp_db by processor.
230
- */
231
- public function set_sql_mode( $modes = array() ) {
232
- return $this->active_processor->set_sql_mode( $modes );
233
- }
234
-
235
- /**
236
- * Overriten logic of wp_db by processor.
237
- */
238
- public function flush() {
239
- return $this->active_processor->flush();
240
- }
241
-
242
- /**
243
- * Overriten logic of wp_db by processor.
244
- */
245
- public function check_database_version( $dbh_or_table = false ) {
246
- return $this->active_processor->check_database_version( $dbh_or_table );
247
- }
248
-
249
- /**
250
- * Overriten logic of wp_db by processor.
251
- */
252
- public function supports_collation( $dbh_or_table = false ) {
253
- return $this->active_processor->supports_collation( $dbh_or_table );
254
- }
255
-
256
- /**
257
- * Overriten logic of wp_db by processor.
258
- */
259
- public function has_cap( $db_cap, $dbh_or_table = false ) {
260
- return $this->active_processor->has_cap( $db_cap, $dbh_or_table );
261
- }
262
-
263
- /**
264
- * Overriten logic of wp_db by processor.
265
- */
266
- public function db_version( $dbh_or_table = false ) {
267
- return $this->active_processor->db_version( $dbh_or_table );
268
- }
269
-
270
- /**
271
- * Default initialization method, calls wp_db apropriate method
272
- */
273
- public function default_initialize() {
274
- parent::__construct( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
275
- }
276
-
277
- /**
278
- * Default implementation, calls wp_db apropriate method
279
- */
280
- public function default_insert( $table, $data, $format = null ) {
281
- return parent::insert( $table, $data, $format );
282
- }
283
-
284
- /**
285
- * Default implementation, calls wp_db apropriate method
286
- */
287
- public function default_query( $query ) {
288
- return parent::query( $query );
289
- }
290
-
291
- public function default__escape( $data ) {
292
- return parent::_escape( $data );
293
- }
294
-
295
- /**
296
- * Default implementation, calls wp_db apropriate method
297
- */
298
- public function default_prepare( $query, $args ) {
299
- return parent::prepare( $query, $args );
300
- }
301
-
302
- /**
303
- * Default implementation, calls wp_db apropriate method
304
- */
305
- public function default_replace( $table, $data, $format = null ) {
306
- return parent::replace( $table, $data, $format );
307
- }
308
-
309
- /**
310
- * Default implementation, calls wp_db apropriate method
311
- */
312
- public function default_update( $table, $data, $where, $format = null, $where_format = null ) {
313
- return parent::update( $table, $data, $where, $format, $where_format );
314
- }
315
-
316
- /**
317
- * Default implementation, calls wp_db apropriate method
318
- */
319
- public function default_delete( $table, $where, $where_format = null ) {
320
- return parent::delete( $table, $where, $where_format );
321
- }
322
-
323
- /**
324
- * Default implementation, calls wp_db apropriate method
325
- */
326
- public function default_init_charset() {
327
- return parent::init_charset();
328
- }
329
-
330
- /**
331
- * Default implementation, calls wp_db apropriate method
332
- */
333
- public function default_set_charset( $dbh, $charset = null, $collate = null ) {
334
- return parent::set_charset( $dbh, $charset, $collate );
335
- }
336
-
337
- /**
338
- * Default implementation, calls wp_db apropriate method
339
- */
340
- public function default_set_sql_mode( $modes = array() ) {
341
- return parent::set_sql_mode( $modes );
342
- }
343
-
344
- /**
345
- * Default implementation, calls wp_db apropriate method
346
- */
347
- public function default_flush() {
348
- return parent::flush();
349
- }
350
-
351
- /**
352
- * Default implementation, calls wp_db apropriate method
353
- */
354
- public function default_check_database_version( $dbh_or_table = false ) {
355
- return parent::check_database_version( $dbh_or_table );
356
- }
357
-
358
- /**
359
- * Default implementation, calls wp_db apropriate method
360
- */
361
- public function default_supports_collation( $dbh_or_table = false ) {
362
- return parent::supports_collation( $dbh_or_table );
363
- }
364
-
365
- /**
366
- * Default implementation, calls wp_db apropriate method
367
- */
368
- public function default_has_cap( $db_cap, $dbh_or_table = false ) {
369
- return parent::has_cap( $db_cap, $dbh_or_table );
370
- }
371
-
372
- /**
373
- * Default implementation, calls wp_db apropriate method
374
- */
375
- public function default_db_version( $dbh_or_table = false ) {
376
- return parent::db_version( $dbh_or_table );
377
- }
378
-
379
- /**
380
- * Default implementation, calls wp_db apropriate method
381
- */
382
- public function switch_active_processor( $offset ) {
383
- $new_processor_number = $this->active_processor_number + $offset;
384
- if ( $new_processor_number <= 0 ) {
385
- $new_processor_number = 0;
386
- } else if ( $new_processor_number >= count( $this->processors ) ) {
387
- $new_processor_number = count( $this->processors ) - 1;
388
- }
389
-
390
- $offset_made = $new_processor_number - $this->active_processor_number;
391
- $this->active_processor_number = $new_processor_number;
392
- $this->active_processor = $this->processors[$new_processor_number];
393
-
394
- return $offset_made;
395
- }
396
- }
397
-
398
-
399
-
400
- /**
401
- * class CallUnderlying
402
- */
403
- class _CallUnderlying {
404
- function __construct( $manager ) {
405
- $this->wpdb_mixin = $manager;
406
- }
407
-
408
- /**
409
- * Calls underlying processor's aproptiate method of wp_db
410
- */
411
- function initialize() {
412
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
413
-
414
- try {
415
- $r = $this->wpdb_mixin->initialize();
416
-
417
- $this->wpdb_mixin->switch_active_processor( -$switched );
418
- return $r;
419
- } catch ( \Exception $e ) {
420
- $this->wpdb_mixin->switch_active_processor( -$switched );
421
- throw $e;
422
- }
423
- }
424
-
425
- /**
426
- * Calls underlying processor's aproptiate method of wp_db
427
- */
428
- function flush() {
429
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
430
-
431
- try {
432
- $r = $this->wpdb_mixin->flush();
433
-
434
- $this->wpdb_mixin->switch_active_processor( -$switched );
435
- return $r;
436
- } catch ( \Exception $e ) {
437
- $this->wpdb_mixin->switch_active_processor( -$switched );
438
- throw $e;
439
- }
440
- }
441
-
442
- /**
443
- * Calls underlying processor's aproptiate method of wp_db
444
- */
445
- function query( $query ) {
446
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
447
-
448
- try {
449
- $r = $this->wpdb_mixin->query( $query );
450
-
451
- $this->wpdb_mixin->switch_active_processor( -$switched );
452
- return $r;
453
- } catch ( \Exception $e ) {
454
- $this->wpdb_mixin->switch_active_processor( -$switched );
455
- throw $e;
456
- }
457
- }
458
-
459
- /**
460
- * Calls underlying processor's aproptiate method of wp_db
461
- */
462
- function _escape( $data ) {
463
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
464
-
465
- try {
466
- $r = $this->wpdb_mixin->_escape( $data );
467
-
468
- $this->wpdb_mixin->switch_active_processor( -$switched );
469
- return $r;
470
- } catch ( \Exception $e ) {
471
- $this->wpdb_mixin->switch_active_processor( -$switched );
472
- throw $e;
473
- }
474
- }
475
-
476
- /**
477
- * Calls underlying processor's aproptiate method of wp_db
478
- */
479
- function prepare( $query, $args ) {
480
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
481
-
482
- try {
483
- $r = $this->wpdb_mixin->prepare( $query, $args );
484
-
485
- $this->wpdb_mixin->switch_active_processor( -$switched );
486
- return $r;
487
- } catch ( \Exception $e ) {
488
- $this->wpdb_mixin->switch_active_processor( -$switched );
489
- throw $e;
490
- }
491
- }
492
-
493
- /**
494
- * Calls underlying processor's aproptiate method of wp_db
495
- */
496
- function insert( $table, $data, $format = null ) {
497
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
498
-
499
- try {
500
- $r = $this->wpdb_mixin->insert( $table, $data, $format );
501
-
502
- $this->wpdb_mixin->switch_active_processor( -$switched );
503
- return $r;
504
- } catch ( \Exception $e ) {
505
- $this->wpdb_mixin->switch_active_processor( -$switched );
506
- throw $e;
507
- }
508
- }
509
-
510
- /**
511
- * Calls underlying processor's aproptiate method of wp_db
512
- */
513
- function replace( $table, $data, $format = null ) {
514
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
515
-
516
- try {
517
- $r = $this->wpdb_mixin->replace( $table, $data, $format );
518
-
519
- $this->wpdb_mixin->switch_active_processor( -$switched );
520
- return $r;
521
- } catch ( \Exception $e ) {
522
- $this->wpdb_mixin->switch_active_processor( -$switched );
523
- throw $e;
524
- }
525
- }
526
-
527
- /**
528
- * Calls underlying processor's aproptiate method of wp_db
529
- */
530
- function update( $table, $data, $where, $format = null, $where_format = null ) {
531
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
532
-
533
- try {
534
- $r = $this->wpdb_mixin->update( $table, $data, $where, $format, $where_format );
535
-
536
- $this->wpdb_mixin->switch_active_processor( -$switched );
537
- return $r;
538
- } catch ( \Exception $e ) {
539
- $this->wpdb_mixin->switch_active_processor( -$switched );
540
- throw $e;
541
- }
542
- }
543
-
544
- function delete( $table, $where, $where_format = null ) {
545
- $switched = $this->wpdb_mixin->switch_active_processor( 1 );
546
-
547
- try {
548
- $r = $this->wpdb_mixin->delete( $table, $where, $where_format );
549
-
550
- $this->wpdb_mixin->switch_active_processor( -$switched );
551
- return $r;
552
- } catch ( \Exception $e ) {
553
- $this->wpdb_mixin->switch_active_processor( -$switched );
554
- throw $e;
555
- }
556
- }
557
  }
36
 
37
  $processors[] = new DbCache_WpdbInjection();
38
 
39
+ global $wp_version;
40
+ if (version_compare( $wp_version, '5.3') >= 0) {
41
+ $o = new DbCache_WpdbNew( $processors );
42
+ } else {
43
+ $o = new DbCache_WpdbLegacy( $processors );
44
+ }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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace W3TC;
3
+
4
+ /**
5
+ * class Db
6
+ * Database access mediator, for WordPress < 5.3
7
+ */
8
+ class DbCache_WpdbLegacy extends DbCache_WpdbBase {
9
+ private $active_processor_number;
10
+ private $active_processor;
11
+ private $processors;
12
+
13
+ private $debug;
14
+ private $request_time_start = 0;
15
+
16
+ /*
17
+ * @param boolean $call_default_constructor
18
+ */
19
+ public function __construct( $processors = null ) {
20
+ // required to initialize $use_mysqli which is private
21
+ parent::__construct( '', '', '', '' );
22
+
23
+ // cant force empty parameter list due to wp requirements
24
+ if ( !is_array( $processors ) )
25
+ throw new Exception( 'called incorrectly, use instance()' );
26
+
27
+ $this->processors = $processors;
28
+ $this->active_processor = $processors[0];
29
+ $this->active_processor_number = 0;
30
+
31
+ $c = Dispatcher::config();
32
+ $this->debug = $c->get_boolean( 'dbcache.debug' );
33
+
34
+ if ( $this->debug )
35
+ $this->_request_time_start = microtime( true );
36
+ }
37
+
38
+ /**
39
+ * Called by Root_Loader when all w3tc plugins loaded,
40
+ * i.e. later that object instantiated
41
+ */
42
+ public function on_w3tc_plugins_loaded() {
43
+ $o = $this;
44
+
45
+ if ( $this->debug ) {
46
+ add_action( 'shutdown', array( $o, 'debug_shutdown' ) );
47
+ }
48
+
49
+ add_filter( 'w3tc_footer_comment', array(
50
+ $o, 'w3tc_footer_comment' ) );
51
+ add_action( 'w3tc_usage_statistics_of_request', array(
52
+ $o, 'w3tc_usage_statistics_of_request' ), 10, 1 );
53
+
54
+ }
55
+
56
+ public function w3tc_footer_comment( $strings ) {
57
+ foreach ( $this->processors as $processor )
58
+ $strings = $processor->w3tc_footer_comment( $strings );
59
+
60
+ return $strings;
61
+ }
62
+
63
+ public function debug_shutdown() {
64
+ $strings = array();
65
+ foreach ( $this->processors as $processor )
66
+ $strings = $processor->w3tc_footer_comment( $strings );
67
+
68
+ $request_time_total = microtime( true ) - $this->request_time_start;
69
+
70
+ $data = sprintf( "\n[%s] [%s] [%s]\n", date( 'r' ),
71
+ $_SERVER['REQUEST_URI'], round( $request_time_total, 4 ) ) .
72
+ implode( "\n", $strings ) . "\n";
73
+ $data = strtr( $data, '<>', '..' );
74
+
75
+ $filename = Util_Debug::log_filename( 'dbcache' );
76
+ @file_put_contents( $filename, $data, FILE_APPEND );
77
+ }
78
+
79
+ public function w3tc_usage_statistics_of_request( $storage ) {
80
+ foreach ( $this->processors as $processor )
81
+ $processor->w3tc_usage_statistics_of_request( $storage );
82
+ }
83
+
84
+ public function flush_cache( $extras = array() ) {
85
+ $v = true;
86
+
87
+ foreach ( $this->processors as $processor )
88
+ $v &= $processor->flush_cache( $extras );
89
+
90
+ return $v;
91
+ }
92
+
93
+ public function db_connect( $allow_bail = true ) {
94
+ if ( empty( $this->dbuser ) ) {
95
+ // skip connection - called from constructor
96
+ } else
97
+ return parent::db_connect( $allow_bail );
98
+ }
99
+
100
+ /**
101
+ * Initializes object after processors configured. Called from instance() only
102
+ */
103
+ public function initialize() {
104
+ return $this->active_processor->initialize();
105
+ }
106
+
107
+ /**
108
+ * Overriten logic of wp_db by processor.
109
+ */
110
+ public function insert( $table, $data, $format = null ) {
111
+ do_action( 'w3tc_db_insert', $table, $data, $format );
112
+ return $this->active_processor->insert( $table, $data, $format );
113
+ }
114
+
115
+ /**
116
+ * Overriten logic of wp_db by processor.
117
+ */
118
+ public function query( $query ) {
119
+ return $this->active_processor->query( $query );
120
+ }
121
+
122
+ public function _escape( $data ) {
123
+ return $this->active_processor->_escape( $data );
124
+ }
125
+
126
+ /**
127
+ * Overriten logic of wp_db by processor.
128
+ */
129
+ public function prepare( $query, $args ) {
130
+ $args = func_get_args();
131
+ array_shift( $args );
132
+
133
+ // If args were passed as an array (as in vsprintf), move them up
134
+ if ( isset( $args[0] ) && is_array($args[0]) ) {
135
+ $args = $args[0];
136
+ }
137
+
138
+ return $this->active_processor->prepare( $query, $args );
139
+ }
140
+
141
+ /**
142
+ * Overriten logic of wp_db by processor.
143
+ */
144
+ public function replace( $table, $data, $format = null ) {
145
+ do_action( 'w3tc_db_replace', $table, $data, $format );
146
+ return $this->active_processor->replace( $table, $data, $format );
147
+ }
148
+
149
+ /**
150
+ * Overriten logic of wp_db by processor.
151
+ */
152
+ public function update( $table, $data, $where, $format = null, $where_format = null ) {
153
+ do_action( 'w3tc_db_update', $table, $data, $where, $format,
154
+ $where_format );
155
+ return $this->active_processor->update( $table, $data, $where, $format, $where_format );
156
+ }
157
+
158
+ /**
159
+ * Overriten logic of wp_db by processor.
160
+ */
161
+ public function delete( $table, $where, $where_format = null ) {
162
+ do_action( 'w3tc_db_delete', $table, $where, $where_format );
163
+ return $this->active_processor->delete( $table, $where, $where_format );
164
+ }
165
+
166
+ /**
167
+ * Overriten logic of wp_db by processor.
168
+ */
169
+ public function init_charset() {
170
+ return $this->active_processor->init_charset();
171
+ }
172
+
173
+ /**
174
+ * Overriten logic of wp_db by processor.
175
+ */
176
+ public function set_charset( $dbh, $charset = null, $collate = null ) {
177
+ return $this->active_processor->set_charset( $dbh, $charset, $collate );
178
+ }
179
+
180
+ /**
181
+ * Overriten logic of wp_db by processor.
182
+ */
183
+ public function set_sql_mode( $modes = array() ) {
184
+ return $this->active_processor->set_sql_mode( $modes );
185
+ }
186
+
187
+ /**
188
+ * Overriten logic of wp_db by processor.
189
+ */
190
+ public function flush() {
191
+ return $this->active_processor->flush();
192
+ }
193
+
194
+ /**
195
+ * Overriten logic of wp_db by processor.
196
+ */
197
+ public function check_database_version( $dbh_or_table = false ) {
198
+ return $this->active_processor->check_database_version( $dbh_or_table );
199
+ }
200
+
201
+ /**
202
+ * Overriten logic of wp_db by processor.
203
+ */
204
+ public function supports_collation( $dbh_or_table = false ) {
205
+ return $this->active_processor->supports_collation( $dbh_or_table );
206
+ }
207
+
208
+ /**
209
+ * Overriten logic of wp_db by processor.
210
+ */
211
+ public function has_cap( $db_cap, $dbh_or_table = false ) {
212
+ return $this->active_processor->has_cap( $db_cap, $dbh_or_table );
213
+ }
214
+
215
+ /**
216
+ * Overriten logic of wp_db by processor.
217
+ */
218
+ public function db_version( $dbh_or_table = false ) {
219
+ return $this->active_processor->db_version( $dbh_or_table );
220
+ }
221
+
222
+ /**
223
+ * Default initialization method, calls wp_db apropriate method
224
+ */
225
+ public function default_initialize() {
226
+ parent::__construct( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
227
+ }
228
+
229
+ /**
230
+ * Default implementation, calls wp_db apropriate method
231
+ */
232
+ public function default_insert( $table, $data, $format = null ) {
233
+ return parent::insert( $table, $data, $format );
234
+ }
235
+
236
+ /**
237
+ * Default implementation, calls wp_db apropriate method
238
+ */
239
+ public function default_query( $query ) {
240
+ return parent::query( $query );
241
+ }
242
+
243
+ public function default__escape( $data ) {
244
+ return parent::_escape( $data );
245
+ }
246
+
247
+ /**
248
+ * Default implementation, calls wp_db apropriate method
249
+ */
250
+ public function default_prepare( $query, $args ) {
251
+ return parent::prepare( $query, $args );
252
+ }
253
+
254
+ /**
255
+ * Default implementation, calls wp_db apropriate method
256
+ */
257
+ public function default_replace( $table, $data, $format = null ) {
258
+ return parent::replace( $table, $data, $format );
259
+ }
260
+
261
+ /**
262
+ * Default implementation, calls wp_db apropriate method
263
+ */
264
+ public function default_update( $table, $data, $where, $format = null, $where_format = null ) {
265
+ return parent::update( $table, $data, $where, $format, $where_format );
266
+ }
267
+
268
+ /**
269
+ * Default implementation, calls wp_db apropriate method
270
+ */
271
+ public function default_delete( $table, $where, $where_format = null ) {
272
+ return parent::delete( $table, $where, $where_format );
273
+ }
274
+
275
+ /**
276
+ * Default implementation, calls wp_db apropriate method
277
+ */
278
+ public function default_init_charset() {
279
+ return parent::init_charset();
280
+ }
281
+
282
+ /**
283
+ * Default implementation, calls wp_db apropriate method
284
+ */
285
+ public function default_set_charset( $dbh, $charset = null, $collate = null ) {
286
+ return parent::set_charset( $dbh, $charset, $collate );
287
+ }
288
+
289
+ /**
290
+ * Default implementation, calls wp_db apropriate method
291
+ */
292
+ public function default_set_sql_mode( $modes = array() ) {
293
+ return parent::set_sql_mode( $modes );
294
+ }
295
+
296
+ /**
297
+ * Default implementation, calls wp_db apropriate method
298
+ */
299
+ public function default_flush() {
300
+ return parent::flush();
301
+ }
302
+
303
+ /**
304
+ * Default implementation, calls wp_db apropriate method
305
+ */
306
+ public function default_check_database_version( $dbh_or_table = false ) {
307
+ return parent::check_database_version( $dbh_or_table );
308
+ }
309
+
310
+ /**
311
+ * Default implementation, calls wp_db apropriate method
312
+ */
313
+ public function default_supports_collation( $dbh_or_table = false ) {
314
+ return parent::supports_collation( $dbh_or_table );
315
+ }
316
+
317
+ /**
318
+ * Default implementation, calls wp_db apropriate method
319
+ */
320
+ public function default_has_cap( $db_cap, $dbh_or_table = false ) {
321
+ return parent::has_cap( $db_cap, $dbh_or_table );
322
+ }
323
+
324
+ /**
325
+ * Default implementation, calls wp_db apropriate method
326
+ */
327
+ public function default_db_version( $dbh_or_table = false ) {
328
+ return parent::db_version( $dbh_or_table );
329
+ }
330
+
331
+ /**
332
+ * Default implementation, calls wp_db apropriate method
333
+ */
334
+ public function switch_active_processor( $offset ) {
335
+ $new_processor_number = $this->active_processor_number + $offset;
336
+ if ( $new_processor_number <= 0 ) {
337
+ $new_processor_number = 0;
338
+ } else if ( $new_processor_number >= count( $this->processors ) ) {
339
+ $new_processor_number = count( $this->processors ) - 1;
340
+ }
341
+
342
+ $offset_made = $new_processor_number - $this->active_processor_number;
343
+ $this->active_processor_number = $new_processor_number;
344
+ $this->active_processor = $this->processors[$new_processor_number];
345
+
346
+ return $offset_made;
347
+ }
348
+ }
349
+
350
+
351
+
352
+ /**
353
+ * class CallUnderlying
354
+ */
355
+ class _CallUnderlying {
356
+ function __construct( $manager ) {
357
+ $this->wpdb_mixin = $manager;
358
+ }
359
+
360
+ /**
361
+ * Calls underlying processor's aproptiate method of wp_db
362
+ */
363
+ function initialize() {
364
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
365
+
366
+ try {
367
+ $r = $this->wpdb_mixin->initialize();
368
+
369
+ $this->wpdb_mixin->switch_active_processor( -$switched );
370
+ return $r;
371
+ } catch ( \Exception $e ) {
372
+ $this->wpdb_mixin->switch_active_processor( -$switched );
373
+ throw $e;
374
+ }
375
+ }
376
+
377
+ /**
378
+ * Calls underlying processor's aproptiate method of wp_db
379
+ */
380
+ function flush() {
381
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
382
+
383
+ try {
384
+ $r = $this->wpdb_mixin->flush();
385
+
386
+ $this->wpdb_mixin->switch_active_processor( -$switched );
387
+ return $r;
388
+ } catch ( \Exception $e ) {
389
+ $this->wpdb_mixin->switch_active_processor( -$switched );
390
+ throw $e;
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Calls underlying processor's aproptiate method of wp_db
396
+ */
397
+ function query( $query ) {
398
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
399
+
400
+ try {
401
+ $r = $this->wpdb_mixin->query( $query );
402
+
403
+ $this->wpdb_mixin->switch_active_processor( -$switched );
404
+ return $r;
405
+ } catch ( \Exception $e ) {
406
+ $this->wpdb_mixin->switch_active_processor( -$switched );
407
+ throw $e;
408
+ }
409
+ }
410
+
411
+ /**
412
+ * Calls underlying processor's aproptiate method of wp_db
413
+ */
414
+ function _escape( $data ) {
415
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
416
+
417
+ try {
418
+ $r = $this->wpdb_mixin->_escape( $data );
419
+
420
+ $this->wpdb_mixin->switch_active_processor( -$switched );
421
+ return $r;
422
+ } catch ( \Exception $e ) {
423
+ $this->wpdb_mixin->switch_active_processor( -$switched );
424
+ throw $e;
425
+ }
426
+ }
427
+
428
+ /**
429
+ * Calls underlying processor's aproptiate method of wp_db
430
+ */
431
+ function prepare( $query, $args ) {
432
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
433
+
434
+ try {
435
+ $r = $this->wpdb_mixin->prepare( $query, $args );
436
+
437
+ $this->wpdb_mixin->switch_active_processor( -$switched );
438
+ return $r;
439
+ } catch ( \Exception $e ) {
440
+ $this->wpdb_mixin->switch_active_processor( -$switched );
441
+ throw $e;
442
+ }
443
+ }
444
+
445
+ /**
446
+ * Calls underlying processor's aproptiate method of wp_db
447
+ */
448
+ function insert( $table, $data, $format = null ) {
449
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
450
+
451
+ try {
452
+ $r = $this->wpdb_mixin->insert( $table, $data, $format );
453
+
454
+ $this->wpdb_mixin->switch_active_processor( -$switched );
455
+ return $r;
456
+ } catch ( \Exception $e ) {
457
+ $this->wpdb_mixin->switch_active_processor( -$switched );
458
+ throw $e;
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Calls underlying processor's aproptiate method of wp_db
464
+ */
465
+ function replace( $table, $data, $format = null ) {
466
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
467
+
468
+ try {
469
+ $r = $this->wpdb_mixin->replace( $table, $data, $format );
470
+
471
+ $this->wpdb_mixin->switch_active_processor( -$switched );
472
+ return $r;
473
+ } catch ( \Exception $e ) {
474
+ $this->wpdb_mixin->switch_active_processor( -$switched );
475
+ throw $e;
476
+ }
477
+ }
478
+
479
+ /**
480
+ * Calls underlying processor's aproptiate method of wp_db
481
+ */
482
+ function update( $table, $data, $where, $format = null, $where_format = null ) {
483
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
484
+
485
+ try {
486
+ $r = $this->wpdb_mixin->update( $table, $data, $where, $format, $where_format );
487
+
488
+ $this->wpdb_mixin->switch_active_processor( -$switched );
489
+ return $r;
490
+ } catch ( \Exception $e ) {
491
+ $this->wpdb_mixin->switch_active_processor( -$switched );
492
+ throw $e;
493
+ }
494
+ }
495
+
496
+ function delete( $table, $where, $where_format = null ) {
497
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
498
+
499
+ try {
500
+ $r = $this->wpdb_mixin->delete( $table, $where, $where_format );
501
+
502
+ $this->wpdb_mixin->switch_active_processor( -$switched );
503
+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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace W3TC;
3
+
4
+ /**
5
+ * class Db
6
+ * Database access mediator, for WordPress >= 5.3
7
+ */
8
+ class DbCache_WpdbNew extends DbCache_WpdbBase {
9
+ private $active_processor_number;
10
+ private $active_processor;
11
+ private $processors;
12
+
13
+ private $debug;
14
+ private $request_time_start = 0;
15
+
16
+ /*
17
+ * @param boolean $call_default_constructor
18
+ */
19
+ public function __construct( $processors = null ) {
20
+ // required to initialize $use_mysqli which is private
21
+ parent::__construct( '', '', '', '' );
22
+
23
+ // cant force empty parameter list due to wp requirements
24
+ if ( !is_array( $processors ) )
25
+ throw new Exception( 'called incorrectly, use instance()' );
26
+
27
+ $this->processors = $processors;
28
+ $this->active_processor = $processors[0];
29
+ $this->active_processor_number = 0;
30
+
31
+ $c = Dispatcher::config();
32
+ $this->debug = $c->get_boolean( 'dbcache.debug' );
33
+
34
+ if ( $this->debug )
35
+ $this->_request_time_start = microtime( true );
36
+ }
37
+
38
+ /**
39
+ * Called by Root_Loader when all w3tc plugins loaded,
40
+ * i.e. later that object instantiated
41
+ */
42
+ public function on_w3tc_plugins_loaded() {
43
+ $o = $this;
44
+
45
+ if ( $this->debug ) {
46
+ add_action( 'shutdown', array( $o, 'debug_shutdown' ) );
47
+ }
48
+
49
+ add_filter( 'w3tc_footer_comment', array(
50
+ $o, 'w3tc_footer_comment' ) );
51
+ add_action( 'w3tc_usage_statistics_of_request', array(
52
+ $o, 'w3tc_usage_statistics_of_request' ), 10, 1 );
53
+
54
+ }
55
+
56
+ public function w3tc_footer_comment( $strings ) {
57
+ foreach ( $this->processors as $processor )
58
+ $strings = $processor->w3tc_footer_comment( $strings );
59
+
60
+ return $strings;
61
+ }
62
+
63
+ public function debug_shutdown() {
64
+ $strings = array();
65
+ foreach ( $this->processors as $processor )
66
+ $strings = $processor->w3tc_footer_comment( $strings );
67
+
68
+ $request_time_total = microtime( true ) - $this->request_time_start;
69
+
70
+ $data = sprintf( "\n[%s] [%s] [%s]\n", date( 'r' ),
71
+ $_SERVER['REQUEST_URI'], round( $request_time_total, 4 ) ) .
72
+ implode( "\n", $strings ) . "\n";
73
+ $data = strtr( $data, '<>', '..' );
74
+
75
+ $filename = Util_Debug::log_filename( 'dbcache' );
76
+ @file_put_contents( $filename, $data, FILE_APPEND );
77
+ }
78
+
79
+ public function w3tc_usage_statistics_of_request( $storage ) {
80
+ foreach ( $this->processors as $processor )
81
+ $processor->w3tc_usage_statistics_of_request( $storage );
82
+ }
83
+
84
+ public function flush_cache( $extras = array() ) {
85
+ $v = true;
86
+
87
+ foreach ( $this->processors as $processor )
88
+ $v &= $processor->flush_cache( $extras );
89
+
90
+ return $v;
91
+ }
92
+
93
+ public function db_connect( $allow_bail = true ) {
94
+ if ( empty( $this->dbuser ) ) {
95
+ // skip connection - called from constructor
96
+ } else
97
+ return parent::db_connect( $allow_bail );
98
+ }
99
+
100
+ /**
101
+ * Initializes object after processors configured. Called from instance() only
102
+ */
103
+ public function initialize() {
104
+ return $this->active_processor->initialize();
105
+ }
106
+
107
+ /**
108
+ * Overriten logic of wp_db by processor.
109
+ */
110
+ public function insert( $table, $data, $format = null ) {
111
+ do_action( 'w3tc_db_insert', $table, $data, $format );
112
+ return $this->active_processor->insert( $table, $data, $format );
113
+ }
114
+
115
+ /**
116
+ * Overriten logic of wp_db by processor.
117
+ */
118
+ public function query( $query ) {
119
+ return $this->active_processor->query( $query );
120
+ }
121
+
122
+ public function _escape( $data ) {
123
+ return $this->active_processor->_escape( $data );
124
+ }
125
+
126
+ /**
127
+ * Overriten logic of wp_db by processor.
128
+ */
129
+ public function prepare( $query, ...$args ) {
130
+ return $this->active_processor->prepare( $query, $args );
131
+ }
132
+
133
+ /**
134
+ * Overriten logic of wp_db by processor.
135
+ */
136
+ public function replace( $table, $data, $format = null ) {
137
+ do_action( 'w3tc_db_replace', $table, $data, $format );
138
+ return $this->active_processor->replace( $table, $data, $format );
139
+ }
140
+
141
+ /**
142
+ * Overriten logic of wp_db by processor.
143
+ */
144
+ public function update( $table, $data, $where, $format = null, $where_format = null ) {
145
+ do_action( 'w3tc_db_update', $table, $data, $where, $format,
146
+ $where_format );
147
+ return $this->active_processor->update( $table, $data, $where, $format, $where_format );
148
+ }
149
+
150
+ /**
151
+ * Overriten logic of wp_db by processor.
152
+ */
153
+ public function delete( $table, $where, $where_format = null ) {
154
+ do_action( 'w3tc_db_delete', $table, $where, $where_format );
155
+ return $this->active_processor->delete( $table, $where, $where_format );
156
+ }
157
+
158
+ /**
159
+ * Overriten logic of wp_db by processor.
160
+ */
161
+ public function init_charset() {
162
+ return $this->active_processor->init_charset();
163
+ }
164
+
165
+ /**
166
+ * Overriten logic of wp_db by processor.
167
+ */
168
+ public function set_charset( $dbh, $charset = null, $collate = null ) {
169
+ return $this->active_processor->set_charset( $dbh, $charset, $collate );
170
+ }
171
+
172
+ /**
173
+ * Overriten logic of wp_db by processor.
174
+ */
175
+ public function set_sql_mode( $modes = array() ) {
176
+ return $this->active_processor->set_sql_mode( $modes );
177
+ }
178
+
179
+ /**
180
+ * Overriten logic of wp_db by processor.
181
+ */
182
+ public function flush() {
183
+ return $this->active_processor->flush();
184
+ }
185
+
186
+ /**
187
+ * Overriten logic of wp_db by processor.
188
+ */
189
+ public function check_database_version( $dbh_or_table = false ) {
190
+ return $this->active_processor->check_database_version( $dbh_or_table );
191
+ }
192
+
193
+ /**
194
+ * Overriten logic of wp_db by processor.
195
+ */
196
+ public function supports_collation( $dbh_or_table = false ) {
197
+ return $this->active_processor->supports_collation( $dbh_or_table );
198
+ }
199
+
200
+ /**
201
+ * Overriten logic of wp_db by processor.
202
+ */
203
+ public function has_cap( $db_cap, $dbh_or_table = false ) {
204
+ return $this->active_processor->has_cap( $db_cap, $dbh_or_table );
205
+ }
206
+
207
+ /**
208
+ * Overriten logic of wp_db by processor.
209
+ */
210
+ public function db_version( $dbh_or_table = false ) {
211
+ return $this->active_processor->db_version( $dbh_or_table );
212
+ }
213
+
214
+ /**
215
+ * Default initialization method, calls wp_db apropriate method
216
+ */
217
+ public function default_initialize() {
218
+ parent::__construct( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
219
+ }
220
+
221
+ /**
222
+ * Default implementation, calls wp_db apropriate method
223
+ */
224
+ public function default_insert( $table, $data, $format = null ) {
225
+ return parent::insert( $table, $data, $format );
226
+ }
227
+
228
+ /**
229
+ * Default implementation, calls wp_db apropriate method
230
+ */
231
+ public function default_query( $query ) {
232
+ return parent::query( $query );
233
+ }
234
+
235
+ public function default__escape( $data ) {
236
+ return parent::_escape( $data );
237
+ }
238
+
239
+ /**
240
+ * Default implementation, calls wp_db apropriate method
241
+ */
242
+ public function default_prepare( $query, $args ) {
243
+ return parent::prepare( $query, ...$args );
244
+ }
245
+
246
+ /**
247
+ * Default implementation, calls wp_db apropriate method
248
+ */
249
+ public function default_replace( $table, $data, $format = null ) {
250
+ return parent::replace( $table, $data, $format );
251
+ }
252
+
253
+ /**
254
+ * Default implementation, calls wp_db apropriate method
255
+ */
256
+ public function default_update( $table, $data, $where, $format = null, $where_format = null ) {
257
+ return parent::update( $table, $data, $where, $format, $where_format );
258
+ }
259
+
260
+ /**
261
+ * Default implementation, calls wp_db apropriate method
262
+ */
263
+ public function default_delete( $table, $where, $where_format = null ) {
264
+ return parent::delete( $table, $where, $where_format );
265
+ }
266
+
267
+ /**
268
+ * Default implementation, calls wp_db apropriate method
269
+ */
270
+ public function default_init_charset() {
271
+ return parent::init_charset();
272
+ }
273
+
274
+ /**
275
+ * Default implementation, calls wp_db apropriate method
276
+ */
277
+ public function default_set_charset( $dbh, $charset = null, $collate = null ) {
278
+ return parent::set_charset( $dbh, $charset, $collate );
279
+ }
280
+
281
+ /**
282
+ * Default implementation, calls wp_db apropriate method
283
+ */
284
+ public function default_set_sql_mode( $modes = array() ) {
285
+ return parent::set_sql_mode( $modes );
286
+ }
287
+
288
+ /**
289
+ * Default implementation, calls wp_db apropriate method
290
+ */
291
+ public function default_flush() {
292
+ return parent::flush();
293
+ }
294
+
295
+ /**
296
+ * Default implementation, calls wp_db apropriate method
297
+ */
298
+ public function default_check_database_version( $dbh_or_table = false ) {
299
+ return parent::check_database_version( $dbh_or_table );
300
+ }
301
+
302
+ /**
303
+ * Default implementation, calls wp_db apropriate method
304
+ */
305
+ public function default_supports_collation( $dbh_or_table = false ) {
306
+ return parent::supports_collation( $dbh_or_table );
307
+ }
308
+
309
+ /**
310
+ * Default implementation, calls wp_db apropriate method
311
+ */
312
+ public function default_has_cap( $db_cap, $dbh_or_table = false ) {
313
+ return parent::has_cap( $db_cap, $dbh_or_table );
314
+ }
315
+
316
+ /**
317
+ * Default implementation, calls wp_db apropriate method
318
+ */
319
+ public function default_db_version( $dbh_or_table = false ) {
320
+ return parent::db_version( $dbh_or_table );
321
+ }
322
+
323
+ /**
324
+ * Default implementation, calls wp_db apropriate method
325
+ */
326
+ public function switch_active_processor( $offset ) {
327
+ $new_processor_number = $this->active_processor_number + $offset;
328
+ if ( $new_processor_number <= 0 ) {
329
+ $new_processor_number = 0;
330
+ } else if ( $new_processor_number >= count( $this->processors ) ) {
331
+ $new_processor_number = count( $this->processors ) - 1;
332
+ }
333
+
334
+ $offset_made = $new_processor_number - $this->active_processor_number;
335
+ $this->active_processor_number = $new_processor_number;
336
+ $this->active_processor = $this->processors[$new_processor_number];
337
+
338
+ return $offset_made;
339
+ }
340
+ }
341
+
342
+
343
+
344
+ /**
345
+ * class CallUnderlying
346
+ */
347
+ class _CallUnderlying {
348
+ function __construct( $manager ) {
349
+ $this->wpdb_mixin = $manager;
350
+ }
351
+
352
+ /**
353
+ * Calls underlying processor's aproptiate method of wp_db
354
+ */
355
+ function initialize() {
356
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
357
+
358
+ try {
359
+ $r = $this->wpdb_mixin->initialize();
360
+
361
+ $this->wpdb_mixin->switch_active_processor( -$switched );
362
+ return $r;
363
+ } catch ( \Exception $e ) {
364
+ $this->wpdb_mixin->switch_active_processor( -$switched );
365
+ throw $e;
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Calls underlying processor's aproptiate method of wp_db
371
+ */
372
+ function flush() {
373
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
374
+
375
+ try {
376
+ $r = $this->wpdb_mixin->flush();
377
+
378
+ $this->wpdb_mixin->switch_active_processor( -$switched );
379
+ return $r;
380
+ } catch ( \Exception $e ) {
381
+ $this->wpdb_mixin->switch_active_processor( -$switched );
382
+ throw $e;
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Calls underlying processor's aproptiate method of wp_db
388
+ */
389
+ function query( $query ) {
390
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
391
+
392
+ try {
393
+ $r = $this->wpdb_mixin->query( $query );
394
+
395
+ $this->wpdb_mixin->switch_active_processor( -$switched );
396
+ return $r;
397
+ } catch ( \Exception $e ) {
398
+ $this->wpdb_mixin->switch_active_processor( -$switched );
399
+ throw $e;
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Calls underlying processor's aproptiate method of wp_db
405
+ */
406
+ function _escape( $data ) {
407
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
408
+
409
+ try {
410
+ $r = $this->wpdb_mixin->_escape( $data );
411
+
412
+ $this->wpdb_mixin->switch_active_processor( -$switched );
413
+ return $r;
414
+ } catch ( \Exception $e ) {
415
+ $this->wpdb_mixin->switch_active_processor( -$switched );
416
+ throw $e;
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Calls underlying processor's aproptiate method of wp_db
422
+ */
423
+ function prepare( $query, $args ) {
424
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
425
+
426
+ try {
427
+ $r = $this->wpdb_mixin->prepare( $query, ...$args );
428
+
429
+ $this->wpdb_mixin->switch_active_processor( -$switched );
430
+ return $r;
431
+ } catch ( \Exception $e ) {
432
+ $this->wpdb_mixin->switch_active_processor( -$switched );
433
+ throw $e;
434
+ }
435
+ }
436
+
437
+ /**
438
+ * Calls underlying processor's aproptiate method of wp_db
439
+ */
440
+ function insert( $table, $data, $format = null ) {
441
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
442
+
443
+ try {
444
+ $r = $this->wpdb_mixin->insert( $table, $data, $format );
445
+
446
+ $this->wpdb_mixin->switch_active_processor( -$switched );
447
+ return $r;
448
+ } catch ( \Exception $e ) {
449
+ $this->wpdb_mixin->switch_active_processor( -$switched );
450
+ throw $e;
451
+ }
452
+ }
453
+
454
+ /**
455
+ * Calls underlying processor's aproptiate method of wp_db
456
+ */
457
+ function replace( $table, $data, $format = null ) {
458
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
459
+
460
+ try {
461
+ $r = $this->wpdb_mixin->replace( $table, $data, $format );
462
+
463
+ $this->wpdb_mixin->switch_active_processor( -$switched );
464
+ return $r;
465
+ } catch ( \Exception $e ) {
466
+ $this->wpdb_mixin->switch_active_processor( -$switched );
467
+ throw $e;
468
+ }
469
+ }
470
+
471
+ /**
472
+ * Calls underlying processor's aproptiate method of wp_db
473
+ */
474
+ function update( $table, $data, $where, $format = null, $where_format = null ) {
475
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
476
+
477
+ try {
478
+ $r = $this->wpdb_mixin->update( $table, $data, $where, $format, $where_format );
479
+
480
+ $this->wpdb_mixin->switch_active_processor( -$switched );
481
+ return $r;
482
+ } catch ( \Exception $e ) {
483
+ $this->wpdb_mixin->switch_active_processor( -$switched );
484
+ throw $e;
485
+ }
486
+ }
487
+
488
+ function delete( $table, $where, $where_format = null ) {
489
+ $switched = $this->wpdb_mixin->switch_active_processor( 1 );
490
+
491
+ try {
492
+ $r = $this->wpdb_mixin->delete( $table, $where, $where_format );
493
+
494
+ $this->wpdb_mixin->switch_active_processor( -$switched );
495
+ return $r;
496
+ } catch ( \Exception $e ) {
497
+ $this->wpdb_mixin->switch_active_processor( -$switched );
498
+ throw $e;
499
+ }
500
+ }
501
+ }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: fredericktownes
3
  Tags: seo, cache, caching, compression, maxcdn, nginx, varnish, redis, new relic, aws, amazon web services, s3, cloudfront, rackspace, cloudflare, azure, apache
4
  Requires at least: 3.2
5
- Tested up to: 5.2
6
- Stable tag: 0.10.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -271,6 +271,9 @@ Please reach out to all of these people and support their projects if you're so
271
 
272
  == Changelog ==
273
 
 
 
 
274
  = 0.10.1 =
275
  * Fixed slowdown in memcached engine
276
  * Fixed Purge Cache menu links so they flush current blog in WPMU
2
  Contributors: fredericktownes
3
  Tags: seo, cache, caching, compression, maxcdn, nginx, varnish, redis, new relic, aws, amazon web services, s3, cloudfront, rackspace, cloudflare, azure, apache
4
  Requires at least: 3.2
5
+ Tested up to: 5.3
6
+ Stable tag: 0.10.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
271
 
272
  == Changelog ==
273
 
274
+ = 0.10.2 =
275
+ * Fixed compatibility with wpdb::prepare in WordPress 5.3
276
+
277
  = 0.10.1 =
278
  * Fixed slowdown in memcached engine
279
  * Fixed Purge Cache menu links so they flush current blog in WPMU
w3-total-cache-api.php CHANGED
@@ -5,7 +5,7 @@ if ( !defined( 'ABSPATH' ) ) {
5
  }
6
 
7
  define( 'W3TC', true );
8
- define( 'W3TC_VERSION', '0.10.1' );
9
  define( 'W3TC_POWERED_BY', 'W3 Total Cache' );
10
  define( 'W3TC_EMAIL', 'w3tc@w3-edge.com' );
11
  define( 'W3TC_TEXT_DOMAIN', 'w3-total-cache' );
5
  }
6
 
7
  define( 'W3TC', true );
8
+ define( 'W3TC_VERSION', '0.10.2' );
9
  define( 'W3TC_POWERED_BY', 'W3 Total Cache' );
10
  define( 'W3TC_EMAIL', 'w3tc@w3-edge.com' );
11
  define( 'W3TC_TEXT_DOMAIN', 'w3-total-cache' );
w3-total-cache.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: W3 Total Cache
4
  Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
5
- Version: 0.10.1
6
  Plugin URI: https://www.w3-edge.com/wordpress-plugins/w3-total-cache/
7
  Author: Frederick Townes
8
  Author URI: http://www.linkedin.com/in/fredericktownes
2
  /*
3
  Plugin Name: W3 Total Cache
4
  Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
5
+ Version: 0.10.2
6
  Plugin URI: https://www.w3-edge.com/wordpress-plugins/w3-total-cache/
7
  Author: Frederick Townes
8
  Author URI: http://www.linkedin.com/in/fredericktownes