@@ -832,9 +832,13 @@ function is_local_path( string $resource_ref ): bool {
832832/**
833833 * Safe generic HTTP wrapper compatible with WP VIP.
834834 *
835- * - Use vip_safe_wp_remote_request() when available.
836- * - Fall back to wp_remote_request() on other scenarios.
837- * - Respect all call args (timeout, headers, method, etc).
835+ * By default this function uses the WordPress HTTP API for requests,
836+ * to use vip_safe_wp_remote_request() (if available) specify
837+ * `$args['use_vip'] = true`.
838+ *
839+ * As a general guide, prompt requests should use the WordPress HTTP API;
840+ * administrative requests (API authentication, scope requests) should use the
841+ * WordPress VIP API if available.
838842 *
839843 * @since 3.6.0
840844 *
@@ -846,6 +850,9 @@ function is_local_path( string $resource_ref ): bool {
846850function safe_wp_remote_request ( string $ method , string $ url , array $ args = [] ) {
847851 $ method = strtoupper ( $ method );
848852 $ args ['method ' ] = $ method ;
853+ $ use_vip = $ args ['use_vip ' ] ?? false ;
854+
855+ unset( $ args ['use_vip ' ] );
849856
850857 // Respect timeout if caller set.
851858 $ timeout = isset ( $ args ['timeout ' ] ) ? (int ) $ args ['timeout ' ] : 20 ;
@@ -860,7 +867,8 @@ function safe_wp_remote_request( string $method, string $url, array $args = [] )
860867 $ args ['headers ' ]['User-Agent ' ] = $ cached_user_agent ;
861868 }
862869
863- if ( function_exists ( 'vip_safe_wp_remote_request ' ) ) {
870+ // Use VIP-safe wrapper if available and wanted. Some requests need a longer timeout than VIP allows.
871+ if ( function_exists ( 'vip_safe_wp_remote_request ' ) && (bool ) $ use_vip ) {
864872 $ fallback = '' ;
865873 $ threshold = 3 ;
866874 $ retry = 20 ;
@@ -925,9 +933,10 @@ function safe_file_get_contents( string $file_path, array $args = [] ) {
925933/**
926934 * Safe GET wrapper compatible with WP VIP.
927935 *
928- * - Use vip_safe_wp_remote_get() when available.
929- * - Fall back to wp_remote_get() on other scenarios.
930- * - Respect all call args (timeout, headers, etc).
936+ * - By default will use the WordPress HTTP API for requests.
937+ * - If `$args['use_vip'] = true` and vip_safe_wp_remote_get() is available,
938+ * then vip_safe_wp_remote_get() will be used instead.
939+ * - Respects all call args (timeout, headers, etc).
931940 *
932941 * @since 3.6.0
933942 *
@@ -942,9 +951,10 @@ function safe_wp_remote_get( string $url, array $args = [] ) {
942951/**
943952 * Safe POST wrapper compatible with WP VIP.
944953 *
945- * - Use vip_safe_wp_remote_post() when available.
946- * - Fall back to wp_remote_post() on other scenarios.
947- * - Respect all call args (timeout, headers, etc).
954+ * - By default will use the WordPress HTTP API for requests.
955+ * - If `$args['use_vip'] = true` and vip_safe_wp_remote_post() is available,
956+ * then vip_safe_wp_remote_post() will be used instead.
957+ * - Respects all call args (timeout, headers, etc).
948958 *
949959 * @since 3.6.0
950960 *
0 commit comments