Skip to content

Commit

Permalink
improve webhook message
Browse files Browse the repository at this point in the history
  • Loading branch information
dphiffer committed Nov 27, 2024
1 parent 63a1731 commit 06e90a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion wp-content/plugins/feed-import/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions wp-content/themes/mediasanctuary/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
]);
});
}, 10, 2);

0 comments on commit 06e90a3

Please sign in to comment.