From 9b2d592b9e55542c3ec427d183cf6396b2708e8e Mon Sep 17 00:00:00 2001 From: David Stone Date: Thu, 16 Apr 2026 00:36:03 -0600 Subject: [PATCH] fix: handle WP_Error array payloads in network-activate error handler When a WP_Error is serialized as JSON in an AJAX response, WordPress can return response.data as an array of error objects rather than a plain object with a .message property. Previously the error handler only checked response.data.message, so array-type WP_Error payloads fell through to the generic fallback message. Now the handler first checks Array.isArray(response.data) and extracts the message from the first element (response.data[0].message), then falls back to response.data.message for plain-object errors, and finally falls back to wu_network_activate.error_message. Guards are in place for missing array elements and missing fields to avoid runtime errors. Resolves #883 --- assets/js/network-activate.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/js/network-activate.js b/assets/js/network-activate.js index 264314ce..e5bad69d 100644 --- a/assets/js/network-activate.js +++ b/assets/js/network-activate.js @@ -45,8 +45,12 @@ jQuery(function($) { var errorMsg = wu_network_activate.error_message; - if (response.data && response.data.message) { - errorMsg = response.data.message; + if (response.data) { + if (Array.isArray(response.data) && response.data.length > 0 && response.data[ 0 ] && response.data[ 0 ].message) { + errorMsg = response.data[ 0 ].message; + } else if (response.data.message) { + errorMsg = response.data.message; + } } $message.text(errorMsg);