Yep! Totally doable, and glad you figured it out 🙂 I’ve updated the documentation.
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?
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?
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.
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.
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.
Can you post your code in a pastebin or Gist so I can take a look? Also, include the code with your var_dump…
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?
I believe this is the code you requested:
http://pastebin.com/aFkCsaXn
In this case, where would I place var_dump?
At the top of the snippet, var_dump() both status values and the $post var
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.
The var_dump() should fire when you execute wp_insert_post(). You can include a die() after the var_dumps to make sure.