Skip to content

Commit 79648d6

Browse files
committed
Optionally flush transients
1 parent 987dfd1 commit 79648d6

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
/**
@@ -11395,11 +11397,11 @@ public function cache_flush_pods(
1139511397
pods_init()->refresh_existing_content_types_cache( true );
1139611398

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

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

1140511407
if ( class_exists( \Pods_Unit_Tests\Pods_UnitTestCase::class ) ) {
@@ -11409,9 +11411,16 @@ public function cache_flush_pods(
1140911411
// Do normal cache clear.
1141011412
pods_cache_clear( true );
1141111413

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

1141711426
if ( $flush_rewrites ) {
@@ -11429,8 +11438,9 @@ public function cache_flush_pods(
1142911438
* @param bool $flush_groups_and_fields Whether to flush cache for groups and fields.
1143011439
* @param bool $static_only Whether to flush only static caches.
1143111440
* @param bool $flush_object_cache Whether to fully flush object caches.
11441+
* @param bool $delete_transients Whether to fully delete transients.
1143211442
*/
11433-
do_action( 'pods_cache_flushed', $pod, $flush_rewrites, $flush_groups_and_fields, $static_only, $flush_object_cache );
11443+
do_action( 'pods_cache_flushed', $pod, $flush_rewrites, $flush_groups_and_fields, $static_only, $flush_object_cache, $flush_transients );
1143411444
}
1143511445

1143611446
/**

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' );
@@ -122,7 +133,12 @@
122133
   
123134
<label>
124135
<input type="checkbox" name="pods_cache_flush_objects" value="1"<?php checked( pods_v( 'pods_cache_flush_objects', 'get', 1 ) ); ?> />
125-
<?php esc_html_e( 'Also flush all WordPress object caches', 'pods' ); ?>
136+
<?php esc_html_e( 'Flush WordPress object caches', 'pods' ); ?>
137+
</label>
138+
&nbsp;&nbsp;&nbsp;
139+
<label>
140+
<input type="checkbox" name="pods_cache_delete_transients" value="1"<?php checked( pods_v( 'pods_cache_delete_transients', 'get', 1 ) ); ?> />
141+
<?php esc_html_e( 'Flush WordPress transient cache', 'pods' ); ?>
126142
</label>
127143
</p>
128144

0 commit comments

Comments
 (0)