) )->clean_all( time() - static::LIFETIME, $time_limit ); } /** * Delete the nonces. * * @param int $limit How many nonces to delete. * @param null|int $cutoff_timestamp All nonces added before this timestamp will be removed. * * @return int|false Number of removed nonces, or `false` if nothing to remove (or in case of a database error). */ public function delete( $limit = 10, $cutoff_timestamp = null ) { global $wpdb; $ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM `{$wpdb->options}`" . " WHERE `option_name` >= 'jetpack_nonce_' AND `option_name` < %s" . ' LIMIT %d', 'jetpack_nonce_' . $cutoff_timestamp, $limit ) ); if ( ! is_array( $ids ) ) { // There's an error and we can't proceed. return false; } // Removing zeroes in case AUTO_INCREMENT of the options table is broken, and all ID's are zeroes. $ids = array_filter( $ids ); if ( array() === $ids ) { // There's nothing to remove. return false; } $ids_fill = implode( ', ', array_fill( 0, count( $ids ), '%d' ) ); $args = $ids; $args[] = 'jetpack_nonce_%'; // The Code Sniffer is unable to understand what's going on... // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber return $wpdb->query( $wpdb->prepare( "DELETE FROM `{$wpdb->options}` WHERE `option_id` IN ( {$ids_fill} ) AND option_name LIKE %s", $args ) ); } /** * Clean the cached nonces valid during the current request, therefore making them invalid. * * @return bool */ public static function invalidate_request_nonces() { static::$nonces_used_this_request = array(); return true; } }