Skip to content

Commit 2d576a2

Browse files
committed
Optionally flush transients
1 parent f6d52dd commit 2d576a2

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

classes/PodsAPI.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11311,17 +11311,19 @@ public function csv_to_php( $data, $delimiter = ',' ) {
1131111311
* @param bool $flush_groups_and_fields Whether to flush cache for groups and fields.
1131211312
* @param bool $static_only Whether to flush only static caches.
1131311313
* @param bool $flush_object_cache Whether to fully flush object caches.
11314+
* @param bool $delete_transients Whether to fully delete transients.
1131411315
*
1131511316
* @return void
1131611317
*
1131711318
* @since 2.0.0
1131811319
*/
1131911320
public function cache_flush_pods(
1132011321
$pod = null,
11321-
$flush_rewrites = true,
11322-
$flush_groups_and_fields = true,
11323-
$static_only = false,
11324-
$flush_object_cache = false
11322+
bool $flush_rewrites = true,
11323+
bool $flush_groups_and_fields = true,
11324+
bool $static_only = false,
11325+
bool $flush_object_cache = false,
11326+
bool $delete_transients = false
1132511327
) {
1132611328

1132711329
/**
@@ -11396,11 +11398,11 @@ public function cache_flush_pods(
1139611398
pods_init()->refresh_existing_content_types_cache( true );
1139711399

1139811400
if ( ! $static_only ) {
11399-
// Delete transients in the database
11401+
// Delete transients in the database.
1140011402
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_pods%'" );
1140111403
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_pods%'" );
1140211404

11403-
// Delete Pods Options Cache in the database
11405+
// Delete Pods Options Cache in the database.
1140411406
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_pods_option_%'" );
1140511407

1140611408
if ( class_exists( \Pods_Unit_Tests\Pods_UnitTestCase::class ) ) {
@@ -11410,9 +11412,16 @@ public function cache_flush_pods(
1141011412
// Do normal cache clear.
1141111413
pods_cache_clear( true );
1141211414

11415+
// Maybe flush the full object cache.
1141311416
if ( $flush_object_cache ) {
1141411417
wp_cache_flush();
1141511418
}
11419+
11420+
// Maybe delete all transients in the database.
11421+
if ( $delete_transients ) {
11422+
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_%'" );
11423+
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_%'" );
11424+
}
1141611425
}
1141711426

1141811427
if ( $flush_rewrites ) {
@@ -11430,8 +11439,9 @@ public function cache_flush_pods(
1143011439
* @param bool $flush_groups_and_fields Whether to flush cache for groups and fields.
1143111440
* @param bool $static_only Whether to flush only static caches.
1143211441
* @param bool $flush_object_cache Whether to fully flush object caches.
11442+
* @param bool $delete_transients Whether to fully delete transients.
1143311443
*/
11434-
do_action( 'pods_cache_flushed', $pod, $flush_rewrites, $flush_groups_and_fields, $static_only, $flush_object_cache );
11444+
do_action( 'pods_cache_flushed', $pod, $flush_rewrites, $flush_groups_and_fields, $static_only, $flush_object_cache, $flush_transients );
1143511445
}
1143611446

1143711447
/**

ui/admin/settings-settings.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,30 @@
3838
// Handle clearing cache.
3939
$api = pods_api();
4040

41+
$flush_objects = (int) pods_v( 'pods_cache_flush_objects', 'post' );
42+
$delete_transients = (int) pods_v( 'pods_cache_delete_transients', 'post' );
43+
4144
$api->cache_flush_pods(
4245
null,
4346
true,
4447
true,
4548
false,
46-
true
49+
1 === $flush_objects,
50+
1 === $delete_transients
4751
);
4852

4953
if ( defined( 'PODS_PRELOAD_CONFIG_AFTER_FLUSH' ) && PODS_PRELOAD_CONFIG_AFTER_FLUSH ) {
5054
$api->load_pods( array( 'bypass_cache' => true ) );
5155
}
5256

53-
pods_redirect( pods_query_arg( array( 'pods_cache_flushed' => 1, 'pods_cache_flush_objects' => (int) pods_v( 'pods_cache_flush_objects', 'post' ) ), array( 'page', 'tab' ) ) );
57+
pods_redirect( pods_query_arg( [
58+
'pods_cache_flushed' => 1,
59+
'pods_cache_flush_objects' => $flush_objects,
60+
'pods_cache_delete_transients' => $delete_transients,
61+
], [
62+
'page',
63+
'tab',
64+
] ) );
5465
} else {
5566
// Handle saving settings.
5667
$action = __( 'saved', 'pods' );
@@ -125,7 +136,12 @@
125136
   
126137
<label>
127138
<input type="checkbox" name="pods_cache_flush_objects" value="1"<?php checked( pods_v( 'pods_cache_flush_objects', 'get', 1 ) ); ?> />
128-
<?php esc_html_e( 'Also flush all WordPress object caches', 'pods' ); ?>
139+
<?php esc_html_e( 'Flush WordPress object caches', 'pods' ); ?>
140+
</label>
141+
&nbsp;&nbsp;&nbsp;
142+
<label>
143+
<input type="checkbox" name="pods_cache_delete_transients" value="1"<?php checked( pods_v( 'pods_cache_delete_transients', 'get', 1 ) ); ?> />
144+
<?php esc_html_e( 'Flush WordPress transient cache', 'pods' ); ?>
129145
</label>
130146
</p>
131147

0 commit comments

Comments
 (0)