PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.13
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.13
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/API/API.php +11 -54 3.7.22.2.13 View file →
@@ -124,30 +124,12 @@
124 124 * @param $request WP_REST_Request for getting all route request in time.
125 125 *
126 126 * @return WP_Error|boolean
127 127 */
128 - public function _permission_check( WP_REST_Request $request ) {
129 - $this->request = $request;
130 - $this->api_key = $this->utils('options')->get( 'api_key' );
131 - if(!current_user_can('delete_posts')){
132 - return false;
133 - }
134 -
135 - add_filter('wp_redirect', '__return_false', 999);
136 -
137 - return $this->permission_check( $request );
138 - }
139 -
140 - /**
141 - * @param $request WP_REST_Request for getting all route request in time.
142 - *
143 - * @return WP_Error|boolean
144 - */
145 128 public function permission_check( WP_REST_Request $request ) {
146 129 $this->request = $request;
147 130 $this->api_key = $this->utils('options')->get( 'api_key' );
148 131
149 -
150 132 if ( ! empty( $this->api_key ) ) {
151 133 return true;
152 134 }
153 135
@@ -162,9 +144,9 @@
162 144 * @return WP_Error
163 145 */
164 146 protected function permission_error( $message, $endpoint = '') {
165 147 if( empty( $message ) ) {
166 - $message = __( 'Your session has expired. Please log in again.', 'templately' );
148 + $message = __( 'Sorry, you need to login/re-login again.', 'templately' );
167 149 }
168 150
169 151 $_additional_data = [
170 152 'status' => rest_authorization_required_code(),
@@ -173,27 +155,18 @@
173 155 if( ! empty( $endpoint ) ) {
174 156 $_additional_data['endpoint'] = $endpoint;
175 157 }
176 158
177 - // Delete user logged meta data — pinned to the acting user, otherwise
178 - // Options::user_id() resolves a linked user to the global-login
179 - // administrator and clears the administrator's session instead.
180 - $options = $this->utils('options');
181 - $options->use_current_user( true );
159 + // Delete user logged meta data
160 + $this->utils('options')
161 + ->remove('user')
162 + ->remove('favourites')
163 + ->remove('reviews')
164 + ->remove('cloud_activity')
165 + ->remove('api_key');
182 166
183 - try {
184 - $options
185 - ->remove('user')
186 - ->remove('favourites')
187 - ->remove('reviews')
188 - ->remove('cloud_activity')
189 - ->remove('api_key');
190 -
191 - if( $options->who_am_i() === 'global' ) {
192 - $options->remove_global_login();
193 - }
194 - } finally {
195 - $options->use_current_user( false );
167 + if( $this->utils('options')->whoami() === 'global' ) {
168 + $this->utils('options')->remove_global_login();
196 169 }
197 170
198 171 return new WP_Error( 'invalid_api_key', $message, $_additional_data );
199 172 }
@@ -211,9 +184,9 @@
211 184 $endpoint,
212 185 [
213 186 'methods' => $methods,
214 187 'callback' => $callback,
215 - 'permission_callback' => [ $this, '_permission_check' ],
188 + 'permission_callback' => [ $this, 'permission_check' ],
216 189 'args' => $args,
217 190 ]
218 191 );
219 192 }
@@ -238,24 +211,8 @@
238 211 * @return WP_REST_Response
239 212 */
240 213 public function success( $data ) {
241 214 return new WP_REST_Response( $data, 200 );
242 - }
243 -
244 - /**
245 - * Enhanced success response wrapper that automatically adds success flag and wraps data
246 - *
247 - * @param $data mixed The data to be wrapped in the response
248 - *
249 - * @return WP_REST_Response
250 - */
251 - public function successWithData( $data ) {
252 - $enhanced_response = [
253 - 'success' => true,
254 - 'data' => $data
255 - ];
256 -
257 - return $this->success( $enhanced_response );
258 215 }
259 216 /**
260 217 * @param $error_code string
261 218 * @param $error_message string|array