Automattic\WooCommerce\Internal\EmailEditor
Integration::save_email_mapping_on_publish
Save the email type → post ID mapping when a woo_email post is published.
Lazily created posts (drafts) carry only the _wc_email_type meta; the mapping that makes a post the rendering source for its email type is written here, on the first transition to publish. Until then the file template remains the source of truth.
Method of the class: Integration{}
No Hooks.
Returns
null. Nothing (null).
Usage
$Integration = new Integration(); $Integration->save_email_mapping_on_publish( $new_status, $old_status, $post ): void;
- $new_status(string) (required)
- New post status.
- $old_status(string) (required)
- Old post status.
- $post(WP_Post) (required)
- Post object.
Changelog
| Since 11.1.0 | Introduced. |
Integration::save_email_mapping_on_publish() Integration::save email mapping on publish code WC 11.2.1
public function save_email_mapping_on_publish( $new_status, $old_status, $post ): void {
if ( ! $post instanceof \WP_Post || self::EMAIL_POST_TYPE !== $post->post_type ) {
return;
}
if ( 'publish' !== $new_status || 'publish' === $old_status ) {
return;
}
$email_type = get_post_meta( $post->ID, WCTransactionalEmailPostsManager::EMAIL_TYPE_META_KEY, true );
if ( empty( $email_type ) || ! is_string( $email_type ) ) {
return;
}
$post_manager = WCTransactionalEmailPostsManager::get_instance();
// Only map registered email types — the meta could carry an arbitrary
// string on imported or programmatically created posts.
if ( ! $post_manager->get_email_by_id( $email_type ) ) {
return;
}
$post_manager->save_email_template_post_id( $email_type, $post->ID );
}