Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCTransactionalEmailPostsManager::get_email_template_post_id │ public │ WC 1.0

Gets the post ID for a specific email template type.

Uses multi-level caching for improved performance.

Метод класса: WCTransactionalEmailPostsManager{}

Хуков нет.

Возвращает

int|false. The post ID if found, false otherwise.

Использование

$WCTransactionalEmailPostsManager = new WCTransactionalEmailPostsManager();
$WCTransactionalEmailPostsManager->get_email_template_post_id( $email_type );
$email_type(строка) (обязательный)
The type of email template e.g. 'customer_new_account' from the WC_Email->id property.

Код WCTransactionalEmailPostsManager::get_email_template_post_id() WC 11.2.2

public function get_email_template_post_id( $email_type ) {
	// Check in-memory cache first.
	$post_id_from_cache = array_search( $email_type, $this->post_id_to_email_type_cache, true );
	if ( false !== $post_id_from_cache ) {
		return $post_id_from_cache;
	}

	$this->maybe_prime_mapping_option_caches();

	$option_name = $this->get_option_name( $email_type );
	$post_id     = get_option( $option_name );

	if ( ! empty( $post_id ) ) {
		$post_id = (int) $post_id;

		// Store in in-memory cache.
		$this->post_id_to_email_type_cache[ $post_id ] = $email_type;
	}

	return $post_id;
}