Skip to content

Commit

Permalink
Add status caching to two core hacks filters
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgeatches committed Oct 14, 2024
1 parent 703072e commit 0ee148e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions modules/shared/php/core-hacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ public static function fix_preview_link_part_one( string $preview_link ): string

$post = get_post( get_the_ID() );

// Only modify if we're using a pre-publish status on a supported custom post type
$status_slugs = wp_list_pluck( CustomStatus::get_custom_statuses(), 'slug' );
// Optimization: preview_post_link is called for each visible post on the Posts -> All Posts page.
// Temporarily cache slugs to avoid calling get_custom_statuses() for each post.
static $status_slugs = false;
if ( false === $status_slugs ) {
$status_slugs = wp_list_pluck( CustomStatus::get_custom_statuses(), 'slug' );
}

if ( ! $post
|| ! is_admin()
|| 'post.php' != $pagenow
Expand Down Expand Up @@ -360,8 +365,14 @@ private static function get_preview_link( WP_Post $post ): string {
public static function fix_post_row_actions( array $actions, WP_Post $post ): array {
global $pagenow;

// Optimization: fix_post_row_actions is called for each visible post on the Posts -> All Posts page.
// Temporarily cache slugs to avoid calling get_custom_statuses() for each post.
static $status_slugs = false;
if ( false === $status_slugs ) {
$status_slugs = wp_list_pluck( CustomStatus::get_custom_statuses(), 'slug' );
}

// Only modify if we're using a pre-publish status on a supported custom post type
$status_slugs = wp_list_pluck( CustomStatus::get_custom_statuses(), 'slug' );
if ( 'edit.php' != $pagenow
|| ! in_array( $post->post_status, $status_slugs )
|| ! in_array( $post->post_type, HelperUtilities::get_supported_post_types() ) ) {
Expand Down

0 comments on commit 0ee148e

Please sign in to comment.