public function get_builder_content_for_display($post_id) { if (!get_post($post_id)) { return ''; } // Avoid recursion if (get_the_ID() === (int) $post_id) { $content = ''; if (Plugin::instance()->editor->is_edit_mode()) { $content = '<div class="elementor-alert elementor-alert-danger">' . __('Invalid Data: The Template ID cannot be the same as the currently edited template. Please choose a different one.', 'elementor') . '</div>'; } return $content; } // Set edit mode as false, so don't render settings and etc. use the $is_edit_mode to indicate if we need the css inline $is_edit_mode = Plugin::instance()->editor->is_edit_mode(); Plugin::instance()->editor->set_edit_mode(false); // Change the global post to current library post, so widgets can use `get_the_ID` and other post data if (isset($GLOBALS['post'])) { $global_post = $GLOBALS['post']; } $GLOBALS['post'] = get_post($post_id); $content = $this->get_builder_content($post_id, $is_edit_mode); // Restore global post if (isset($global_post)) { $GLOBALS['post'] = $global_post; } else { unset($GLOBALS['post']); } // Restore edit mode state Plugin::instance()->editor->set_edit_mode($is_edit_mode); return $content; }