• Resolved Mikko Saari

    (@msaari)


    Our site has a publishing process where posts go through a publishing queue. Something in the process turns off the “Send to Telegram” setting. Here’s how the process works:

    1. Post is written and saved as pending to wait for approval.
    2. Editor checks the post and saves it as spq_queued, a custom status.
    3. Our scheduler picks up the post from the queue, changes the post status to future and sets the post_date.

    Step 3 seems to turn off the “Send to Telegram” setting. Here’s what it does:

    $updated_post = array(
    	'ID'            => $post_id,
    	'post_status'   => 'future',
    	'post_date'     => date( 'Y-m-d h:i:s', $timestamp ),
    	'post_date_gmt' => date( 'Y-m-d h:i:s', $timestamp - $gmt_offset ),
    	'edit_date'     => true,
    );
    
    return wp_update_post( $updated_post );

    Why does this turn off the setting? I suppose I can run the wp_update_posts() and, after that, set the send2tg custom field back to yes, but I’d also like to understand why this disables the setting. It shouldn’t, so maybe there’s a bug in the plugin?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Irshad Ahmad

    (@irshadahmad21)

    Such a post is considered an existing post by the plugin, and thus the rule “Send when” set in Post to Telegram settings comes into play to check whether “An existing post is updated” option is enabled or not.

    It’s not a bug, but it definitely needs some improvement. Thank you for reporting that.

    Plugin Author Irshad Ahmad

    (@irshadahmad21)

    You can check the logic here
    https://github.com/wpsocio/wptelegram/blob/191ff89e7aa62ee09fdd2db2636769b88de27d03/src/modules/p2tg/Admin.php#L583-L614

    You can also use the wptelegram_p2tg_send2tg_default filter given in that code to control the behavior explicitly.

    Thread Starter Mikko Saari

    (@msaari)

    Could you pass the post object as a parameter to the wptelegram_p2tg_send2tg_default filter? I can’t use the “An existing post is updated” option, as I don’t want the sending to trigger every time, so a filter function might help. I know I can use the same method as you do to get the post object, but since you already have it, why not pass it to the filter?

    Plugin Author Irshad Ahmad

    (@irshadahmad21)

    Post object is not necessarily to be always available. You need to get it from post ID via $_GET['post'].

    Thread Starter Mikko Saari

    (@msaari)

    Ah, yes, it’s fetched inside the if condition. Anyway, it would be nice if the post ID would be passed as a parameter to the filter, to avoid the need to access the query variables; that feels a bit clumsy and adds a complication the user needs to know. Having the filter hook include the post ID as a parameter would make things smoother for the user of the hook.

    Plugin Author Irshad Ahmad

    (@irshadahmad21)

    We can definitely do that and add it as the third parameter to the filter callback. You will see it in the next update.

    Thread Starter Mikko Saari

    (@msaari)

    It’s still not working. The wptelegram_p2tg_send2tg_default hook works for setting the default value, but the posts won’t get sent to Telegram when the scheduled post is published.

    Do you have any suggestions on how I could get this to work? I can’t enable the “An existing post is updated” sending because I edit many old posts, and I don’t want those posts to be sent to Telegram.

    Also, I think having a scheduled post be published for the first time should count as “A new post is published” case – it’s a new post published for the first time. Is it possible there’s a bug in the plugin? I noticed you have a function future_to_publish() for sending out scheduled posts when they are published, but the function is never called anywhere in your plugin.

    Plugin Author Irshad Ahmad

    (@irshadahmad21)

    Yes, wptelegram_p2tg_send2tg_default will only
    affect the Send to Telegram option for post edit page.

    Logs will tell the actual reason for posts not being sent. I would suggest to enable logs in Advanced Settings and try again. Then send View log links to our support on Telegram – @WPTelegramSupport.

    Thread Starter Mikko Saari

    (@msaari)

    Thanks, I’ll do that and will get back to you when I have data.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Send to Telegram gets disabled by status changes’ is closed to new replies.