Automattic\WooCommerce\Internal\Admin\Emails
EmailListingRestController::find_unpublished_post_for_email_type
Find an existing unpublished post (editing scratchpad) for the given email type.
Scratchpads are created as drafts. The auto-draft status is matched as well so the lookup keeps working when scratchpad creation switches to auto-drafts (planned once the Gutenberg auto-draft title blanking is fixed upstream) — including during the transition, when a site can hold a mix of both.
Метод класса: EmailListingRestController{}
Хуков нет.
Возвращает
\WP_Post|null. The post if found, null otherwise.
Использование
// private - только в коде основоного (родительского) класса $result = $this->find_unpublished_post_for_email_type( $email_id ): ?\WP_Post;
- $email_id(строка) (обязательный)
- The email type identifier.
Код EmailListingRestController::find_unpublished_post_for_email_type() EmailListingRestController::find unpublished post for email type WC 11.2.2
private function find_unpublished_post_for_email_type( string $email_id ): ?\WP_Post {
$posts = get_posts(
array(
'post_type' => Integration::EMAIL_POST_TYPE,
'post_status' => array( 'auto-draft', 'draft' ),
'meta_key' => WCTransactionalEmailPostsManager::EMAIL_TYPE_META_KEY, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Scoped to a handful of unpublished woo_email posts.
'meta_value' => $email_id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Scoped to a handful of unpublished woo_email posts.
'posts_per_page' => 1,
'orderby' => 'ID',
'order' => 'DESC',
)
);
return $posts[0] ?? null;
}