From 090fb72df03b8154ff0cb3fe430d0fd3f38c14b2 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 13 Aug 2025 16:28:31 +0000 Subject: [PATCH] Export: Split the query for post authors in `wxr_authors_list()` into smaller chunks. This aims to avoid a fatal error when attempting to export content on larger WP instances with a lot of data. Follow-up to [15961], [28731]. Props bor0, SirLouen, SergeyBiryukov. Fixes #63503. Built from https://develop.svn.wordpress.org/trunk@60632 git-svn-id: http://core.svn.wordpress.org/trunk@59968 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/export.php | 19 +++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php index 566c9d802b..9d5903a98c 100644 --- a/wp-admin/includes/export.php +++ b/wp-admin/includes/export.php @@ -405,19 +405,26 @@ function export_wp( $args = array() ) { global $wpdb; if ( ! empty( $post_ids ) ) { - $post_ids = array_map( 'absint', $post_ids ); - $and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')'; + $post_ids = array_map( 'absint', $post_ids ); + $post_id_chunks = array_chunk( $post_ids, 20 ); } else { - $and = ''; + $post_id_chunks = array( array() ); } $authors = array(); - $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" ); - foreach ( (array) $results as $result ) { - $authors[] = get_userdata( $result->post_author ); + + foreach ( $post_id_chunks as $next_posts ) { + $and = ! empty( $next_posts ) ? 'AND ID IN (' . implode( ', ', $next_posts ) . ')' : ''; + + $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" ); + + foreach ( (array) $results as $result ) { + $authors[] = get_userdata( $result->post_author ); + } } $authors = array_filter( $authors ); + $authors = array_unique( $authors, SORT_REGULAR ); // Remove duplicate authors. foreach ( $authors as $author ) { echo "\t"; diff --git a/wp-includes/version.php b/wp-includes/version.php index 2da1dbadd0..6f1582113c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.9-alpha-60631'; +$wp_version = '6.9-alpha-60632'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.