@@ -191,15 +191,29 @@ function fictioneer_post_comment_to_discord( $comment_id, $comment_approved ) {
191
191
*
192
192
* @since 5.6.0
193
193
* @since 5.21.2 - Refactored.
194
+ * @since 5.27.2 - Switch back to save_post hook to ensure the thumbnail is saved.
194
195
*
195
- * @param string $new_status New post status .
196
- * @param string $new_status Old post status .
197
- * @param WP_Post $post Post object .
196
+ * @param int $post_id Post ID .
197
+ * @param WP_Post $post Post object .
198
+ * @param bool $update Whether this is an existing post being updated. Unreliable .
198
199
*/
199
200
200
- function fictioneer_post_story_to_discord ( $ new_status , $ old_status , $ post ) {
201
- // Only if story going from non-publish status to publish
202
- if ( $ post ->post_type !== 'fcn_story ' || $ new_status !== 'publish ' || $ old_status === 'publish ' ) {
201
+ function fictioneer_post_story_to_discord ( $ post_id , $ post , $ update ) {
202
+ // Prevent multi-fire
203
+ if ( fictioneer_multi_save_guard ( $ post_id ) ) {
204
+ return ;
205
+ }
206
+
207
+ // Only if published chapter
208
+ if ( $ post ->post_type !== 'fcn_story ' || $ post ->post_status !== 'publish ' ) {
209
+ return ;
210
+ }
211
+
212
+ // Only if published less than 10 minutes ago
213
+ $ post_timestamp = get_post_time ( 'U ' , true , $ post_id );
214
+ $ current_timestamp = current_time ( 'U ' , true );
215
+
216
+ if ( $ update && ( $ current_timestamp - $ post_timestamp ) >= 600 ) {
203
217
return ;
204
218
}
205
219
@@ -210,14 +224,13 @@ function fictioneer_post_story_to_discord( $new_status, $old_status, $post ) {
210
224
211
225
// Data
212
226
$ title = html_entity_decode ( get_the_title ( $ post ) );
213
- $ url = get_permalink ( $ post ->ID );
214
227
215
228
// Message
216
229
$ message = array (
217
230
'content ' => sprintf (
218
231
_x ( "New story published: [%s](%s)! \n_ _ " , 'Discord message for new story. ' , 'fictioneer ' ),
219
232
$ title ,
220
- $ url
233
+ get_permalink ( $ post_id )
221
234
),
222
235
'embeds ' => array (
223
236
array (
@@ -258,11 +271,11 @@ function fictioneer_post_story_to_discord( $new_status, $old_status, $post ) {
258
271
update_post_meta ( $ post ->ID , 'fictioneer_discord_post_trigger ' , true );
259
272
260
273
// Unhook if done to avoid additional triggers (if any)
261
- remove_action ( 'transition_post_status ' , 'fictioneer_post_story_to_discord ' , 99 );
274
+ remove_action ( 'save_post ' , 'fictioneer_post_story_to_discord ' , 99 );
262
275
}
263
276
264
277
if ( get_option ( 'fictioneer_discord_channel_stories_webhook ' ) ) {
265
- add_action ( 'transition_post_status ' , 'fictioneer_post_story_to_discord ' , 99 , 3 );
278
+ add_action ( 'save_post ' , 'fictioneer_post_story_to_discord ' , 99 , 3 );
266
279
}
267
280
268
281
// =============================================================================
@@ -278,7 +291,7 @@ function fictioneer_post_story_to_discord( $new_status, $old_status, $post ) {
278
291
*
279
292
* @param int $post_id Post ID.
280
293
* @param WP_Post $post Post object.
281
- * @param bool $update Whether this is an existing post being updated.
294
+ * @param bool $update Whether this is an existing post being updated. Unreliable.
282
295
*/
283
296
284
297
function fictioneer_post_chapter_to_discord ( $ post_id , $ post , $ update ) {
0 commit comments