diff --git a/wp-content/plugins/feed-import/plugin.php b/wp-content/plugins/feed-import/plugin.php index ff5c6c8a..c195e886 100644 --- a/wp-content/plugins/feed-import/plugin.php +++ b/wp-content/plugins/feed-import/plugin.php @@ -13,15 +13,21 @@ function __construct($feeds = []) { } } - function import() { + function import($args) { foreach ($this->feeds as $url) { $feed = new Feed($url); $feed_data = $feed->import(); foreach ($feed_data as $post_data) { $post = new Post($post_data); - if ($post->has_updates()) { - echo $post->title() . "\n"; + if (!empty($args)) { + if ($post->has_id($args[0])) { + $post->save(); + echo $post->title() . "\n"; + break; + } + } else if ($post->has_updates()) { $post->save(); + echo $post->title() . "\n"; } } } diff --git a/wp-content/plugins/feed-import/post.php b/wp-content/plugins/feed-import/post.php index faac03f1..2e468842 100644 --- a/wp-content/plugins/feed-import/post.php +++ b/wp-content/plugins/feed-import/post.php @@ -19,7 +19,7 @@ function save() { 'ID' => $this->id, 'post_title' => $this->title(), 'post_content' => $this->content(), - 'post_category' => $this->category(), + 'post_category' => $this->post_category(), ]); } else { $this->id = wp_insert_post([ @@ -28,7 +28,7 @@ function save() { 'post_content' => $this->content(), 'post_date' => $this->date(), 'post_date_gmt' => $this->date_gmt(), - 'post_category' => $this->category(), + 'post_category' => $this->post_category(), ]); } $this->update_metadata(); @@ -44,6 +44,14 @@ function has_updates() { return ($this->get_content_hash() != $db_hash); } + function has_id($id) { + $existing = $this->get_existing(); + if (empty($existing)) { + return false; + } + return $existing->ID == $id; + } + function update_metadata() { set_post_format($this->id, 'audio'); update_post_meta($this->id, 'feed_import_guid', $this->data['guid']); @@ -84,18 +92,18 @@ function get_existing() { } function status() { - return apply_filters('feed_import_post_status', 'publish'); + return apply_filters('feed_import_post_status', 'publish', $this); } function title() { - return apply_filters('feed_import_post_title', $this->data['title']); + return apply_filters('feed_import_post_title', $this->data['title'], $this); } function content() { $content = $this->data['description']; $content = $this->autolink_urls($content); $content = $this->format_paragraphs($content); - $content = apply_filters('feed_import_post_content', $content); + $content = apply_filters('feed_import_post_content', $content, $this); return $content; } @@ -148,18 +156,29 @@ function format_paragraphs($content) { function date() { $date = new \DateTime($this->data['pubDate'], wp_timezone()); - $date = apply_filters('feed_import_post_date', $date); + $date = apply_filters('feed_import_post_date', $date, $this); return $date->format('Y-m-d H:i:s'); } function date_gmt() { $date = new \DateTime($this->data['pubDate']); - $date = apply_filters('feed_import_post_date_gmt', $date); + $date = apply_filters('feed_import_post_date_gmt', $date, $this); return $date->format('Y-m-d H:i:s'); } function category() { - return apply_filters('feed_import_post_category', ''); + return apply_filters('feed_import_post_category', '', $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())) { + return []; + } + $term = get_term_by('name', $this->category(), 'category'); + return [$term->term_id]; } function attach_image() { diff --git a/wp-content/themes/mediasanctuary/functions.php b/wp-content/themes/mediasanctuary/functions.php index a765b586..80111849 100644 --- a/wp-content/themes/mediasanctuary/functions.php +++ b/wp-content/themes/mediasanctuary/functions.php @@ -273,9 +273,9 @@ function social_meta_tags() { echo "\n"; - echo '