Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer

Content_Renderer::set_template_globalsprivateWC 1.0

Set template globals

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->set_template_globals( $email_post, $template );
$email_post(WP_Post) (обязательный)
Post object.
$template(WP_Block_Template) (обязательный)
Block template.

Код Content_Renderer::set_template_globals() WC 10.0.2

private function set_template_globals( WP_Post $email_post, WP_Block_Template $template ) {
	global $_wp_current_template_content, $_wp_current_template_id, $wp_query, $post;

	// Backup current values of globals.
	// Because overriding the globals can affect rendering of the page itself, we need to backup the current values.
	$this->backup_template_content = $_wp_current_template_content;
	$this->backup_template_id      = $_wp_current_template_id;
	$this->backup_query            = $wp_query;
	$this->backup_post             = $email_post;

	$_wp_current_template_id      = $template->id;
	$_wp_current_template_content = $template->content;
	$wp_query                     = new \WP_Query( array( 'p' => $email_post->ID ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- We need to set the query for correct rendering the blocks.
	$post                         = $email_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- We need to set the post for correct rendering the blocks.
}