$args Request args. * @return array{status:int,body:string,json:mixed}|WP_Error */ public function request( $method, $url, $args = array() ) { if ( 'https' !== strtolower( (string) wp_parse_url( $url, PHP_URL_SCHEME ) ) ) { return new WP_Error( 'anar_sms_https_required', __( 'SMS gateways must use HTTPS.', 'anar-toolkit' ) ); } $args['method'] = strtoupper( $method ); $args['timeout'] = isset( $args['timeout'] ) ? absint( $args['timeout'] ) : 15; $args['redirection'] = 0; $args['user-agent'] = 'Anar-Login/' . ANAR_LOGIN_VERSION; $response = wp_safe_remote_request( esc_url_raw( $url ), $args ); if ( is_wp_error( $response ) ) { return new WP_Error( 'anar_sms_network', __( 'Could not connect to the SMS provider.', 'anar-toolkit' ), array( 'detail' => $response->get_error_message() ) ); } $status = wp_remote_retrieve_response_code( $response ); $body = wp_remote_retrieve_body( $response ); $json = json_decode( $body, true ); if ( $status < 200 || $status >= 300 ) { return new WP_Error( 'anar_sms_http', sprintf( /* translators: %d: HTTP status */ __( 'The SMS provider returned an unsuccessful response (HTTP %d).', 'anar-toolkit' ), $status ), array( 'status' => $status, 'body' => substr( wp_strip_all_tags( $body ), 0, 300 ), ) ); } return array( 'status' => $status, 'body' => $body, 'json' => $json, ); } }