@@ -148,8 +148,9 @@ class SiteWPAPIRestClient @Inject constructor(
148148 * The `jetpack/` REST namespace is only a first filter: it's registered by the shared
149149 * `automattic/jetpack-connection` package, which also ships inside Jetpack Boost, Protect, Social and
150150 * VaultPress Backup, so its presence does *not* mean the Jetpack plugin is installed. What it does give
151- * us for free is a reliable negative -- no namespace, no active Jetpack -- which keeps the plugin lookup
152- * off the refresh path for the sites that have nothing to do with Jetpack.
151+ * us for free is a reliable negative -- a namespace list without `jetpack/` means no active Jetpack --
152+ * which keeps the plugin lookup off the refresh path for the sites that have nothing to do with Jetpack.
153+ * That only holds when the list is present: an absent field is "couldn't read", not "no Jetpack".
153154 *
154155 * Reading the plugin list needs credentials and the `activate_plugins` capability, so it returns null for
155156 * sites without an application password and for users who aren't administrators. Callers must read null
@@ -159,17 +160,14 @@ class SiteWPAPIRestClient @Inject constructor(
159160 namespaces : List <String >? ,
160161 apiRootUrl : String ,
161162 payload : FetchWPAPISitePayload
162- ): JetpackPluginState ? {
163- val hasJetpackNamespace = namespaces?.any { it.startsWith(JETPACK_API_NAMESPACE_PREFIX ) } ? : false
164- if (! hasJetpackNamespace) return JetpackPluginState (isActive = false , version = null )
165-
166- val username = payload.username
167- val password = payload.password
168- return if (payload.isApplicationPassword && ! username.isNullOrEmpty() && ! password.isNullOrEmpty()) {
169- requestJetpackPlugin(apiRootUrl, username, password)
170- } else {
171- null
172- }
163+ ): JetpackPluginState ? = when {
164+ namespaces == null -> null
165+ namespaces.none { it.startsWith(JETPACK_API_NAMESPACE_PREFIX ) } ->
166+ JetpackPluginState (isActive = false , version = null )
167+ payload.isApplicationPassword &&
168+ ! payload.username.isNullOrEmpty() && ! payload.password.isNullOrEmpty() ->
169+ requestJetpackPlugin(apiRootUrl, payload.username.orEmpty(), payload.password.orEmpty())
170+ else -> null
173171 }
174172
175173 private suspend fun requestJetpackPlugin (
0 commit comments