• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

timber / timber / 5690057835

pending completion
5690057835

push

github

nlemoine
Merge branch '2.x' of github.com:timber/timber into 2.x-refactor-file-models

# Conflicts:
#	src/Attachment.php
#	src/ExternalImage.php
#	src/FileSize.php
#	src/URLHelper.php

1134 of 1134 new or added lines in 55 files covered. (100.0%)

3923 of 4430 relevant lines covered (88.56%)

59.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.15
/src/Loader.php
1
<?php
2

3
namespace Timber;
4

5
use InvalidArgumentException;
6
use Timber\Cache\Cleaner;
7
use Twig\CacheExtension;
8
use Twig\Environment;
9
use Twig\Loader\FilesystemLoader;
10
use Twig\TwigFunction;
11

12
class Loader
13
{
14
    public const CACHEGROUP = 'timberloader';
15

16
    public const TRANS_KEY_LEN = 50;
17

18
    public const CACHE_NONE = 'none';
19

20
    public const CACHE_OBJECT = 'cache';
21

22
    public const CACHE_TRANSIENT = 'transient';
23

24
    public const CACHE_SITE_TRANSIENT = 'site-transient';
25

26
    public const CACHE_USE_DEFAULT = 'default';
27

28
    /** Identifier of the main namespace. Will likely mirror Twig\Loader\FilesystemLoader::MAIN_NAMESPACE */
29
    public const MAIN_NAMESPACE = '__main__';
30

31
    public static $cache_modes = [
32
        self::CACHE_NONE,
33
        self::CACHE_OBJECT,
34
        self::CACHE_TRANSIENT,
35
        self::CACHE_SITE_TRANSIENT,
36
    ];
37

38
    protected $cache_mode = self::CACHE_TRANSIENT;
39

40
    protected $locations;
41

42
    /**
43
     * @param bool|string   $caller the calling directory or false
44
     */
45
    public function __construct($caller = false)
46
    {
47
        $this->locations = LocationManager::get_locations($caller);
408✔
48

49
        /**
50
         * Filters the cache mode.
51
         *
52
         * You can read more about Caching in the
53
         * [Performance/Caching]({{<relref "performance.md" >}}) guide.
54
         *
55
         * @since 0.20.10
56
         *
57
         * @param string $cache_mode The cache mode. Can be one of the following:
58
         *                           `Timber\Loader::CACHE_NONE`,
59
         *                           `Timber\Loader::CACHE_OBJECT`,
60
         *                           `Timber\Loader::CACHE_TRANSIENT`,
61
         *                           `Timber\Loader::CACHE_SITE_TRANSIENT`,
62
         *                           `Timber\Loader::CACHE_USE_DEFAULT`.
63
         *                           Default `Timber\Loader::CACHE_TRANSIENT`.
64
         */
65
        $this->cache_mode = \apply_filters('timber/cache/mode', $this->cache_mode);
408✔
66

67
        /**
68
         * Filters the cache mode.
69
         *
70
         * @deprecated 2.0.0, use `timber/cache/mode`
71
         */
72
        $this->cache_mode = \apply_filters_deprecated(
408✔
73
            'timber_cache_mode',
408✔
74
            [$this->cache_mode],
408✔
75
            '2.0.0',
408✔
76
            'timber/cache/mode'
408✔
77
        );
408✔
78
    }
79

80
    /**
81
     * @param string            $file
82
     * @param array             $data
83
     * @param array|boolean        $expires (array for options, false for none, integer for # of seconds)
84
     * @param string            $cache_mode
85
     * @return bool|string
86
     */
87
    public function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT)
