summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/protect/transient-cleanup.php')
-rw-r--r--plugins/jetpack/modules/protect/transient-cleanup.php35
1 files changed, 19 insertions, 16 deletions
diff --git a/plugins/jetpack/modules/protect/transient-cleanup.php b/plugins/jetpack/modules/protect/transient-cleanup.php
index 8f1c169d..de5f5764 100644
--- a/plugins/jetpack/modules/protect/transient-cleanup.php
+++ b/plugins/jetpack/modules/protect/transient-cleanup.php
@@ -1,8 +1,11 @@
<?php
-/*
-Adapted from Purge Transients by Seebz
-https://github.com/Seebz/Snippets/tree/master/Wordpress/plugins/purge-transients
-*/
+/**
+ * Adapted from Purge Transients by Seebz
+ * https://github.com/Seebz/Snippets/tree/master/Wordpress/plugins/purge-transients
+ *
+ * @package automattic/jetpack
+ */
+
if ( ! function_exists( 'jp_purge_transients' ) ) {
/**
@@ -10,7 +13,6 @@ if ( ! function_exists( 'jp_purge_transients' ) ) {
*
* @access public
* @param string $older_than (default: '1 hour') Older Than.
- * @return void
*/
function jp_purge_transients( $older_than = '1 hour' ) {
global $wpdb;
@@ -18,13 +20,12 @@ if ( ! function_exists( 'jp_purge_transients' ) ) {
if ( $older_than_time > time() || $older_than_time < 1 ) {
return false;
}
- $sql = $wpdb->prepare( "
- SELECT REPLACE(option_name, '_transient_timeout_jpp_', '') AS transient_name
- FROM {$wpdb->options}
- WHERE option_name LIKE '\_transient\_timeout\_jpp\__%%'
- AND option_value < %d
- ", $older_than_time );
- $transients = $wpdb->get_col( $sql );
+ $sql = $wpdb->prepare(
+ // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery
+ "SELECT REPLACE(option_name, '_transient_timeout_jpp_', '') AS transient_name FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\_jpp\__%%' AND option_value < %d",
+ $older_than_time
+ );
+ $transients = $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $sql is prepared above.
$options_names = array();
foreach ( $transients as $transient ) {
$options_names[] = '_transient_jpp_' . $transient;
@@ -32,14 +33,16 @@ if ( ! function_exists( 'jp_purge_transients' ) ) {
}
if ( $options_names ) {
$option_names_string = implode( ', ', array_fill( 0, count( $options_names ), '%s' ) );
- $delete_sql = "DELETE FROM {$wpdb->options} WHERE option_name IN ($option_names_string)";
- $delete_sql = call_user_func_array( array( $wpdb, 'prepare' ), array_merge( array( $delete_sql ), $options_names ) );
- $result = $wpdb->query( $delete_sql );
+ $result = $wpdb->query(
+ $wpdb->prepare(
+ "DELETE FROM {$wpdb->options} WHERE option_name IN ($option_names_string)", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- the placeholders are set above.
+ $options_names
+ )
+ );
if ( ! $result ) {
return false;
}
}
- return;
}
}