WordPress.org

Ready to get started?Download WordPress

Forums

Edit Flow Plugin - Automatically send email notifications based on post status c (14 posts)

  1. schtifin
    Member
    Posted 2 years ago #

    Hello,

    I am testing the Edit Flow plugin 9really like it –thanks!) and I came across the option to auto subscribe user group for notifications upon post status change using the code here:

    http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/

    Is it possible to add multiple if statements? For example, I want to say something like this:

    If status is changed to “draft” send notification to usergroup with ID 1.
    If status is changed to “review” send notification to usergroup with ID 2.

    Thanks.

  2. Daniel Bachhuber
    Hand Built
    Posted 2 years ago #

    Yep! Totally doable, and glad you figured it out :) I've updated the documentation.

  3. schtifin
    Member
    Posted 2 years ago #

    Status change notifications are working great, but I ran into an issue and wanted to get some insight from the experts.

    I'm using wp_insert_post to automatically create new posts from a web form. I have configured it so that a specific custom status is assigned to these new posts. However, no notification is sent when the new post is created, I assume because the status technically has not been changed - it's just getting a default status from wp_insert_post.

    Is there a function or setting that enables sending a notification when a new post is created, perhaps with a specific custom status?

  4. Daniel Bachhuber
    Hand Built
    Posted 2 years ago #

    wp_transition_post_status() runs in wp_insert_post(), so I'm not entirely sure why it's not working.

    You might also try hooking into the 'wp_insert_post' action.

    Have you tried debugging at all?

  5. schtifin
    Member
    Posted 2 years ago #

    Yes on debugging. Everything appears to be working as expected.

    I've tried a number of things and can't seem to get this to work. I can only assume that when a new post is created using the web form, the status never changes from "draft" to the post status I am passing in wp_insert_post(). If I create a post manually and save it, I get the notification.

    Any ideas on how I can force the notification or setup some kind of condition that would be met when using wp_insert_post()?

    Thanks.

  6. Daniel Bachhuber
    Hand Built
    Posted 2 years ago #

    I've tried a number of things and can't seem to get this to work. I can only assume that when a new post is created using the web form, the status never changes from "draft" to the post status I am passing in wp_insert_post(). If I create a post manually and save it, I get the notification.

    Sorry, I missed this part. It's likely that the post_status field is empty when you first create the post, so you might want to var_dump() the post status value in your transition filter to double check. If that's the case, you might need to update your code snippet accordingly.

  7. schtifin
    Member
    Posted 2 years ago #

    I ran a var_dump and the post_status information is being passed correctly. And naturally it shows up correctly when viewing the post in WP Admin Panel

    Strange.

  8. Daniel Bachhuber
    Hand Built
    Posted 2 years ago #

    Can you post your code in a pastebin or Gist so I can take a look? Also, include the code with your var_dump...

  9. schtifin
    Member
    Posted 2 years ago #

  10. Daniel Bachhuber
    Hand Built
    Posted 2 years ago #

    Sorry, wrong dump (or wrong place for your var_dump())

    In the code where you're subscribing your user groups to email notifications, can you var_dump() your statuses and let me know what you see?

  11. schtifin
    Member
    Posted 2 years ago #

    I believe this is the code you requested:
    http://pastebin.com/aFkCsaXn

    In this case, where would I place var_dump?

  12. Daniel Bachhuber
    Hand Built
    Posted 2 years ago #

    At the top of the snippet, var_dump() both status values and the $post var

  13. schtifin
    Member
    Posted 2 years ago #

    Forgive my ignorance, but the code snippet was in the WP functions file. How or where would I be able to see the var_dump info?

    I tried a few different things like forcing new_status and old-status values, but I don't believe I did that correctly. I also tried running wp_update_post after the new post was inserted, but that was a mistake.

    I realize this is really outside the scope of edit-flow, so I do appreciate your help.

  14. Daniel Bachhuber
    Hand Built
    Posted 2 years ago #

    The var_dump() should fire when you execute wp_insert_post(). You can include a die() after the var_dumps to make sure.

Topic Closed

This topic has been closed to new replies.

About this Topic