88
    {
89
        // Different $expires if user is anonymous or logged in
90
        if (\is_array($expires)) {
79✔
91
            /** @var array $expires */
92
            if (\is_user_logged_in() && isset($expires[1])) {
4✔
93
                $expires = $expires[1];
1✔
94
            } else {
95
                $expires = $expires[0];
3✔
96
            }
97
        }
98

99
        if ($expires === 0) {
79✔
100
            $expires = false;
×
101
        }
102

103
        $key = null;
79✔
104
        $output = false;
79✔
105
        if (false !== $expires) {
79✔
106
            \ksort($data);
11✔
107
            $encoded = \json_encode($data);
11✔
108

109
            /**
110
             * The encoding might fail, e.g. when an object has a recursion. In that case, we’d rather not cache the
111
             * data instead of possibly returning the wrong data.
112
             */
113
            if (false !== $encoded) {
11✔
114
                $key = \md5($file . $encoded);
11✔
115
                $output = $this->get_cache($key, self::CACHEGROUP, $cache_mode);
11✔
116
            }
117
        }
118

119
        if (false === $output || null === $output) {
79✔
120
            $twig = $this->get_twig();
79✔
121
            if (\strlen($file)) {
79✔
122
                $loader = $this->get_loader();
79✔
123
                $result = $loader->getCacheKey($file);
79✔
124

125
                /**
126
                 * Fires after …
127
                 *
128
                 * @todo Add summary, description parameter description
129
                 *
130
                 * @param string $result
131
                 */
132
                \do_action('timber/loader/render_file', $result);
79✔
133

134
                /**
135
                 * Fires after …
136
                 *
137
                 * This action is used by the Timber Debug Bar extension.
138
                 *
139
                 * @todo Add summary
140
                 *
141
                 * @deprecated 2.0.0, use `timber/loader/render_file`
142
                 */
143
                \do_action_deprecated(
79✔
144
                    'timber_loader_render_file',
79✔
145
                    [$result],
79✔
146
                    '2.0.0',
79✔
147
                    'timber/loader/render_file'
79✔
148
                );
79✔
149
            }
150

151
            /**
152
             * Filters …
153
             *
154
             * @todo Add summary, description, example, parameter descriptions
155
             *
156
             * @since 0.20.10
157
             *
158
             * @param array  $data
159
             * @param string $file
160
             */
161
            $data = \apply_filters('timber/loader/render_data', $data, $file);
79✔
162

163
            /**
164
             * Filters …
165
             *
166
             * @todo Add summary
167
             *
168
             * @deprecated 2.0.0, use `timber/loader/render_data`
169
             */
170
            $data = \apply_filters_deprecated(
79✔
171
                'timber_loader_render_data',
79✔
172
                [$data],
79✔
173
                '2.0.0',
79✔
174
                'timber/loader/render_data'
79✔
175
            );
79✔
176

177
            $template = $twig->load($file);
79✔
178
            $output = $template->render($data);
78✔
179
        }
180

181
        if (false !== $output && false !== $expires && null !== $key) {
77✔
182
            $this->delete_cache();
11✔
183
            $this->set_cache($key, $output, self::CACHEGROUP, $expires, $cache_mode);
11✔
184
        }
185

186
        /**
187
         * Filters …
188
         *
189
         * @todo  Add summary, description, example, parameter descriptions
190
         *
191
         * @since 0.20.10
192
         *
193
         * @param string $output
194
         * @param array  $data
195
         * @param string $file
196
         */
197
        $output = \apply_filters('timber/output', $output, $data, $file);
77✔
198

199
        /**
200
         * Filters …
201
         *
202
         * @todo Add summary
203
         *
204
         * @deprecated 2.0.0, use `timber/output`
205
         */
206
        $output = \apply_filters_deprecated('timber_output', [$output], '2.0.0', 'timber/output');
77✔
207

208
        return $output;
77✔
209
    }
210

211
    protected function delete_cache()
212
    {
213
        Cleaner::delete_transients();
11✔
214
    }
215

216
    /**
217
     * Get first existing template.
218
     *
219
     * @param array|string $templates  Name(s) of the Twig template(s) to choose from.
220
     * @return string|bool             Name of chosen template, otherwise false.
221
     */
222
    public function choose_template($templates)
223
    {
224
        // Change $templates into array, if needed
225
        if (!\is_array($templates)) {
81✔
226
            $templates = (array) $templates;
77✔
227
        }
228

229
        // Get Twig loader
230
        $loader = $this->get_loader();
81✔
231

232
        // Run through template array
233
        foreach ($templates as $template) {
81✔
234
            // Remove any whitespace around the template name
235
            $template = \trim($template);
81✔
236
            // Use the Twig loader to test for existance
237
            if ($loader->exists($template)) {
81✔
238
                // Return name of existing template
239
                return $template;
79✔
240
            }
241
        }
242

243
        // No existing template was found
244
        return false;
2✔
245
    }
246

