Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

author-categories-cache #1935

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/core/Classes/Post_Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,20 @@ public static function flush_cache($post_id)
{
if (empty($post_id)) {
wp_cache_flush_group('get_post_authors');
wp_cache_flush_group('author_categories_relation_cache');

return;
}

// author categories relation for the post
$args = [
'post_id' => $post_id,
'author_term_id' => ''
];
$cache_key = 'author_categories_relation_' . md5(serialize($args));
wp_cache_delete($cache_key, 'author_categories_relation_cache');

// post authors
wp_cache_delete($post_id, 'get_post_authors:authors');
}
}
1 change: 1 addition & 0 deletions src/core/Classes/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public static function updatePostAuthorCategory($post_id, $authors, $post_author
}
}
}
do_action('publishpress_authors_flush_cache', $post_id);
}

public static function detect_author_slug_mismatch()
Expand Down
11 changes: 11 additions & 0 deletions src/modules/author-categories/author-categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function init()
add_action('wp_ajax_reorder_ppma_author_category', [$this, 'handleReOrderCategory']);
add_filter('removable_query_args', [$this, 'removableQueryArgs']);
add_action('delete_post', [$this, 'deleteAuthorCategoryRelation']);
add_action('publishpress_author_categories_flush_cache', [$this, 'flush_cache'], 15);
}

/**
Expand Down Expand Up @@ -173,6 +174,13 @@ public function removableQueryArgs($args) {

}

/**
* Flush author category cache
*/
public function flush_cache($category_id) {
wp_cache_flush_group('author_categories_results_cache');
}

/**
* Add the admin submenu.
*/
Expand Down Expand Up @@ -432,6 +440,7 @@ private function addAuthorCategory($insert_args) {
foreach ($meta_data as $meta_data_key => $meta_data_value) {
self::updateAuthorCategoryMeta($category_id, $meta_data_key, $meta_data_value);
}
do_action('publishpress_author_categories_flush_cache', $category_id);
return get_ppma_author_categories(['id' => $category_id]);
} else {
return false;
Expand Down Expand Up @@ -473,6 +482,8 @@ private function editAuthorCategory($edit_args, $id) {
self::updateAuthorCategoryMeta($id, $meta_data_key, $meta_data_value);
}

do_action('publishpress_author_categories_flush_cache', $id);

return get_ppma_author_categories(['id' => $id]);
}

Expand Down
Loading