Improve fictioneer_multi_save_guard

Should now only fire the first trigger with the correct parameters (updated, etc.) depending on whether the block editor is used or not.
This commit is contained in:
Tetrakern 2023-08-17 10:39:00 +02:00
parent 0e3a3bc20c
commit 96c69d1f7c
2 changed files with 14 additions and 4 deletions

View File

@ -235,7 +235,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `manage_comments_custom_column` | `fictioneer_add_comments_report_column_content`
| `personal_options_update` | `fictioneer_update_admin_user_profile`, `fictioneer_update_my_user_profile`
| `pre_get_posts` | `fictioneer_extend_search_query`, `fictioneer_remove_unlisted_from_search`, `fictioneer_read_others_files`, `fictioneer_read_others_files_list_view`
| `save_post` | `fictioneer_create_sitemap`, `fictioneer_refresh_chapters_schema`, `fictioneer_refresh_chapter_schema`, `fictioneer_refresh_collections_schema`, `fictioneer_refresh_post_caches`, `fictioneer_refresh_post_schema`, `fictioneer_refresh_recommendations_schema`, `fictioneer_refresh_recommendation_schema`, `fictioneer_refresh_stories_schema`, `fictioneer_refresh_story_schema`, `fictioneer_save_seo_metabox`, `fictioneer_save_word_count`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_update_shortcode_relationships`, `fictioneer_purge_cache_transients`, `fictioneer_restrict_page_templates`, `fictioneer_flush_object_cache`, `fictioneer_acf_append_chapter_to_story`, `fictioneer_post_story_to_discord`, `fictioneer_post_chapter_to_discord`
| `save_post` | `fictioneer_create_sitemap`, `fictioneer_refresh_chapters_schema`, `fictioneer_refresh_chapter_schema`, `fictioneer_refresh_collections_schema`, `fictioneer_refresh_post_caches`, `fictioneer_refresh_post_schema`, `fictioneer_refresh_recommendations_schema`, `fictioneer_refresh_recommendation_schema`, `fictioneer_refresh_stories_schema`, `fictioneer_refresh_story_schema`, `fictioneer_save_seo_metabox`, `fictioneer_save_word_count`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_update_shortcode_relationships`, `fictioneer_purge_cache_transients`, `fictioneer_restrict_page_templates`, `fictioneer_flush_object_cache`, `fictioneer_append_chapter_to_story`, `fictioneer_post_story_to_discord`, `fictioneer_post_chapter_to_discord`
| `show_user_profile` | `fictioneer_custom_profile_fields`
| `switch_theme` | `fictioneer_theme_deactivation`
| `template_redirect` | `fictioneer_disable_date_archives`, `fictioneer_generate_epub`, `fictioneer_handle_oauth`, `fictioneer_logout`, `fictioneer_disable_attachment_pages`

View File

@ -1611,6 +1611,7 @@ if ( ! function_exists( 'fictioneer_multi_save_guard' ) ) {
* Prevents multi-fire in update hooks
*
* @since 5.5.2
* @since 5.6.0 Account for REST requests first.
*
* @param int $post_id The ID of the updated post.
*
@ -1618,9 +1619,18 @@ if ( ! function_exists( 'fictioneer_multi_save_guard' ) ) {
*/
function fictioneer_multi_save_guard( $post_id ) {
// Automatic save?
// Block if...
if ( use_block_editor_for_post_type( get_post_type( $post_id ) ) ) {
if ( ! ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
return true;
}
} else {
if ( ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
return true;
}
}
if (
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
wp_is_post_autosave( $post_id ) ||
wp_is_post_revision( $post_id ) ||
in_array( get_post_status( $post_id ), ['auto-draft'] )
@ -1628,7 +1638,7 @@ if ( ! function_exists( 'fictioneer_multi_save_guard' ) ) {
return true;
}
// Allowed save
// Pass
return false;
}
}