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.
Метод класса: Integration{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$Integration = new Integration(); $Integration->save_email_mapping_on_publish( $new_status, $old_status, $post ): void;
- $new_status(строка) (обязательный)
- New post status.
- $old_status(строка) (обязательный)
- Old post status.
- $post(WP_Post) (обязательный)
- Post object.
Список изменений
| С версии 11.1.0 | Введена. |
Код Integration::save_email_mapping_on_publish() Integration::save email mapping on publish WC 11.3.0
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 );
}