247
    /**
248
     * @return \Twig\Loader\FilesystemLoader
249
     */
250
    public function get_loader()
251
    {
252
        $paths = $this->locations;
407✔
253

254
        /**
255
         * Filters the template paths used by the Loader.
256
         *
257
         * @since 0.20.10
258
         *
259
         * @deprecated 2.0.0, use `timber/locations`
260
         *
261
         * @param array $paths
262
         */
263
        $paths = \apply_filters_deprecated(
407✔
264
            'timber/loader/paths',
407✔
265
            [$paths],
407✔
266
            '2.0.0',
407✔
267
            'timber/locations'
407✔
268
        );
407✔
269

270
        $open_basedir = \ini_get('open_basedir');
407✔
271
        $rootPath = '/';
407✔
272
        if ($open_basedir) {
407✔
273
            $rootPath = null;
×
274
        }
275

276
        $fs = new FilesystemLoader([], $rootPath);
407✔
277

278
        foreach ($paths as $namespace => $path_locations) {
407✔
279
            if (\is_array($path_locations)) {
407✔
280
                \array_map(function ($path) use ($fs, $namespace) {
406✔
281
                    if (\is_string($namespace)) {
406✔
282
                        $fs->addPath($path, $namespace);
406✔
283
                    } else {
284
                        $fs->addPath($path, Loader::MAIN_NAMESPACE);
8✔
285
                    }
286
                }, $path_locations);
406✔
287
            } else {
288
                Helper::deprecated(
2✔
289
                    'add_filter( \'timber/loader/paths\', [\'path/to/my/templates\'] ) in a non-associative array',
2✔
290
                    'add_filter( \'timber/loader/paths\', [ 0 => [ \'path/to/my/templates\' ] ] )',
2✔
291
                    '2.0.0'
2✔
292
                );
2✔
293
                $fs->addPath($path_locations, self::MAIN_NAMESPACE);
2✔
294
            }
295
        }
296

297
        /**
298
         * Filters …
299
         *
300
         * @todo Add summary, description, example, parameter description
301
         *
302
         * @link https://github.com/timber/timber/pull/1254
303
         * @since 1.1.11
304
         */
305
        $fs = \apply_filters('timber/loader/loader', $fs);
407✔
306

307
        return $fs;
407✔
308
    }
309

310
    /**
311
     * @return \Twig\Environment
312
     */
313
    public function get_twig()
