| @@ -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 extend 'Render_Mode_Base'." ); | |
| 66 | 62 | } |
| 67 | 63 | |
| 68 | 64 | $this->render_modes[ $class_name::get_name() ] = $class_name; |
| 69 | 65 | |
| @@ -96,12 +92,10 @@ | ||
| 96 | 92 | * @return $this |
| 97 | 93 | */ |
| 98 | 94 | private function choose_render_mode() { |
| 99 | 95 | $post_id = null; |
| 100 | - $template_id = null; | |
| 101 | 96 | $key = null; |
| 102 | 97 | $nonce = null; |
| 103 | - $kit_preview = null; | |
| 104 | 98 | |
| 105 | 99 | if ( isset( $_GET[ self::QUERY_STRING_POST_ID ] ) ) { |
| 106 | 100 | $post_id = $_GET[ self::QUERY_STRING_POST_ID ]; // phpcs:ignore -- Nonce will be checked next line. |
| 107 | 101 | } |
| @@ -113,12 +107,8 @@ | ||
| 113 | 107 | if ( isset( $_GET[ self::QUERY_STRING_PARAM_NAME ] ) ) { |
| 114 | 108 | $key = $_GET[ self::QUERY_STRING_PARAM_NAME ]; // phpcs:ignore -- Nonce will be checked next line. |
| 115 | 109 | } |
| 116 | 110 | |
| 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 | 111 | if ( |
| 122 | 112 | $post_id && |
| 123 | 113 | $nonce && |
| 124 | 114 | wp_verify_nonce( $nonce, self::get_nonce_action( $post_id ) ) && |
| @@ -125,10 +115,8 @@ | ||
| 125 | 115 | $key && |
| 126 | 116 | array_key_exists( $key, $this->render_modes ) |
| 127 | 117 | ) { |
| 128 | 118 | $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 ) ); | |
| 131 | 119 | } else { |
| 132 | 120 | $this->set_current( new Render_Mode_Normal( $post_id ) ); |
| 133 | 121 | } |
| 134 | 122 | |
| @@ -134,33 +122,13 @@ | ||
| 134 | 122 | |
| 135 | 123 | return $this; |
| 136 | 124 | } |
| 137 | 125 | |
| 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 | 126 | /** |
| 159 | 127 | * Add actions base on the current render. |
| 160 | 128 | * |
| 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. | |
| 129 | + * @throws \Requests_Exception_HTTP_403 | |
| 130 | + * @throws Status403 | |
| 163 | 131 | */ |
| 164 | 132 | private function add_current_actions() { |
| 165 | 133 | if ( ! $this->current->get_permissions_callback() ) { |
| 166 | 134 | // WP >= 6.2-alpha |
| @@ -177,9 +145,9 @@ | ||
| 177 | 145 | |
| 178 | 146 | /** |
| 179 | 147 | * Render_Mode_Manager constructor. |
| 180 | 148 | * |
| 181 | - * @throws \Exception If the render mode registration fails. | |
| 149 | + * @throws \Exception | |
| 182 | 150 | */ |
| 183 | 151 | public function __construct() { |
| 184 | 152 | $this->register_render_mode( Render_Mode_Normal::class ); |
| 185 | 153 | |