@@ -96,7 +96,8 @@ public function handle_ajax() {
9696 nocache_headers ();
9797
9898 if ( is_wp_error ( $ result ) ) {
99- $ status = (int ) $ result ->get_error_data ();
99+ $ error_data = $ result ->get_error_data ();
100+ $ status = is_array ( $ error_data ) && isset ( $ error_data ['status ' ] ) ? (int ) $ error_data ['status ' ] : 500 ;
100101
101102 wp_send_json_error ( $ result ->get_error_message (), $ status );
102103 }
@@ -115,20 +116,20 @@ public function handle_ajax() {
115116 */
116117 private function handle_token_request ( int $ form_id ) {
117118 if ( $ form_id < 1 ) {
118- return new WP_Error ( 'missing_form_id ' , __ ( 'A valid form_id is required. ' , 'gravity-forms-zero-spam ' ), 400 );
119+ return new WP_Error ( 'missing_form_id ' , __ ( 'A valid form_id is required. ' , 'gravity-forms-zero-spam ' ), [ ' status ' => 400 ] );
119120 }
120121
121122 $ form = GFAPI ::get_form ( $ form_id );
122123
123124 if ( ! $ form ) {
124- return new WP_Error ( 'invalid_form ' , __ ( 'Form not found. ' , 'gravity-forms-zero-spam ' ), 400 );
125+ return new WP_Error ( 'invalid_form ' , __ ( 'Form not found. ' , 'gravity-forms-zero-spam ' ), [ ' status ' => 400 ] );
125126 }
126127
127128 // Check if Zero Spam is enabled for this form.
128129 $ enabled = gf_apply_filters ( 'gf_zero_spam_check_key_field ' , $ form_id , true , $ form , [] );
129130
130131 if ( false === $ enabled ) {
131- return new WP_Error ( 'zero_spam_disabled ' , __ ( 'Zero Spam is not enabled for this form. ' , 'gravity-forms-zero-spam ' ), 400 );
132+ return new WP_Error ( 'zero_spam_disabled ' , __ ( 'Zero Spam is not enabled for this form. ' , 'gravity-forms-zero-spam ' ), [ ' status ' => 400 ] );
132133 }
133134
134135 $ rate_check = $ this ->check_rate_limit ();
@@ -193,7 +194,7 @@ private function check_rate_limit() {
193194 $ limit = (int ) apply_filters ( 'gf_zero_spam_rate_limit ' , self ::RATE_LIMIT );
194195
195196 if ( $ count >= $ limit ) {
196- return new WP_Error ( 'rate_limited ' , __ ( 'Too many requests. Please try again later. ' , 'gravity-forms-zero-spam ' ), 429 );
197+ return new WP_Error ( 'rate_limited ' , __ ( 'Too many requests. Please try again later. ' , 'gravity-forms-zero-spam ' ), [ ' status ' => 429 ] );
197198 }
198199
199200 set_transient ( $ key , $ count + 1 , 60 );
0 commit comments