namespace WPForms\Admin\Splash;
use WPForms\Helpers\CacheBase;
class SplashCache extends CacheBase {
public const REMOTE_SOURCE = 'https://wpformsapi.com/feeds/v1/splash/';
* Determine if the class is allowed to load.
protected function allow_load(): bool {
return is_admin() || wp_doing_cron() || wpforms_doing_wp_cli();
* @return array Settings array.
protected function setup(): array {
'remote_source' => $this->get_remote_source(),
// Splash cache file name.
'cache_file' => 'splash.json',
* Time-to-live of the splash cache file in seconds.
* This applies to `uploads/wpforms/cache/splash.json` file.
* @param integer $cache_ttl Cache time-to-live, in seconds.
* Default value: WEEK_IN_SECONDS.
'cache_ttl' => (int) apply_filters( 'wpforms_admin_splash_cache_ttl', WEEK_IN_SECONDS ),
protected function get_remote_source(): string {
return defined( 'WPFORMS_SPLASH_REMOTE_SOURCE' ) ? WPFORMS_SPLASH_REMOTE_SOURCE : self::REMOTE_SOURCE;
* Prepare splash modal data.
* @param array $data Splash modal data.
protected function prepare_cache_data( $data ): array {
if ( empty( $data ) || ! is_array( $data ) ) {
$blocks = $this->prepare_blocks( $data );
if ( empty( $blocks ) ) {
$prepared_data['blocks'] = $blocks;
* @param array $data Splash modal data.
* @return array Prepared blocks.
private function prepare_blocks( array $data ): array {
$user_license = $this->get_user_license();
$user_version = $this->get_user_version();
// Filter data by plugin version.
static function ( $block ) use ( $user_license ) {
// Return only blocks that match the user license.
return in_array( $user_license, $block['type'] ?? [], true );
// Get the latest 10 blocks.
$blocks = array_slice( $blocks, 0, 10 );
$blocks = array_values( $blocks );
function ( $block ) use ( $user_version ) {
$block_version = $block['version'] ?? '';
$block['buttons'] = $this->prepare_buttons( $block['btns'] ?? [] );
// Change main button URL if the block version is greater than the user version.
if ( version_compare( $block_version, $user_version, '>' ) ) {
$block['buttons']['main'] = [
'url' => $this->get_update_url(),
'text' => __( 'Update Now', 'wpforms-lite' ),
// If the block version is less than the user version, set 'new' to false.
if ( version_compare( $block_version, $user_version, '<' ) ) {
// Set layout based on an image type.
$block['layout'] = $this->get_block_layout( $block['img'] );