PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.4
Elementor Website Builder – more than just a page builder v3.0.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | core/frontend/render-mode-manager.php +9 -58 4.1.0-dev23.0.4 View file →
@@ -2,9 +2,8 @@
2 2 namespace Elementor\Core\Frontend;
3 3
4 4 use Elementor\Core\Frontend\RenderModes\Render_Mode_Base;
5 5 use Elementor\Core\Frontend\RenderModes\Render_Mode_Normal;
6 -use Elementor\Modules\CloudLibrary\Render_Mode_Preview;
7 6
8 7 if ( ! defined( 'ABSPATH' ) ) {
9 8 exit; // Exit if accessed directly.
10 9 }
@@ -11,11 +10,8 @@
11 10
12 11 class Render_Mode_Manager {
13 12 const QUERY_STRING_PARAM_NAME = 'render_mode';
14 13 const QUERY_STRING_POST_ID = 'post_id';
15 -
16 - const QUERY_STRING_TEMPLATE_ID = 'template_id';
17 -
18 14 const QUERY_STRING_NONCE_PARAM_NAME = 'render_mode_nonce';
19 15 const NONCE_ACTION_PATTERN = 'render_mode_{post_id}';
20 16
21 17 /**
@@ -57,13 +53,13 @@
57 53 *
58 54 * @param $class_name
59 55 *
60 56 * @return $this
61 - * @throws \Exception If the class does not extend Render_Mode_Base.
57 + * @throws \Exception
62 58 */
63 59 public function register_render_mode( $class_name ) {
64 60 if ( ! is_subclass_of( $class_name, Render_Mode_Base::class ) ) {
65 - throw new \Exception( sprintf( "'%s' must extend 'Render_Mode_Base'.", esc_html( $class_name ) ) );
61 + throw new \Exception( "'{$class_name}' must extends 'Render_Mode_Base'" );
66 62 }
67 63
68 64 $this->render_modes[ $class_name::get_name() ] = $class_name;
69 65
@@ -79,29 +75,16 @@
79 75 return $this->current;
80 76 }
81 77
82 78 /**
83 - * @param Render_Mode_Base $render_mode
84 - *
85 - * @return $this
86 - */
87 - private function set_current( Render_Mode_Base $render_mode ) {
88 - $this->current = $render_mode;
89 -
90 - return $this;
91 - }
92 -
93 - /**
94 79 * Set render mode.
95 80 *
96 81 * @return $this
97 82 */
98 - private function choose_render_mode() {
83 + private function set_current_render_mode() {
99 84 $post_id = null;
100 - $template_id = null;
101 85 $key = null;
102 86 $nonce = null;
103 - $kit_preview = null;
104 87
105 88 if ( isset( $_GET[ self::QUERY_STRING_POST_ID ] ) ) {
106 89 $post_id = $_GET[ self::QUERY_STRING_POST_ID ]; // phpcs:ignore -- Nonce will be checked next line.
107 90 }
@@ -113,12 +96,8 @@
113 96 if ( isset( $_GET[ self::QUERY_STRING_PARAM_NAME ] ) ) {
114 97 $key = $_GET[ self::QUERY_STRING_PARAM_NAME ]; // phpcs:ignore -- Nonce will be checked next line.
115 98 }
116 99
117 - if ( isset( $_GET[ self::QUERY_STRING_TEMPLATE_ID ] ) ) {
118 - $template_id = $_GET[ self::QUERY_STRING_TEMPLATE_ID ]; // phpcs:ignore -- Nonce will be checked next line.
119 - }
120 -
121 100 if (
122 101 $post_id &&
123 102 $nonce &&
124 103 wp_verify_nonce( $nonce, self::get_nonce_action( $post_id ) ) &&
@@ -124,52 +103,24 @@
124 103 wp_verify_nonce( $nonce, self::get_nonce_action( $post_id ) ) &&
125 104 $key &&
126 105 array_key_exists( $key, $this->render_modes )
127 106 ) {
128 - $this->set_current( new $this->render_modes[ $key ]( $post_id ) );
129 - } elseif ( $this->is_template_preview_mode( $template_id, $key, $nonce ) ) {
130 - $this->set_current( new $this->render_modes[ $key ]( $template_id ) );
107 + $this->current = new $this->render_modes[ $key ]( $post_id );
131 108 } else {
132 - $this->set_current( new Render_Mode_Normal( $post_id ) );
109 + $this->current = new Render_Mode_Normal( $post_id );
133 110 }
134 111
135 112 return $this;
136 113 }
137 114
138 - private function is_template_preview_mode( $template_id, $render_mode, $nonce ) {
139 - if ( empty( $template_id ) ) {
140 - return false;
141 - }
142 -
143 - if ( Render_Mode_Preview::MODE !== $render_mode ) {
144 - return false;
145 - }
146 -
147 - if ( ! array_key_exists( $render_mode, $this->render_modes ) ) {
148 - return false;
149 - }
150 -
151 - if ( ! wp_verify_nonce( $nonce, self::get_nonce_action( $template_id ) ) ) {
152 - wp_die( esc_html__( 'Not Authorized', 'elementor' ), esc_html__( 'Error', 'elementor' ), 403 );
153 - }
154 -
155 - return true;
156 - }
157 -
158 115 /**
159 116 * Add actions base on the current render.
160 117 *
161 - * @throws \Requests_Exception_HTTP_403 If the current render mode does not have the required permissions.
162 - * @throws \WpOrg\Requests\Exception\Http\Status403 If the current render mode does not have the required permissions.
118 + * @throws \Requests_Exception_HTTP_403
163 119 */
164 120 private function add_current_actions() {
165 121 if ( ! $this->current->get_permissions_callback() ) {
166 - // WP >= 6.2-alpha
167 - if ( class_exists( '\WpOrg\Requests\Exception\Http\Status403' ) ) {
168 - throw new \WpOrg\Requests\Exception\Http\Status403();
169 - } else {
170 - throw new \Requests_Exception_HTTP_403();
171 - }
122 + throw new \Requests_Exception_HTTP_403();
172 123 }
173 124
174 125 // Run when 'template-redirect' actually because the the class is instantiate when 'template-redirect' run.
175 126 $this->current->prepare_render();
@@ -177,9 +128,9 @@
177 128
178 129 /**
179 130 * Render_Mode_Manager constructor.
180 131 *
181 - * @throws \Exception If the render mode registration fails.
132 + * @throws \Exception
182 133 */
183 134 public function __construct() {
184 135 $this->register_render_mode( Render_Mode_Normal::class );
185 136
@@ -184,8 +135,8 @@
184 135 $this->register_render_mode( Render_Mode_Normal::class );
185 136
186 137 do_action( 'elementor/frontend/render_mode/register', $this );
187 138
188 - $this->choose_render_mode();
139 + $this->set_current_render_mode();
189 140 $this->add_current_actions();
190 141 }
191 142 }