From 06e90a3654697c95b1ca40fc47e86e7b6e4af1af Mon Sep 17 00:00:00 2001 From: Dan Phiffer Date: Wed, 27 Nov 2024 07:50:13 -0500 Subject: [PATCH] improve webhook message --- wp-content/plugins/feed-import/post.php | 4 +++- wp-content/themes/mediasanctuary/functions.php | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/wp-content/plugins/feed-import/post.php b/wp-content/plugins/feed-import/post.php index 3a6d323c..13450bc5 100644 --- a/wp-content/plugins/feed-import/post.php +++ b/wp-content/plugins/feed-import/post.php @@ -21,6 +21,7 @@ function save() { 'post_content' => $this->content(), 'post_category' => $this->post_category(), ]); + $action = 'Updated'; } else { $this->id = wp_insert_post([ 'post_status' => $this->status(), @@ -30,10 +31,11 @@ function save() { 'post_date_gmt' => $this->date_gmt(), 'post_category' => $this->post_category(), ]); + $action = 'Created'; } $this->update_metadata(); $this->attach_image(); - do_action('feed_import_post_saved', $this); + do_action('feed_import_post_saved', $this, $action); } function has_updates() { diff --git a/wp-content/themes/mediasanctuary/functions.php b/wp-content/themes/mediasanctuary/functions.php index 505ffb83..deb9d92c 100644 --- a/wp-content/themes/mediasanctuary/functions.php +++ b/wp-content/themes/mediasanctuary/functions.php @@ -468,18 +468,19 @@ function feed_import_post_date($date, $post) { } }, 10, 2); -add_action('feed_import_post_saved', function($post) { +add_action('feed_import_post_saved', function($post, $action) { if (! defined('SLACK_WEBHOOK')) { return false; } $edit_url = home_url("/wp-admin/post.php?post=$post->id&action=edit"); + $view_url = get_permalink($post->id); $payload = [ 'type' => 'mrkdwn', - 'text' => "Imported <$edit_url|{$post->title()}> from <{$post->data['link']}|soundcloud.com>"; + 'text' => "$action <$view_url|{$post->title()}> from <{$post->data['link']}|soundcloud.com> (<$edit_url|edit>)" ]; $rsp = wp_remote_post(SLACK_WEBHOOK, [ 'body' => [ 'payload' => json_encode($payload) ] ]); -}); \ No newline at end of file +}, 10, 2); \ No newline at end of file