Skip to content

Instantly share code, notes, and snippets.

@Pross
Created September 1, 2021 18:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pross/e1fc79700dacd93bb90ce91f10a64eac to your computer and use it in GitHub Desktop.
Save Pross/e1fc79700dacd93bb90ce91f10a64eac to your computer and use it in GitHub Desktop.
Mini plugin for Beaver Builder that clears all history states and draft data weekly for people on crippled potato hosting.
<?php
/*
Plugin Name: Beaver Builder Cleanup Tool
Description: Clears temporary data weekly
Author: <Simon>
Version: 1.0
*/
class BB_Cleanup {
protected $seconds = 604800; // Weekly.
function __construct() {
add_action( 'init', array( $this, 'set_schedule' ) );
add_action( 'fl_builder_cleanup_event', array( $this, 'cleanup_run' ) );
}
function set_schedule() {
if ( ! wp_next_scheduled( 'fl_builder_cleanup_event' ) ) {
wp_schedule_single_event( time() + $this->seconds, 'fl_builder_cleanup_event' );
}
}
function cleanup_run() {
global $wpdb;
delete_post_meta_by_key( '_fl_builder_draft' );
delete_post_meta_by_key( '_fl_builder_draft_settings' );
delete_post_meta_by_key( '_fl_builder_history_position' );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s", '%_fl_builder_history_state%' ) );
}
}
new BB_Cleanup;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment