Skip to content

Commit

Permalink
Merge pull request #732 from helsingborg-stad/feature/clear-oembed-cache
Browse files Browse the repository at this point in the history
feat: clear oembed cache
  • Loading branch information
NiclasNorin authored Oct 31, 2023
2 parents a3dafc9 + 295ca2d commit 71308ab
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions library/Helper/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public static function clearCache($postId, $post)
wp_cache_delete($postId, self::getKeyGroup());
wp_cache_delete($post->post_type, self::getKeyGroup());

self::clearOembedCache($postId);

// Empty post type for all sites in network (?)
if (function_exists('is_multisite') && is_multisite() && apply_filters('Municipio\Cache\EmptyForAllBlogs', false, $post)) {
$blogs = get_sites();
Expand All @@ -87,6 +89,23 @@ public static function clearCache($postId, $post)
return true;
}

/**
* Clears Oembed cache
* @param integer $postId Post id to clear
*/
public static function clearOembedCache(int $postId) {
global $wpdb;

$metaKeyPattern = '_oembed_%';
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s AND post_id = %d",
$metaKeyPattern,
$postId
)
);
}

/**
* Starts the "cache engine"
* @return boolean Returns true if engine started or inactivated, returns false if previous cache is loaded
Expand Down

0 comments on commit 71308ab

Please sign in to comment.