Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer
Content_Renderer::set_template_globals
Set template globals
Method of the class: Content_Renderer{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->set_template_globals( $email_post, $template );
- $email_post(WP_Post) (required)
- Post object.
- $template(WP_Block_Template) (required)
- Block template.
Content_Renderer::set_template_globals() Content Renderer::set template globals code WC 10.5.0
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 = $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.
}