diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 0d82d9fc..08304b31 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -238,7 +238,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook | `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`, `fictioneer_gate_unpublished_content`, `fictioneer_serve_sitemap`, `fictioneer_redirect_story` -| `transition_post_status` | `fictioneer_log_story_chapter_status_changes` +| `transition_post_status` | `fictioneer_log_story_chapter_status_changes`, `fictioneer_chapter_future_to_publish` | `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` diff --git a/includes/functions/_service-posts.php b/includes/functions/_service-posts.php index 17897f7a..b14988b1 100644 --- a/includes/functions/_service-posts.php +++ b/includes/functions/_service-posts.php @@ -352,6 +352,31 @@ function fictioneer_chapter_to_draft( $post ) { add_action( 'publish_to_draft', 'fictioneer_chapter_to_draft' ); add_action( 'private_to_draft', 'fictioneer_chapter_to_draft' ); +/** + * Perform updates when a chapter goes from future to publish + * + * @since 5.21.0 + * + * @param string $new_status New post status. + * @param string $old_status Old post status. + * @param WP_Post $post Post object. + */ + +function fictioneer_chapter_future_to_publish( $new_status, $old_status, $post ) { + // Validate transition... + if ( $post->post_type !== 'fcn_chapter' || $old_status !== 'future' || $new_status !== 'publish' ) { + return; + } + + // Update fictioneer_chapters_added field of story (if any) + $story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true ); + + if ( $story_id ) { + update_post_meta( $story_id, 'fictioneer_chapters_added', $post->post_date ); + } +} +add_action( 'transition_post_status', 'fictioneer_chapter_future_to_publish', 10, 3 ); + // ============================================================================= // POST PASSWORD EXPIRATION // =============================================================================