314
    {
315
        // Default options.
316
        $environment_options = [
405✔
317
            'debug' => WP_DEBUG,
405✔
318
            'autoescape' => false,
405✔
319
            'cache' => false,
405✔
320
        ];
405✔
321

322
        /**
323
         * Filters the environment options that are used when creating a Twig Environment instance.
324
         *
325
         * By default, Timber sets the following values:
326
         *
327
         * - `'debug' => WP_DEBUG`
328
         * - `'autoescape' => false`
329
         * - `'cache' => false`
330
         *
331
         * @api
332
         * @since 1.9.5
333
         * @link https://twig.symfony.com/doc/2.x/api.html#environment-options
334
         * @example
335
         * ```php
336
         * add_filter( 'timber/twig/environment/options', 'update_twig_environment_options' );
337
         *
338
         * /**
339
         *  * Updates Twig environment options.
340
         *  *
341
         *  * @link https://twig.symfony.com/doc/2.x/api.html#environment-options
342
         *  *
343
         *  * \@param array $options An array of environment options.
344
         *  *
345
         *  * @return array
346
         *  *\/
347
         * function update_twig_environment_options( $options ) {
348
         *     $options['cache']       = true;
349
         *     $options['auto_reload'] = true;
350
         *
351
         *     return $options;
352
         * }
353
         * ```
354
         *
355
         * @param array $environment_options An array of Twig environment options.
356
         */
357
        $environment_options = \apply_filters(
405✔
358
            'timber/twig/environment/options',
405✔
359
            $environment_options
405✔
360
        );
405✔
361

362
        /**
363
         * @deprecated 2.0.0
364
         */
365
        if (isset(Timber::$autoescape) && false !== Timber::$autoescape) {
405✔
366
            Helper::deprecated(
1✔
367
                'Timber::$autoescape',
1✔
368
                'the \'timber/twig/environment/options filter\'',
1✔
369
                '2.0.0'
1✔
370
            );
1✔
371

372
            $environment_options['autoescape'] = Timber::$autoescape;
1✔
373
        }
374

375
        /**
376
         * Backwards compatibility fix.
377
         *
378
         * The value `true` doesn’t exist anymore for the `autoescape` option. You need to define
379
         * an auto-escaping fallback strategy. This fallback uses the `html` strategy.
380
         */
381
        if (true === $environment_options['autoescape']) {
405✔
382
            $environment_options['autoescape'] = 'html';
2✔
383
        }
384

385
        /**
386
         * Alias Timber::$cache can be used for Timber::$twig_cache.
387
         *
388
         * @deprecated 2.0.0
389
         */
390
        if (isset(Timber::$cache) && true === Timber::$cache) {
405✔
391
            Timber::$twig_cache = true;
1✔
392
        }
393

394
        /**
395
         * @deprecated 2.0.0
396
         */
397
        if (isset(Timber::$twig_cache) && false !== Timber::$twig_cache) {
405✔
398
            Helper::deprecated(
2✔
399
                'Timber::$cache and Timber::$twig_cache',
2✔
400
                'the \'timber/twig/environment/options filter\'',
2✔
401
                '2.0.0'
2✔
402
            );
2✔
403

404
            $environment_options['cache'] = Timber::$twig_cache;
2✔
405
        }
406

407
        if (true === $environment_options['cache']) {
405✔
408
            $twig_cache_loc = TIMBER_LOC . '/cache/twig';
6✔
409

410
            /**
411
             * Filters the cache location used for Twig.
412
             *
413
             * Allows you to set a new cache location for Twig. If the folder doesn’t exist yet, it
414
             * will be created automatically.
415
             *
416
             * @since 0.20.10
417
             * @deprecated 2.0.0
418
             *
419
             * @param string $twig_cache_loc Full path to the cache location. Default `/cache/twig`
420
             *                               in the Timber root folder.
421
             */
422
            $twig_cache_loc = \apply_filters_deprecated(
6✔
423
                'timber/cache/location',
6✔
424
                [$twig_cache_loc],
6✔
425
                '2.0.0',
6✔
426
                'timber/twig/environment/options'
6✔
427
            );
6✔
428

429
            if (!\file_exists($twig_cache_loc)) {
6✔
430
                \mkdir($twig_cache_loc, 0777, true);
6✔
431
            }
432

433
            $environment_options['cache'] = $twig_cache_loc;
6✔
434
        }
435
        $twig = new \Twig\Environment($this->get_loader(), $environment_options);
405✔
436

437
        if (WP_DEBUG) {
405✔
438
            $twig->addExtension(new \Twig\Extension\DebugExtension());
405✔
439
        } else {
440
            $twig->addFunction(new TwigFunction('dump', function () {
×
441
                return null;
×
442
            }));
×
443
        }
444

445
        /**
446
         * Filters the cache extension activation.
447
         *
448
         * Allows users to disable the cache extension and use their own
449
         *
450
         * @since 2.0.0
451
         * @param bool $enable_cache_extension Whether to enable the cache extension.
452
         */
453
        $enable_cache_extension = \apply_filters('timber/cache/enable_extension', true);
405✔
454

455
        if ($enable_cache_extension && \class_exists('\Twig\CacheExtension\Extension')) {
405✔
456
            $twig->addExtension($this->_get_cache_extension());
×
457
        }
458

459
        /**
460
         * Filters …
461
         *
462
         * @todo Add summary, description, example
463
         *
464
         * @since 0.20.10
465
         *
466
         * @param \Twig\Environment $twig The Twig environment you can add functionality to.
467
         */
468
        $twig = \apply_filters('timber/loader/twig', $twig);
405✔
469

470
        /**
471
         * Filters …
472
         *
473
         * @deprecated 2.0.0, use `timber/twig`
474
         */
475
        $twig = \apply_filters_deprecated('twig_apply_filters', [$twig], '2.0.0', 'timber/twig');
405✔
476

477
        /**
478
         * Filters the Twig environment used in the global context.
479
         *
480
         * You can use this filter if you want to add additional functionality to Twig, like global
481
         * variables, filters or functions.
482
         *
483
         * @since 0.21.9
484
         * @example
485
         * ```php
486
         * /**
487
         *  * Adds Twig functionality.
488
         *  *
489
         *  * \@param \Twig\Environment $twig The Twig Environment to which you can add additional functionality.
490
         *  *\/
491
         * add_filter( 'timber/twig', function( $twig ) {
492
         *     // Make get_theme_file_uri() usable as {{ theme_file() }} in Twig.
493
         *     $twig->addFunction( new Twig\TwigFunction( 'theme_file', 'get_theme_file_uri' ) );
494
         *
495
         *     return $twig;
496
         * } );
497
         * ```
498
         *
499
         * ```twig
500
         * <a class="navbar-brand" href="{{ site.url }}">
501
         *     <img src="{{ theme_file( 'build/img/logo-example.svg' ) }}" alt="Logo {{ site.title }}">
502
         * </a>
503
         * ```
504
         *
505
         * @param \Twig\Environment $twig The Twig environment.
506
         */
507
        $twig = \apply_filters('timber/twig', $twig);
405✔
508

509
        /**
510
         * Filters the Twig environment used in the global context.
511
         *
512
         * @deprecated 2.0.0
513
         */
514
        $twig = \apply_filters_deprecated('get_twig', [$twig], '2.0.0', 'timber/twig');
405✔
515

516
        return $twig;
405✔
517
    }
518

519
    /**
520
     * Clears Timber’s cache.
521
     *
522
     * @param string $cache_mode
523
     * @return bool Whether Timber’s cache was cleared
524
     */
525
    public function clear_cache_timber($cache_mode = self::CACHE_USE_DEFAULT)
526
    {
527
        //_transient_timberloader
528
        $cache_mode = $this->_get_cache_mode($cache_mode);
5✔
529

530
        if (self::CACHE_TRANSIENT === $cache_mode || self::CACHE_SITE_TRANSIENT === $cache_mode) {
5✔
531
            // $wpdb->query() might return 0 affected rows, but that means it’s still successful.
532
            return false !== self::clear_cache_timber_database();
4✔
533
        } elseif (self::CACHE_OBJECT === $cache_mode && $this->is_object_cache()) {
1✔
534
            return false !== self::clear_cache_timber_object();
1✔
535
        }
536

537
        return false;
×
538
    }
539

540
    /**
541
     * Clears Timber cache in database.
542
     *
543
     * @return bool|int Number of deleted rows or false on error.
544
     */
545
    protected static function clear_cache_timber_database()
546
    {
547
        global $wpdb;
548

549
        return $wpdb->query($wpdb->prepare(
4✔
550
            "DELETE FROM $wpdb->options WHERE option_name LIKE '%s'",
4✔
551
            '_transient%timberloader_%'
4✔
552
        ));
4✔
553
    }
554

555
    /**
556
     * @return bool True when no cache was found or all cache was deleted, false when there was an
557
     *              error deleting the cache.
558
     */
559
    protected static function clear_cache_timber_object()
560
    {
561
        global $wp_object_cache;
562

563
        $result = true;
1✔
564

565
        // Return true if no object cache is set.
566
        if (!isset($wp_object_cache->cache[self::CACHEGROUP])) {
1✔
567
            return $result;
×
568
        }
569

570
        $items = $wp_object_cache->cache[self::CACHEGROUP];
1✔
571

572
        foreach ($items as $key => $value) {
1✔
573
            if (\is_multisite()) {
1✔
574
                $key = \preg_replace('/^(.*?):/', '', $key);
×
575
            }
576

577
            // If any cache couldn’t be deleted, the result will be false.
578
            if (!\wp_cache_delete($key, self::CACHEGROUP)) {
1✔
579
                $result = false;
×
580
            }
581
        }
582

583
        return $result;
1✔
584
    }
585

586
    public function clear_cache_twig()
587
    {
588
        $twig = $this->get_twig();
8✔
589

590
        // Get the configured cache location.
591
        $cache_location = $twig->getCache(true);
8✔
592

593
        // Cache not activated.
594
        if (!$cache_location) {
8✔
595
            return true;
2✔
596
        }
597

598
        if (\is_string($cache_location) && \is_dir($cache_location)) {
6✔
599
            self::rrmdir($cache_location);
6✔
600
            return true;
6✔
601
        }
602

603
        return false;
×
604
    }
605

