From 7b30d3dd341858d58cee130c0bf26ef87dcf7aec Mon Sep 17 00:00:00 2001 From: Dan Phiffer Date: Wed, 27 Nov 2024 10:00:09 -0500 Subject: [PATCH] improve special episodes --- wp-content/plugins/feed-import/post.php | 17 ++++++++++------- .../acf/group_67471a8d19703.json | 6 +++--- wp-content/themes/mediasanctuary/functions.php | 18 +++++++++--------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/wp-content/plugins/feed-import/post.php b/wp-content/plugins/feed-import/post.php index 13450bc5..9649724f 100644 --- a/wp-content/plugins/feed-import/post.php +++ b/wp-content/plugins/feed-import/post.php @@ -169,19 +169,22 @@ function date_gmt() { return $date->format('Y-m-d H:i:s'); } - function category() { - return apply_filters('feed_import_post_category', '', $this); + function categories() { + // Returns an array of category names. + return apply_filters('feed_import_post_categories', [], $this); } function post_category() { // The wp_insert_post and wp_update_post functions expect an array of - // term IDs, so we convert a more useful string to that format at the - // very last minute. - if (empty($this->category())) { + // term IDs, so we convert our category names to term IDs at the very + // last minute. + if (empty($this->categories())) { return []; } - $term = get_term_by('name', $this->category(), 'category'); - return [$term->term_id]; + return array_map(function($name) { + $term = get_term_by('name', $name, 'category'); + return $term->term_id; + }, $this->categories()); } function attach_image() { diff --git a/wp-content/themes/mediasanctuary/acf/group_67471a8d19703.json b/wp-content/themes/mediasanctuary/acf/group_67471a8d19703.json index a5aced64..885ab9ac 100644 --- a/wp-content/themes/mediasanctuary/acf/group_67471a8d19703.json +++ b/wp-content/themes/mediasanctuary/acf/group_67471a8d19703.json @@ -8,7 +8,7 @@ "name": "special_episode", "aria-label": "", "type": "true_false", - "instructions": "", + "instructions": "Make sure to add special episodes to the 'Stories' category.", "required": 0, "conditional_logic": 0, "wrapper": { @@ -16,7 +16,7 @@ "class": "", "id": "" }, - "message": "Special Episode (display with stories)", + "message": "This is a special episode", "default_value": 0, "allow_in_bindings": 0, "ui_on_text": "", @@ -29,7 +29,7 @@ "name": "special_episode_title", "aria-label": "", "type": "text", - "instructions": "", + "instructions": "Override the 'HMM_MM-DD-YYYY' title.", "required": 0, "conditional_logic": [ [ diff --git a/wp-content/themes/mediasanctuary/functions.php b/wp-content/themes/mediasanctuary/functions.php index 4ae2f939..115c9a27 100644 --- a/wp-content/themes/mediasanctuary/functions.php +++ b/wp-content/themes/mediasanctuary/functions.php @@ -320,10 +320,6 @@ function is_story_post($post) { return true; } } - $special_episode = get_field('special_episode', $post); - if (!empty($special_episode)) { - return true; - } return false; } @@ -435,19 +431,23 @@ function audio_player() { ]; }, 10, 2); -add_filter('feed_import_post_category', function($category, $post) { +add_filter('feed_import_post_categories', function($categories, $post) { if (preg_match('/^HMM/i', $post->data['title'])) { - return 'Hudson Mohawk Magazine Episodes'; + $categories = ['Hudson Mohawk Magazine Episodes']; + if (get_field('special_episode', $post->id)) { + $categories[] = 'Stories'; + } + return $categories; } - return 'Stories'; + return ['Stories']; }, 10, 2); function feed_import_post_date($date, $post) { - $category = $post->category(); + $categories = $post->categories(); $four_days = 60 * 60 * 24 * 4; $timezone = $date->getTimezone(); - if ($category == 'Stories' && + if (in_array('Stories', $categories) && current_time('u') - $date->getTimestamp() < $four_days) { // If the track's timestamp is within 4 days, we should schedule // it for the next weekday at 6pm.