Last active
August 20, 2024 16:36
-
-
Save Pross/0b517612bb1d1dfb17083b9b32628b82 to your computer and use it in GitHub Desktop.
Publish BB draft data on certain date/time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* Convert BB drafted changes to live data on a certain date. | |
*/ | |
class Publish_BB_Draft { | |
public $date = 'Aug 10 17:00'; // Day/time to convert | |
public $post_id = 474688; // the post/page/layout id | |
public function __construct() { | |
// Convert date to a timestamp | |
$this->date = strtotime( gmdate( 'Y-m-d H:i:s', strtotime( $this->date ) ) ); | |
// if today is after date, bail | |
if ( time() > $this->date ) { | |
return false; | |
} | |
// Schedule the single event | |
wp_schedule_single_event( $this->date, 'publish_draft_changes' ); | |
// Make the changes | |
add_action( 'publish_draft_changes', function () { | |
$draft_data = get_post_meta( $this->post_id, '_fl_builder_draft', true ); | |
$draft_settings = get_post_meta( $this->post_id, '_fl_builder_draft_settings', true ); | |
if ( ! empty( $draft_data ) && ! empty( $draft_settings ) ) { | |
update_post_meta( $this->post_id, '_fl_builder_data', $draft_data ); | |
update_post_meta( $this->post_id, '_fl_builder_data_settings', $draft_settings ); | |
} | |
} ); | |
} | |
} | |
new Publish_BB_Draft; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example to schedule multiple: