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

timber / timber / 5690593717

pending completion
5690593717

Pull #1617

github

web-flow
Merge f587ceffa into b563d274e
Pull Request #1617: 2.x

4433 of 4433 new or added lines in 57 files covered. (100.0%)

3931 of 4433 relevant lines covered (88.68%)

58.28 hits per line

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

74.19
/src/Cache/Cleaner.php
1
<?php
2

3
namespace Timber\Cache;
4

5
use Timber\Loader;
6

7
/**
8
 * Class Cleaner
9
 *
10
 * @api
11
 */
12
class Cleaner
13
{
14
    public static function clear_cache(string $mode = 'all'): bool
15
    /**
16
     * Clears Timber’s caches.
17
     *
18
     * @api
19
     * @since 2.0.0
20
     * @example
21
     * ```php
22
     * // Clear all caches.
23
     * Timber\Cache\Cleaner::clear_cache();
24
     *
25
     * // Clear Timber’s cache only.
26
     * Timber\Cache\Cleaner::clear_cache( 'timber' );
27
     *
28
     * // Clear Twigs’s cache only.
29
     * Timber\Cache\Cleaner::clear_cache( 'twig' );
30
     * ```
31
     *
32
     * @param string $mode Optional. The cache to clear. Accepts ``, `timber` or `twig`. Default ``, which clears all caches.
33
     * @return bool
34
     */
35
    {
36
        switch ($mode) {
37
            case 'all':
6✔
38
                $twig_cache = self::clear_cache_twig();
2✔
39
                $timber_cache = self::clear_cache_timber();
2✔
40

41
                if ($twig_cache && $timber_cache) {
2✔
42
                    return true;
2✔
43
                }
44

45
                break;
×
46
            case 'twig':
4✔
47
                return self::clear_cache_twig();
3✔
48
            case 'timber':
1✔
49
                return self::clear_cache_timber();
1✔
50
        }
51

52
        return false;
×
53
    }
54

55
    /**
56
     * Clears Timber’s cache.
57
     *
58
     * @api
59
     * @since 2.0.0
60
     * @example
61
     * ```php
62
     * Timber\Cache\Cleaner::clear_cache_timber();
63
     * ```
64
     *
65
     * @return bool
66
     */
67
    public static function clear_cache_timber()
68
    {
69
        $loader = new Loader();
3✔
70
        return $loader->clear_cache_timber();
3✔
71
    }
72

73
    /**
74
     * Clears Twig’s cache.
75
     *
76
     * @api
77
     * @since 2.0.0
78
     * @example
79
     * ```php
80
     * Timber\Cache\Cleaner::clear_cache_twig();
81
     * ```
82
     *
83
     * @return bool
84
     */
85
    public static function clear_cache_twig()
86
    {
87
        $loader = new Loader();
5✔
88
        return $loader->clear_cache_twig();
5✔
89
    }
90

91
    protected static function delete_transients_single_site()
92
    {
93
        global $wpdb;
94
        $sql = "
8✔
95
                DELETE
96
                    a, b
97
                FROM
98
                    {$wpdb->options} a, {$wpdb->options} b
8✔
99
                WHERE
100
                    a.option_name LIKE '%_transient_%' AND
101
                    a.option_name NOT LIKE '%_transient_timeout_%' AND
102
                    b.option_name = CONCAT(
103
                        '_transient_timeout_',
104
                        SUBSTRING(
105
                            a.option_name,
106
                            CHAR_LENGTH('_transient_') + 1
107
                        )
108
                    )
109
                AND b.option_value < UNIX_TIMESTAMP()
110
            ";
8✔
111
        return $wpdb->query($sql);
8✔
112
    }
113

114
    protected static function delete_transients_multisite()
115
    {
116
        global $wpdb;
117
        $sql = "
×
118
                    DELETE
119
                        a, b
120
                    FROM
121
                        {$wpdb->sitemeta} a, {$wpdb->sitemeta} b
×
122
                    WHERE
123
                        a.meta_key LIKE '_site_transient_%' AND
124
                        a.meta_key NOT LIKE '_site_transient_timeout_%' AND
125
                        b.meta_key = CONCAT(
126
                            '_site_transient_timeout_',
127
                            SUBSTRING(
128
                                a.meta_key,
129
                                CHAR_LENGTH('_site_transient_') + 1
130
                            )
131
                        )
132
                    AND b.meta_value < UNIX_TIMESTAMP()
133
                ";
×
134

135
        $clean = $wpdb->query($sql);
×
136
        return $clean;
×
137
    }
138

139
    public static function delete_transients()
140
    {
141
        global $_wp_using_ext_object_cache;
142

143
        if ($_wp_using_ext_object_cache) {
11✔
144
            return 0;
3✔
145
        }
146

147
        global $wpdb;
148
        $records = 0;
8✔
149

150
        // Delete transients from options table
151
        $records .= self::delete_transients_single_site();
8✔
152

153
        // Delete transients from multisite, if configured as such
154

155
        if (\is_multisite() && \is_main_network()) {
8✔
156
            $records .= self::delete_transients_multisite();
×
157
        }
158
        return $records;
8✔
159
    }
160
}
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

© 2026 Coveralls, Inc