Closed CharlyLeetham closed 6 years ago
@CharlyLeetham Did you want to open a pull request for this? Maybe call the boolean wpdiscord_posted
Also I think it would be fine to just add the condition to the existing if check.
<?php
// Only post to discord when a post switches from unpublished to published.
if ($old_status == 'publish' || $new_status != 'publish' || $alreadyposted) {
return true;
}`
Hi @rspraymond Sorry for the delay, busy few weeks. You're correct regarding the logic, I tested that to be sure. I think I've created the pull request correctly - first time doing this and all.
Please let me know if it's correct.
@CharlyLeetham Pull request merged. Thanks for your contribution!
I use Gravity Forms to allow people to edit certain posts from the frontend. That plugin will set an already published post to 'draft' and then republish it.
As wp-discord uses transition_post_status to determine if a post should be sent to discord is problematic.
To get around this, I've modified the post_published_event function in class-wp-discord-admin.php (Around line 209 at the time of writing) and replaced:
With:
After
$webhook->post_content($content);
Add:update_post_meta($post->ID, 'wpdiscord_alreadyposted', 'true');
These changes allow for custom meta to be set when the discord post is made and then for the post to be skipped if the function in use toggles the published setting.
I'm sure there's a better way of doing this, but that's what I came up with.