Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter for bypass curated posts cache #276

Merged
merged 1 commit into from
May 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion includes/blocks/site-automation-block/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,23 @@ function render_block_callback( $attributes, $content, $block ) {

$curated_posts_transient_key = 'sophi_curated_posts_' . $page_name . '_' . $widget_name;

/**
* Whether to bypass caching.
*
* @since 1.1.1
* @hook sophi_bypass_curated_posts_cache
*
* @param {bool} $bypass_cache True or false.
* @param {string} $page Page name.
* @param {string} $widget Widget name.
*
* @return {bool} Whether to bypass cache.
*/
$bypass_cache = apply_filters( 'sophi_bypass_curated_posts_cache', false, $page_name, $widget_name );

$curated_posts = get_transient( $curated_posts_transient_key );

if ( false === $curated_posts ) {
if ( $bypass_cache || false === $curated_posts ) {
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_posts
$curated_posts = get_posts(
[
Expand Down