Skip to content

Commit f78534d

Browse files
committed
Fix PHPStan findings, avoid the deprecated wp_clear_object_cache()
Guard against WP_Query::$posts being null, and free the in-process object cache directly instead of through the deprecated helper, whose deprecation is reported differently depending on the PHPStan setup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D26yjkN2BiqCXT6p6o1WqS
1 parent 5161ba1 commit f78534d

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎src/Post_Command.php‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ private function query_posts_in_chunks( $query_args, $need_url ) {
10971097
$query = new WP_Query( $chunk_args );
10981098

10991099
$posts = [];
1100-
foreach ( $query->posts as $post ) {
1100+
foreach ( $query->posts ?? [] as $post ) {
11011101
if ( $post instanceof \WP_Post ) {
11021102
$posts[ $post->ID ] = $post;
11031103
}
@@ -1117,7 +1117,20 @@ private function query_posts_in_chunks( $query_args, $need_url ) {
11171117
}
11181118

11191119
unset( $posts, $query );
1120-
Utils\wp_clear_object_cache(); // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.wp_clear_object_cacheDeprecatedRemoved @phpstan-ignore-line
1120+
self::clear_runtime_object_cache();
1121+
}
1122+
}
1123+
1124+
/**
1125+
* Free the memory held by the in-process object cache.
1126+
*
1127+
* Persistent object caches are left alone unless they can flush their in-process part only.
1128+
*/
1129+
private static function clear_runtime_object_cache() {
1130+
if ( function_exists( 'wp_cache_flush_runtime' ) && function_exists( 'wp_cache_supports' ) && wp_cache_supports( 'flush_runtime' ) ) {
1131+
wp_cache_flush_runtime();
1132+
} elseif ( ! wp_using_ext_object_cache() ) {
1133+
wp_cache_flush();
11211134
}
11221135
}
11231136

0 commit comments

Comments
 (0)