jp_purge_transients

Jetpack Purge Transients.

Description

jp_purge_transients( (string) $older_than = '1 hour' ); 

Parameters (1)

0. $older_than — Optional. (string) => '1 hour'
The older than.

Usage

  1. if ( !function_exists( 'jp_purge_transients' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/protect/transient-cleanup.php'; 
  3.  
  4. // The older than. 
  5. $older_than = '1 hour'; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jp_purge_transients($older_than); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/protect/transient-cleanup.php  
  1. function jp_purge_transients( $older_than = '1 hour' ) { 
  2. global $wpdb; 
  3.  
  4. $older_than_time = strtotime( '-' . $older_than ); 
  5. if ( $older_than_time > time() || $older_than_time < 1 ) { 
  6. return false; 
  7.  
  8. $sql = $wpdb->prepare( " 
  9. SELECT REPLACE(option_name, '_transient_timeout_jpp_', '') AS transient_name 
  10. FROM {$wpdb->options} 
  11. WHERE option_name LIKE '\_transient\_timeout\_jpp\__%%' 
  12. AND option_value < %d 
  13. ", $older_than_time ); 
  14.  
  15. $transients = $wpdb->get_col( $sql ); 
  16.  
  17. $options_names = array(); 
  18.  
  19. foreach( $transients as $transient ) { 
  20. $options_names[] = '_transient_jpp_' . $transient; 
  21. $options_names[] = '_transient_timeout_jpp_' . $transient; 
  22.  
  23. if ($options_names) { 
  24. $option_names_string = implode( ', ', array_fill( 0, count( $options_names ), '%s') ); 
  25. $delete_sql = "DELETE FROM {$wpdb->options} WHERE option_name IN ($option_names_string)"; 
  26.  
  27. $delete_sql = call_user_func_array( array($wpdb, 'prepare'), array_merge( array( $delete_sql ), $options_names ) ); 
  28.  
  29. $result = $wpdb->query( $delete_sql ); 
  30. if ( !$result ) { 
  31. return false; 
  32.  
  33. return;