Skip to content

Commit 2bae8c7

Browse files
swissspidyCopilot
andauthored
Update src/Media_Command.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7d89a2b commit 2bae8c7

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/Media_Command.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,14 +1841,31 @@ private function update_post_content_for_attachment( array $url_replacements ) {
18411841
}
18421842

18431843
$where_sql = implode( ' OR ', $where_clauses );
1844+
1845+
// First, find the IDs of posts whose content will be updated so we can clear their object cache entries.
18441846
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1847+
$post_ids = $wpdb->get_col(
1848+
$wpdb->prepare(
1849+
"SELECT ID FROM {$wpdb->posts} WHERE {$where_sql}",
1850+
...$where_args
1851+
)
1852+
);
1853+
18451854
$result = $wpdb->query(
1846-
$wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = {$replace_expr} WHERE {$where_sql}", ...array_merge( $replace_args, $where_args ) )
1855+
$wpdb->prepare(
1856+
"UPDATE {$wpdb->posts} SET post_content = {$replace_expr} WHERE {$where_sql}",
1857+
...array_merge( $replace_args, $where_args )
1858+
)
18471859
);
18481860
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
18491861
if ( false === $result ) {
18501862
WP_CLI::warning( 'Failed to update post content references for attachment.' );
18511863
} else {
1864+
if ( ! empty( $post_ids ) ) {
1865+
foreach ( $post_ids as $post_id ) {
1866+
clean_post_cache( (int) $post_id );
1867+
}
1868+
}
18521869
wp_cache_set( 'last_changed', microtime(), 'posts' );
18531870
}
18541871
}

0 commit comments

Comments
 (0)