wp admin - Send email to user that his post has been rejected

I am searching for a solution for the following problem: I am using WP User Frontend, so that users can create posts in

I am searching for a solution for the following problem:

I am using WP User Frontend, so that users can create posts in the frontend. After saving, the admin needs to review the post, and the publish (if approved), or reject (if not approved).

If the post is approved, an email is automatically sent to the user, that his post has been approved (this I already found out how to do).

But if the admin does not approve, how to send the user an email, with a possible custom text (why he did not approve) from the backend, per click on a button?

I am searching for a solution for the following problem:

I am using WP User Frontend, so that users can create posts in the frontend. After saving, the admin needs to review the post, and the publish (if approved), or reject (if not approved).

If the post is approved, an email is automatically sent to the user, that his post has been approved (this I already found out how to do).

But if the admin does not approve, how to send the user an email, with a possible custom text (why he did not approve) from the backend, per click on a button?

Share Improve this question edited Sep 14, 2013 at 10:00 brasofilo 22.1k8 gold badges70 silver badges264 bronze badges asked Sep 14, 2013 at 8:22 AspedAsped 3567 silver badges13 bronze badges 5
  • 1 What is "wp_user_frontend" ? If this is plugin please link to it so others don't have to look it up. – Rarst Commented Sep 14, 2013 at 8:26
  • 1 For a complete context, how are you sending the approval email? – brasofilo Commented Sep 14, 2013 at 9:58
  • Here is the snipplet which send the approval mail: paulund.co.uk/send-email-to-wordpress-author-on-post-publish But this is automated. I need the rejection to be per click – Asped Commented Sep 14, 2013 at 10:20
  • No time for a complete answer, so I comment to give you a hint what to do. You can either use ajax or put the button in a form to execute your reject function on button click. Take a look around, I'm 100% certain this has been answered on here. Good luck! – Nicolai Grossherr Commented Sep 14, 2013 at 13:09
  • Another idea, use the wp_trash_post or the before_delete_post action to hook in. There are others - documented here: codex.wordpress/Plugin_API/Action_Reference – Nicolai Grossherr Commented Sep 14, 2013 at 13:21
Add a comment  | 

1 Answer 1

Reset to default 3

In the post edit page, just under the 'Publish' button, add a button, 'Reject and Notify' that once clicked open a modal (thickbox) window that contain a form (pre-compiled with the post author name, post title and a standard message) that you can use to send the email to post author.

To accomplish this you need:

  1. A function that print the button. You can use the 'post_submitbox_misc_actions' action hook to print it in the right place
  2. A function that output the form in a modal window. This function should use the current post id to get the author and put the author email in a hidden field.
  3. A function that send the email when the form is submitted

The 2 last functions can work easily with Ajax Api, so you need also a js file where put the ajax and other js code.

So, another function is needed for the script enqueueing and script localize with wp_localize_script

The button should contain also js-accessible information about current post, a data-* attribute can be used for that.

For both the functions that print the button and the form (points 1. and 2.) you have to check that:

  • the current user has editor capabilities
  • the current page is the post edit page (post.php)

In the function that sends the email (points 3.) you have to do some security tasks:

  • check if the current user has editor capabilities
  • check a nonce (previously added as hidden field on the form)

After that, this function should output some info on the mail send process (message sended or not) and output them as json, in this way via js it's possible to give a feedback on the modal. If an error occurred, is a good idea also output some debug info, maybe checking if debugging is active or not in WP.


Edit: Plugin Code

In the original answer I posted the code here. Now I've just created a plugin to include all the workflow described here using OOP approach. The plugin is ready for localization and already localized in italian.

The plugin in GPL licensed and available on GitHub.


Plugin Screenshots





If something goes wrong and debug is active...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742404206a4437513.html

相关推荐

  • wp admin - Send email to user that his post has been rejected

    I am searching for a solution for the following problem: I am using WP User Frontend, so that users can create posts in

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信