diff --git a/includes/api/class-wc-api-json-handler.php b/includes/api/class-wc-api-json-handler.php new file mode 100644 index 00000000000..9bad7855bbd --- /dev/null +++ b/includes/api/class-wc-api-json-handler.php @@ -0,0 +1,73 @@ +api->server->send_status( 400 ); + + $data = array( array( 'code' => 'woocommerce_api_jsonp_disabled', 'message' => __( 'JSONP support is disabled on this site', 'woocommerce' ) ) ); + } + + // Check for invalid characters (only alphanumeric allowed) + if ( preg_match( '/\W/', $_GET['_jsonp'] ) ) { + + WC()->api->server->send_status( 400 ); + + $data = array( array( 'code' => 'woocommerce_api_json_callback_invalid', __( 'The JSONP callback function is invalid', 'woocommerce' ) ) );; + } + + return $_GET['_jsonp'] . '(' . json_encode( $data ) . ')'; + } + + return json_encode( $data ); + } + +}