From 899f730eace13ef7334da90ec327a5a43c0af6bd Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:17:29 +0200 Subject: [PATCH] Made fictioneer_cleanup_discord_meta() generic --- DEVELOPMENT.md | 2 +- includes/functions/_utility.php | 10 -------- includes/functions/hooks/_chapter_hooks.php | 28 --------------------- includes/functions/hooks/_general_hooks.php | 27 ++++++++++++++++++++ 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 7b372411..ad4535f0 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -315,7 +315,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook | `wp_default_scripts` | `fictioneer_remove_jquery_migrate` | `wp_enqueue_scripts` | `fictioneer_add_custom_scripts`, `fictioneer_customizer_queue`, `fictioneer_style_queue` | `wp_footer` | `fictioneer_render_taxonomy_submenu` -| `wp_head` | `fictioneer_output_head_seo`, `fictioneer_output_rss`, `fictioneer_output_schemas`, `fictioneer_add_fiction_css`, `fictioneer_output_head_fonts`, `fictioneer_output_head_translations`, `fictioneer_remove_mu_registration_styles`, `fictioneer_output_mu_registration_style`, `fictioneer_output_head_meta`, `fictioneer_output_head_critical_scripts`. `fictioneer_output_head_anti_flicker` +| `wp_head` | `fictioneer_output_head_seo`, `fictioneer_output_rss`, `fictioneer_output_schemas`, `fictioneer_add_fiction_css`, `fictioneer_output_head_fonts`, `fictioneer_output_head_translations`, `fictioneer_remove_mu_registration_styles`, `fictioneer_output_mu_registration_style`, `fictioneer_output_head_meta`, `fictioneer_output_head_critical_scripts`. `fictioneer_output_head_anti_flicker`, `fictioneer_cleanup_discord_meta` | `wp_insert_comment` | `fictioneer_delete_cached_story_card_by_comment`, `fictioneer_increment_story_comment_count` | `wp_update_nav_menu` | `fictioneer_purge_nav_menu_transients` diff --git a/includes/functions/_utility.php b/includes/functions/_utility.php index 6696614c..95e3d87c 100644 --- a/includes/functions/_utility.php +++ b/includes/functions/_utility.php @@ -393,16 +393,6 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) { $comment_count = 0; $visible_chapter_ids = []; $indexed_chapter_ids = []; - $post_timestamp = get_post_time( 'U', true, $story_id ); - $current_timestamp = current_time( 'U', true ); - - // Remove Discord trigger meta field if outdated - if ( - get_post_meta( $story_id, 'fictioneer_discord_post_trigger' ) && - ( $current_timestamp - $post_timestamp ) > DAY_IN_SECONDS - ) { - delete_post_meta( $story_id, 'fictioneer_discord_post_trigger' ); - } // Assign correct icon if ( $status != 'Ongoing' ) { diff --git a/includes/functions/hooks/_chapter_hooks.php b/includes/functions/hooks/_chapter_hooks.php index 8c28082e..e07e8b12 100644 --- a/includes/functions/hooks/_chapter_hooks.php +++ b/includes/functions/hooks/_chapter_hooks.php @@ -763,31 +763,3 @@ function fictioneer_chapter_suggestion_tools() { if ( get_option( 'fictioneer_enable_suggestions' ) ) { add_action( 'fictioneer_chapter_after_main', 'fictioneer_chapter_suggestion_tools', 10 ); } - -// ============================================================================= -// CHAPTER DISCORD META FIELD CLEANUP -// ============================================================================= - -/** - * Removes Discord trigger meta field if outdated - * - * @since 5.24.1 - * - * @param array $args Chapter arguments passed to the hook. - */ - -function fictioneer_cleanup_discord_meta( $args ) { - $chapter_id = $args['chapter_id'] ?? 0; - - if ( ! get_post_meta( $chapter_id, 'fictioneer_discord_post_trigger' ) ) { - return; - } - - $post_timestamp = get_post_time( 'U', true, $chapter_id ); - $current_timestamp = current_time( 'U', true ); - - if ( $current_timestamp - $post_timestamp > DAY_IN_SECONDS ) { - delete_post_meta( $chapter_id, 'fictioneer_discord_post_trigger' ); - } -} -add_action( 'fictioneer_chapter_before_header', 'fictioneer_cleanup_discord_meta' ); diff --git a/includes/functions/hooks/_general_hooks.php b/includes/functions/hooks/_general_hooks.php index e62af792..f0ab756c 100644 --- a/includes/functions/hooks/_general_hooks.php +++ b/includes/functions/hooks/_general_hooks.php @@ -1154,3 +1154,30 @@ function fictioneer_render_character_submenu() { function fictioneer_render_warning_submenu() { fictioneer_render_taxonomy_submenu( 'fcn_content_warning' ); } + +// ============================================================================= +// DISCORD META FIELD CLEANUP +// ============================================================================= + +/** + * Removes Discord trigger meta field if outdated + * + * @since 5.24.1 + * @global WP_Post $post + */ + +function fictioneer_cleanup_discord_meta() { + global $post; + + if ( ! is_singular() || ! $post || ! get_post_meta( $post->ID, 'fictioneer_discord_post_trigger' ) ) { + return; + } + + $post_timestamp = get_post_time( 'U', true, $post->ID ); + $current_timestamp = current_time( 'U', true ); + + if ( $current_timestamp - $post_timestamp > DAY_IN_SECONDS ) { + delete_post_meta( $post->ID, 'fictioneer_discord_post_trigger' ); + } +} +add_action( 'wp_head', 'fictioneer_cleanup_discord_meta' );