606
    /**
607
     * Remove a directory and everything inside
608
     *
609
     * @param string|false $dirPath
610
     */
611
    public static function rrmdir($dirPath)
612
    {
613
        if (!\is_dir($dirPath)) {
6✔
614
            throw new InvalidArgumentException("$dirPath must be a directory");
×
615
        }
616
        if (\substr($dirPath, \strlen($dirPath) - 1, 1) != '/') {
6✔
617
            $dirPath .= '/';
6✔
618
        }
619
        $files = \glob($dirPath . '*', GLOB_MARK);
6✔
620
        foreach ($files as $file) {
6✔
621
            if (\is_dir($file)) {
1✔
622
                self::rrmdir($file);
1✔
623
            } else {
624
                \unlink($file);
1✔
625
            }
626
        }
627
        \rmdir($dirPath);
6✔
628
    }
629

630
    /**
631
     * @return \Twig\CacheExtension\Extension
632
     */
633
    private function _get_cache_extension()
634
    {
635
        $key_generator = new \Timber\Cache\KeyGenerator();
×
636
        $cache_provider = new \Timber\Cache\WPObjectCacheAdapter($this);
×
637
        $cache_lifetime = \apply_filters('timber/cache/extension/lifetime', 0);
×
638
        $cache_strategy = new CacheExtension\CacheStrategy\GenerationalCacheStrategy(
×
639
            $cache_provider,
×
640
            $key_generator,
×
641
            $cache_lifetime
×
642
        );
×
643
        $cache_extension = new CacheExtension\Extension($cache_strategy);
×
644

645
        return $cache_extension;
×
646
    }
647

648
    /**
649
     * @param string $key
650
     * @param string $group
651
     * @param string $cache_mode
652
     * @return bool
653
     */
654
    public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT)
655
    {
656
        $cache_mode = $this->_get_cache_mode($cache_mode);
12✔
657
        $value = false;
12✔
658
        $trans_key = \substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
12✔
659

660
        if (self::CACHE_TRANSIENT === $cache_mode) {
12✔
661
            $value = \get_transient($trans_key);
8✔
662
        } elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) {
6✔
663
            $value = \get_site_transient($trans_key);
1✔
664
        } elseif (self::CACHE_OBJECT === $cache_mode && $this->is_object_cache()) {
5✔
665
            $value = \wp_cache_get($key, $group);
4✔
666
        }
667

668
        return $value;
12✔
669
    }
670

671
    /**
672
     * @param string $key
673
     * @param string|boolean $value
674
     * @param string $group
675
     * @param integer $expires
676
     * @param string $cache_mode
677
     * @return string|boolean
678
     */
679
    public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT)
680
    {
681
        if ((int) $expires < 1) {
12✔
682
            $expires = 0;
1✔
683
        }
684

685
        $cache_mode = $this->_get_cache_mode($cache_mode);
12✔
686
        $trans_key = \substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
12✔
687

688
        if (self::CACHE_TRANSIENT === $cache_mode) {
12✔
689
            \set_transient($trans_key, $value, $expires);
8✔
690
        } elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) {
6✔
691
            \set_site_transient($trans_key, $value, $expires);
1✔
692
        } elseif (self::CACHE_OBJECT === $cache_mode && $this->is_object_cache()) {
5✔
693
            \wp_cache_set($key, $value, $group, $expires);
4✔
694
        }
695

696
        return $value;
12✔
697
    }
698

699
    /**
700
     * @param string $cache_mode
701
     * @return string
702
     */
703
    private function _get_cache_mode($cache_mode)
704
    {
705
        if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) {
13✔
706
            $cache_mode = $this->cache_mode;
10✔
707
        }
708

709
        // Fallback if self::$cache_mode did not get a valid value
710
        if (!\in_array($cache_mode, self::$cache_modes)) {
13✔
711
            $cache_mode = self::CACHE_OBJECT;
×
712
        }
713

714
        return $cache_mode;
13✔
715
    }
716

717
    /**
718
     * Checks whether WordPress object cache is activated.
719
     *
720
     * @since 2.0.0
721
     * @return bool
722
     */
723
    protected function is_object_cache()
724
    {
725
        return isset($GLOBALS['wp_object_cache']) && \is_object($GLOBALS['wp_object_cache']);
4✔
726
    }
727
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc