| @@ -125,12 +125,16 @@ | ||
| 125 | 125 | * |
| 126 | 126 | * @return WP_Error|boolean |
| 127 | 127 | */ |
| 128 | 128 | public function _permission_check( WP_REST_Request $request ) { |
| 129 | + $this->request = $request; | |
| 130 | + $this->api_key = $this->utils('options')->get( 'api_key' ); | |
| 129 | 131 | if(!current_user_can('delete_posts')){ |
| 130 | 132 | return false; |
| 131 | 133 | } |
| 132 | 134 | |
| 135 | + add_filter('wp_redirect', '__return_false', 999); | |
| 136 | + | |
| 133 | 137 | return $this->permission_check( $request ); |
| 134 | 138 | } |
| 135 | 139 | |
| 136 | 140 | /** |
| @@ -158,9 +162,9 @@ | ||
| 158 | 162 | * @return WP_Error |
| 159 | 163 | */ |
| 160 | 164 | protected function permission_error( $message, $endpoint = '') { |
| 161 | 165 | if( empty( $message ) ) { |
| 162 | - $message = __( 'Sorry, you need to login/re-login again.', 'templately' ); | |
| 166 | + $message = __( 'Your session has expired. Please log in again.', 'templately' ); | |
| 163 | 167 | } |
| 164 | 168 | |
| 165 | 169 | $_additional_data = [ |
| 166 | 170 | 'status' => rest_authorization_required_code(), |
| @@ -225,8 +229,24 @@ | ||
| 225 | 229 | * @return WP_REST_Response |
| 226 | 230 | */ |
| 227 | 231 | public function success( $data ) { |
| 228 | 232 | return new WP_REST_Response( $data, 200 ); |
| 233 | + } | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * Enhanced success response wrapper that automatically adds success flag and wraps data | |
| 237 | + * | |
| 238 | + * @param $data mixed The data to be wrapped in the response | |
| 239 | + * | |
| 240 | + * @return WP_REST_Response | |
| 241 | + */ | |
| 242 | + public function successWithData( $data ) { | |
| 243 | + $enhanced_response = [ | |
| 244 | + 'success' => true, | |
| 245 | + 'data' => $data | |
| 246 | + ]; | |
| 247 | + | |
| 248 | + return $this->success( $enhanced_response ); | |
| 229 | 249 | } |
| 230 | 250 | /** |
| 231 | 251 | * @param $error_code string |
| 232 | 252 | * @param $error_message string|array |