Automattic\WooCommerce\Internal\EmailEditor

PageRenderer::get_edited_itemprivateWC 1.0

Check if the post can be edited in the email editor.

Method of the class: PageRenderer{}

No Hooks.

Returns

\WP_Post|\WP_Block_Template|null. Edited item or null if the item is not found.

Usage

// private - for code of main (parent) class only
$result = $this->get_edited_item( $id, $type );
$id(int|string) (required)
The post ID.
$type(string) (required)
The post type.

PageRenderer::get_edited_item() code WC 10.3.6

private function get_edited_item( $id, string $type ) {
	// When we pass template we need to verify that the template is registered in the email template registry.
	if ( 'wp_template' === $type ) {
		$wp_template = get_block_template( $id );
		if ( ! $wp_template ) {
			return null;
		}
		$email_template = $this->template_registry->get_by_slug( $wp_template->slug );
		return $email_template instanceof Template ? $wp_template : null;
	}

	// For post we need to verify that the post is of the email type.
	$post = get_post( $id );
	if ( $post instanceof \WP_Post && $type === $post->post_type ) {
		return $post;
	}

	return null;
}