Add filters to Discord channel webhooks

This commit is contained in:
Tetrakern 2024-06-10 17:09:59 +02:00
parent dca254f75f
commit 60279af03a
2 changed files with 51 additions and 6 deletions

View File

@ -517,6 +517,33 @@ Filters the story message array passed to `fictioneer_discord_send_message()` in
---
### `apply_filters( 'fictioneer_filter_discord_chapter_webhook', $post, $story_id )`
Filters the webhook used for the Discord notification about a new chapters.
**Parameters:**
* $post (WP_Post) - The chapter post.
* $story_id (int|null) - The ID of the story post (if any). Unsafe.
---
### `apply_filters( 'fictioneer_filter_discord_comment_webhook', $comment, $post, $user )`
Filters the webhook used for the Discord notification about a new comment.
**Parameters:**
* $comment (WP_Comment) - The comment in question.
* $post (WP_Post) - The post the comment is for.
* $user (WP_User|null) - The user who wrote comment (if registered). Unsafe.
---
### `apply_filters( 'fictioneer_filter_discord_story_webhook', $post )`
Filters the webhook used for the Discord notification about a new stories.
**Parameters:**
* $post (WP_Post) - The story post.
---
### `apply_filters( 'fictioneer_filter_falsy_meta_allow_list', $allowed )`
Filters the array of meta keys allowed to be saved as "falsy" ("", 0, null, false, []) instead of being deleted when updated via theme functions. Applies to post, comment, and user meta fields. This does not affect the core update functions. See `fictioneer_update_user_meta(…)`, `fictioneer_update_comment_meta(…)`, and `fictioneer_update_post_meta(…)`.

View File

@ -161,12 +161,19 @@ function fictioneer_post_comment_to_discord( $comment_id, $comment_approved ) {
// Filter
$message = apply_filters( 'fictioneer_filter_discord_comment_message', $message, $comment, $post, $user );
$webhook = apply_filters(
'fictioneer_filter_discord_comment_webhook',
get_option( 'fictioneer_discord_channel_comments_webhook' ),
$comment,
$post,
$user
);
// Send to Discord
fictioneer_discord_send_message( get_option( 'fictioneer_discord_channel_comments_webhook' ), $message );
fictioneer_discord_send_message( $webhook, $message );
}
if ( ! empty( get_option( 'fictioneer_discord_channel_comments_webhook' ) ) ) {
if ( get_option( 'fictioneer_discord_channel_comments_webhook' ) ) {
add_action( 'comment_post', 'fictioneer_post_comment_to_discord', 99, 2 );
}
@ -249,15 +256,20 @@ function fictioneer_post_story_to_discord( $post_id ) {
// Filter
$message = apply_filters( 'fictioneer_filter_discord_story_message', $message, $post );
$webhook = apply_filters(
'fictioneer_filter_discord_story_webhook',
get_option( 'fictioneer_discord_channel_stories_webhook' ),
$post
);
// Send to Discord
fictioneer_discord_send_message( get_option( 'fictioneer_discord_channel_stories_webhook' ), $message );
fictioneer_discord_send_message( $webhook, $message );
// Set trigger true
update_post_meta( $post->ID, 'fictioneer_discord_post_trigger', true );
}
if ( ! empty( get_option( 'fictioneer_discord_channel_stories_webhook' ) ) ) {
if ( get_option( 'fictioneer_discord_channel_stories_webhook' ) ) {
add_action( 'save_post', 'fictioneer_post_story_to_discord', 99 );
}
@ -356,15 +368,21 @@ function fictioneer_post_chapter_to_discord( $post_id ) {
// Filter
$message = apply_filters( 'fictioneer_filter_discord_chapter_message', $message, $post, $story_id );
$webhook = apply_filters(
'fictioneer_filter_discord_chapter_webhook',
get_option( 'fictioneer_discord_channel_chapters_webhook' ),
$post,
$story_id
);
// Send to Discord
fictioneer_discord_send_message( get_option( 'fictioneer_discord_channel_chapters_webhook' ), $message );
fictioneer_discord_send_message( $webhook, $message );
// Set trigger true
update_post_meta( $post->ID, 'fictioneer_discord_post_trigger', true );
}
if ( ! empty( get_option( 'fictioneer_discord_channel_chapters_webhook' ) ) ) {
if ( get_option( 'fictioneer_discord_channel_chapters_webhook' ) ) {
add_action( 'save_post', 'fictioneer_post_chapter_to_discord', 99 );
}