diff --git a/inc/Engine/Plugin/UpdaterApiCommonSubscriber.php b/inc/Engine/Plugin/UpdaterApiCommonSubscriber.php index 7b32d418ef..a5070de344 100644 --- a/inc/Engine/Plugin/UpdaterApiCommonSubscriber.php +++ b/inc/Engine/Plugin/UpdaterApiCommonSubscriber.php @@ -81,7 +81,11 @@ public static function get_subscribed_events() { * @param string $url Requested URL. * @return array An array of requested arguments */ - public function maybe_set_rocket_user_agent( $request, string $url ) { + public function maybe_set_rocket_user_agent( $request, $url ) { + if ( ! is_string( $url ) ) { // @phpstan-ignore-line GH #7042 - $url variable may be change by other plugins to something else than string. + return $request; + } + if ( strpos( $url, self::API_HOST ) !== false ) { $request['user-agent'] = sprintf( '%s;%s', $request['user-agent'], $this->get_rocket_user_agent() ); } diff --git a/inc/Engine/Plugin/UpdaterSubscriber.php b/inc/Engine/Plugin/UpdaterSubscriber.php index 5e9c39da51..23bcc22a04 100644 --- a/inc/Engine/Plugin/UpdaterSubscriber.php +++ b/inc/Engine/Plugin/UpdaterSubscriber.php @@ -132,7 +132,11 @@ public static function get_subscribed_events() { * @param string $url The request URL. * @return array Updated array of HTTP request arguments. */ - public function exclude_rocket_from_wp_updates( $request, string $url ) { + public function exclude_rocket_from_wp_updates( $request, $url ) { + if ( ! is_string( $url ) ) { // @phpstan-ignore-line GH #7042 - $url variable may be change by other plugins to something else than string. + return $request; + } + if ( ! preg_match( '@^https?://api.wordpress.org/plugins/update-check(/|\?|$)@', $url ) || empty( $request['body']['plugins'] ) ) { // Not a plugin update request. Stop immediately. return $request;