Need a Very Simple Beaver Builder Function
-
I need to write a custom plugin that clears the Beaver Builder cache BEFORE a Saved Row is “Saved” (ie. updated) for ANY Saved Row template.
Does this code look correct?<?php
/**
* Plugin Name: Clear BB Cache Before Saved Row Update
* Description: Clears the Beaver Builder cache before updating any Saved Row.
* Author: Yours Truly
* Version: 1.1
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// Hook into Beaver Builder's before save layout action.
add_action( 'fl_builder_before_save_layout', 'clear_bb_cache_before_update_saved_row', 10, 2 );
/**
* Clear Beaver Builder Cache Before Updating Saved Rows
*
* @param int $post_id The post ID.
* @param array $data The layout data.
*/
function clear_bb_cache_before_update_saved_row( $post_id, $data ) {
// Check if the post is a saved row.
if ( 'fl-builder-template' === get_post_type( $post_id ) ) {
// Clear the Beaver Builder cache.
if ( class_exists( 'FLBuilderModel' ) ) {
FLBuilderModel::delete_asset_cache();
FLBuilderModel::delete_all_transients();
}
}
}
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.