WPSEO_Sitemaps_Cache_Validator::cleanup_database
Cleanup invalidated database cache.
Метод класса: WPSEO_Sitemaps_Cache_Validator{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = WPSEO_Sitemaps_Cache_Validator::cleanup_database( $type, $validator );
- $type(строка|null)
- The type of sitemap to clear cache for.
По умолчанию:null - $validator(строка|null)
- The validator to clear cache of.
По умолчанию:null
Список изменений
| С версии 3.2 | Введена. |
Код WPSEO_Sitemaps_Cache_Validator::cleanup_database() WPSEO Sitemaps Cache Validator::cleanup database Yoast 27.3
public static function cleanup_database( $type = null, $validator = null ) {
global $wpdb;
if ( $type === null ) {
// Clear all cache if no type is provided.
$like = sprintf( '%s%%', self::STORAGE_KEY_PREFIX );
}
else {
// Clear type cache for all type keys.
$like = sprintf( '%1$s%2$s_%%', self::STORAGE_KEY_PREFIX, $type );
}
/*
* Add slashes to the LIKE "_" single character wildcard.
*
* We can't use `esc_like` here because we need the % in the query.
*/
$where = [];
$where[] = sprintf( "option_name LIKE '%s'", addcslashes( '_transient_' . $like, '_' ) );
$where[] = sprintf( "option_name LIKE '%s'", addcslashes( '_transient_timeout_' . $like, '_' ) );
// Delete transients.
//phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to use a direct query here.
//phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
$wpdb->query(
$wpdb->prepare(
//phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized.
'DELETE FROM %i WHERE ' . implode( ' OR ', array_fill( 0, count( $where ), '%s' ) ),
array_merge( [ $wpdb->options ], $where ),
),
);
wp_cache_delete( 'alloptions', 'options' );
}