Fix missing story ID in discord chapter message

This commit is contained in:
Tetrakern 2024-09-10 11:52:18 +02:00
parent b5a31d7e0b
commit 3f65c2b883
2 changed files with 14 additions and 9 deletions

View File

@ -296,13 +296,13 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `publish_to_draft` | `fictioneer_chapter_to_draft`
| `rest_api_init` | `fictioneer_register_endpoint_get_story_comments`
| `restrict_manage_posts` | `fictioneer_add_chapter_story_filter_dropdown`
| `save_post` | `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_transients`, `fictioneer_save_story_metaboxes`, `fictioneer_save_chapter_metaboxes`, `fictioneer_save_advanced_metabox`, `fictioneer_save_support_links_metabox`, `fictioneer_save_collection_metaboxes`, `fictioneer_save_recommendation_metaboxes`, `fictioneer_save_post_metaboxes`, `fictioneer_delete_cached_story_card_after_update`, `fictioneer_rebuild_story_data_collection`
| `save_post` | `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_transients`, `fictioneer_save_story_metaboxes`, `fictioneer_save_chapter_metaboxes`, `fictioneer_save_advanced_metabox`, `fictioneer_save_support_links_metabox`, `fictioneer_save_collection_metaboxes`, `fictioneer_save_recommendation_metaboxes`, `fictioneer_save_post_metaboxes`, `fictioneer_delete_cached_story_card_after_update`, `fictioneer_rebuild_story_data_collection`, `fictioneer_post_chapter_to_discord`
| `send_headers` | `fictioneer_block_pages_from_indexing`
| `show_user_profile` | `fictioneer_custom_profile_fields`
| `shutdown` | `fictioneer_save_story_card_cache`, `fictioneer_save_query_result_cache_registry`
| `switch_theme` | `fictioneer_theme_deactivation`
| `template_redirect` | `fictioneer_disable_date_archives`, `fictioneer_generate_epub`, `fictioneer_handle_oauth`, `fictioneer_logout`, `fictioneer_disable_attachment_pages`, `fictioneer_gate_unpublished_content`, `fictioneer_serve_sitemap`, `fictioneer_redirect_story`
| `transition_post_status` | `fictioneer_log_story_chapter_status_changes`, `fictioneer_chapter_future_to_publish`, `fictioneer_post_story_to_discord`, `fictioneer_post_chapter_to_discord`
| `transition_post_status` | `fictioneer_log_story_chapter_status_changes`, `fictioneer_chapter_future_to_publish`, `fictioneer_post_story_to_discord`
| `trashed_post` | `fictioneer_refresh_post_caches`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_purge_transients`, `fictioneer_remove_chapter_from_story`
| `untrash_post` | `fictioneer_refresh_post_caches`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_purge_transients`
| `update_option_*` | `fictioneer_update_option_disable_extended_chapter_list_meta_queries`, `fictioneer_update_option_disable_extended_story_list_meta_queries`

View File

@ -266,15 +266,20 @@ if ( get_option( 'fictioneer_discord_channel_stories_webhook' ) ) {
*
* @since 5.6.0
* @since 5.21.2 - Refactored.
* @since 5.24.1 - Switch back to save_post hook to ensure the story ID is set.
*
* @param string $new_status New post status.
* @param string $new_status Old post status.
* @param WP_Post $post Post object.
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
function fictioneer_post_chapter_to_discord( $new_status, $old_status, $post ) {
// Only if chapter going from non-publish status to publish
if ( $post->post_type !== 'fcn_chapter' || $new_status !== 'publish' || $old_status === 'publish' ) {
function fictioneer_post_chapter_to_discord( $post_id, $post ) {
// Prevent multi-fire
if ( fictioneer_multi_save_guard( $post_id ) ) {
return;
}
// Only if published chapter
if ( $post->post_type !== 'fcn_chapter' || $post->post_status !== 'publish' ) {
return;
}
@ -351,7 +356,7 @@ function fictioneer_post_chapter_to_discord( $new_status, $old_status, $post ) {
}
if ( get_option( 'fictioneer_discord_channel_chapters_webhook' ) ) {
add_action( 'transition_post_status', 'fictioneer_post_chapter_to_discord', 99, 3 );
add_action( 'save_post', 'fictioneer_post_chapter_to_discord', 99, 2 );
}
// =============================================================================