PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
← All changes | api/Resource/BaseResourceApi.php +11 -4 1.6.0 → 1.6.5 View file →
@@ -83,11 +83,14 @@
83 83 * 'data' => Optional. Error data. Default empty string.
84 84 * ],
85 85 * string
86 86 * ]
87 + * @param int|null $status HTTP status the framework's wpErrorToResponse should use
88 + * (Route::dispatch converts any returned WP_Error via rest_convert_error_to_response,
89 + * which reads error_data['status'] and falls back to 500 when absent).
87 90 * @return WP_Error
88 91 */
89 - public static function makeErrorResponse($errors): WP_Error
92 + public static function makeErrorResponse($errors, ?int $status = null): WP_Error
90 93 {
91 94 $wpError = new WP_Error();
92 95
93 96 if (is_array($errors)) {
@@ -92,19 +95,23 @@
92 95
93 96 if (is_array($errors)) {
94 97 foreach ($errors as $key => $error) {
95 98 if (is_array($error)) {
99 + $data = Arr::get($error, 'data', '');
100 + if ($status) {
101 + $data = is_array($data) ? array_merge($data, ['status' => $status]) : ['status' => $status];
102 + }
96 103 $wpError->add(
97 104 Arr::get($error, 'code', $key),
98 105 Arr::get($error, 'message'),
99 - Arr::get($error, 'data', '')
106 + $data
100 107 );
101 108 } else {
102 - $wpError->add($key, $error);
109 + $wpError->add($key, $error, $status ? ['status' => $status] : '');
103 110 }
104 111 }
105 112 } else {
106 - $wpError->add($errors, $errors);
113 + $wpError->add($errors, $errors, $status ? ['status' => $status] : '');
107 114 }
108 115 return $wpError;
109 116 }
110 117