Automattic\WooCommerce\Internal\EmailEditor

Integration::maybe_refresh_scratchpadprivateWC 1.0

Refresh a never-edited scratchpad from the current file template when the editor opens directly (bookmark, browser refresh) — the listing Edit flow refreshes through the REST endpoint before redirecting here.

Method of the class: Integration{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->maybe_refresh_scratchpad( $post ): void;
$post(WP_Post) (required)
Post being opened in the editor.

Integration::maybe_refresh_scratchpad() code WC 11.1.2

private function maybe_refresh_scratchpad( $post ): void {
	if ( ! in_array( $post->post_status, array( 'auto-draft', 'draft' ), true ) ) {
		return;
	}

	$post_manager = WCTransactionalEmailPostsManager::get_instance();
	$email_type   = $post_manager->get_email_type_from_post_id( $post->ID );
	if ( ! is_string( $email_type ) || '' === $email_type ) {
		return;
	}

	$email = $post_manager->get_email_by_id( $email_type );
	if ( ! $email ) {
		return;
	}

	( new WCEmailScratchpadRefresher() )->maybe_refresh( $post, $email );
}