From dab2c6f570ce24d09c94121618689035047ef1b4 Mon Sep 17 00:00:00 2001 From: jamesros Date: Wed, 7 May 2025 14:31:17 -0400 Subject: [PATCH 1/2] Update class-boldgrid-backup-admin-migrate-rx-rest.php --- ...-boldgrid-backup-admin-migrate-rx-rest.php | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/admin/migrate/class-boldgrid-backup-admin-migrate-rx-rest.php b/admin/migrate/class-boldgrid-backup-admin-migrate-rx-rest.php index 5ac2570c..1ee1a0e2 100644 --- a/admin/migrate/class-boldgrid-backup-admin-migrate-rx-rest.php +++ b/admin/migrate/class-boldgrid-backup-admin-migrate-rx-rest.php @@ -373,10 +373,33 @@ public function validate_url( $request ) { ), 200 ); } - $links = explode( ',', $headers['link'] ); - $wp_json_link = array_filter( $links, function( $link ) { - return false !== strpos( $link, 'rel="https://api.w.org/"' ); - } ); + // Make sure we have an array of link‐headers. + $raw_links = isset( $headers['link'] ) + ? (array) $headers['link'] + : []; + + // Flatten all comma-separated links into one array. + $all_links = []; + foreach ( $raw_links as $header ) { + // explode may yield spaces around each link, so trim(). + $parts = array_map( 'trim', explode( ',', $header ) ); + $all_links = array_merge( $all_links, $parts ); + } + + // Find the first link with rel="https://api.w.org/". + $wp_json_link = null; + foreach ( $all_links as $link ) { + if ( false !== strpos( $link, 'rel="https://api.w.org/"' ) ) { + $wp_json_link = $link; + break; + } + } + + if ( $wp_json_link ) { + if ( preg_match( '/<([^>]+)>/', $wp_json_link, $m ) ) { + $wp_json_url = $m[1]; + } + } $rest_api_error_response = new WP_REST_Response( array( 'error' => true, @@ -390,10 +413,6 @@ public function validate_url( $request ) { return $rest_api_error_response; } - preg_match('/<([^>]+)>/', $wp_json_link[0], $matches ); - - $wp_json_url = $matches[1]; - $wp_json_response = wp_remote_get( $wp_json_url, array( From 5801a7771729f4be79e11b0b44eb5320f3ab99e0 Mon Sep 17 00:00:00 2001 From: jamesros Date: Wed, 7 May 2025 14:35:09 -0400 Subject: [PATCH 2/2] Update class-boldgrid-backup-admin-migrate-util.php --- ...ass-boldgrid-backup-admin-migrate-util.php | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/admin/migrate/class-boldgrid-backup-admin-migrate-util.php b/admin/migrate/class-boldgrid-backup-admin-migrate-util.php index 0625bae7..66b2ef26 100644 --- a/admin/migrate/class-boldgrid-backup-admin-migrate-util.php +++ b/admin/migrate/class-boldgrid-backup-admin-migrate-util.php @@ -618,14 +618,37 @@ public function get_site_rest_url( $site_url ) { return $response; } $headers = $response['headers']->getAll(); - $links = explode( ',', $headers['link'] ); - $wp_json_link = array_filter( $links, function( $link ) { - return false !== strpos( $link, 'rel="https://api.w.org/"' ); - } ); + // Make sure we have an array of link‐headers + $raw_links = isset( $headers['link'] ) + ? (array) $headers['link'] + : []; + + // Flatten all comma-separated links into one array + $all_links = []; + foreach ( $raw_links as $header ) { + // explode may yield spaces around each link, so trim() + $parts = array_map( 'trim', explode( ',', $header ) ); + $all_links = array_merge( $all_links, $parts ); + } + + // Find the first link with rel="https://api.w.org/" + $wp_json_link = null; + foreach ( $all_links as $link ) { + if ( false !== strpos( $link, 'rel="https://api.w.org/"' ) ) { + $wp_json_link = $link; + break; + } + } + + if ( $wp_json_link ) { + if ( preg_match( '/<([^>]+)>/', $wp_json_link, $m ) ) { + $wp_json_url = $m[1]; + } + } preg_match('/<([^>]+)>/', $wp_json_link[0], $matches ); - return $matches[1]; + return $wp_json_url; } /** @@ -1583,4 +1606,4 @@ public function format_time( $seconds ) { // Less than 1 hour return date_i18n( 'i:s', mktime( 0, 0, $seconds ) ); } -} \ No newline at end of file +}