query_vars['adscaleStatus'] = sanitize_key( wp_unslash( $_GET['adscaleStatus'] ) ); } // make sure endpoint request if ( ! isset( $wp->query_vars['adscaleStatus'] ) ) { return; } try { ob_start(); Helper::nocache_headers(); // Check Request (Guards) self::checkRequest(); ob_end_clean(); // Handle Request self::handleRequest(); // Default error Helper::send_response_formatted_error( self::makeErrorBody() ); } catch ( ServiceApiException $ex ) { Helper::send_response_formatted_error( self::makeErrorBody( $ex->getApiErrorCode(), $ex->getMessage(), $ex->getApiErrorDetails() ) ); } catch ( \Exception $ex ) { Helper::send_response_formatted_error( self::makeErrorBody( $ex->getCode(), $ex->getMessage() ) ); } } public static function handleRequest() { $statusData = StatusHandler::getStatusData(); $post_body_format = Helper::get_post_body_data_value( 'format' ); $post_body_format = is_string( $post_body_format ) ? $post_body_format : ''; $is_format_json_by_post_body = 'JSON' === strtoupper( trim( $post_body_format ) ); $is_format_json_by_get = isset( $_GET['format'] ) && strtoupper( sanitize_text_field( wp_unslash( $_GET['format'] ) ) ) === 'JSON'; $is_format_json = $is_format_json_by_post_body || $is_format_json_by_get; if ( $is_format_json ) { $response = StatusHandler::renderDataToJson( $statusData ); Helper::send_response( Helper::format_response( $response ), 200, '', 'text/plain' ); } else { $response = StatusHandler::renderDataToHtml( $statusData ); Helper::send_response( Helper::format_response( $response ), 200, '', 'text/html' ); } } }