Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1.             $expiration_keys = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%'" );
  2.            
  3.             $now              = current_time( 'timestamp' );
  4.             $expired_sessions = array();
  5.            
  6.             foreach ( $expiration_keys as $expiration ) {
  7.                
  8.                 // If the session has expired
  9.                 if ( $now > intval( $expiration->option_value ) ) {
  10.                    
  11.                     // Get the session ID by parsing the option_name
  12.                     $session_id = substr( $expiration->option_name, 20 );
  13.                    
  14.                     if ( (int) - 1 === (int) $session_id || ! preg_match( '/^[a-f0-9]{32}$/', $session_id ) ) {
  15.                         continue;
  16.                     }
  17.                    
  18.                     $expired_sessions[] = $expiration->option_name;
  19.                     $expired_sessions[] = esc_sql( "_wp_session_$session_id" );
  20.                 }
  21.             }
  22.            
  23.             // Delete all expired sessions in a single query
  24.             if ( ! empty( $expired_sessions ) ) {
  25.                 $option_names = implode( "','", $expired_sessions );
  26.                 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name IN ('$option_names')" );
  27.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement