admin管理员组文章数量:1387402
I setup a custom post type and everything works right. The user can submit for review and I see it's pending in the admin area. How can I have WordPress send me an Email Notification whenever a user submits a post?
add_action( 'init', 'artwork_feature');
function artwork_feature() {
register_post_type( 'artwork',
array(
'labels' => array(
'name' => __( 'Artwork' ),
'singular_name' => __( 'Artwork' )
),
'public' => true,
'exclude_from_search' => false,
'capability_type' => 'artwork',
'supports' => array('custom-fields', 'comments'),
'capabilities' => array(
'publish_posts' => 'publish_artworks',
'edit_posts' => 'edit_artworks',
'edit_others_posts' => 'edit_others_artwork',
'delete_posts' => 'delete_artworks',
'delete_others_posts' => 'delete_others_artwork',
'read_private_posts' => 'read_private_artwork',
'edit_post' => 'edit_artwork',
'delete_post' => 'delete_artwork',
'read_post' => 'read_artwork',
),
'map_meta_cap' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail')
)
);
}
I setup a custom post type and everything works right. The user can submit for review and I see it's pending in the admin area. How can I have WordPress send me an Email Notification whenever a user submits a post?
add_action( 'init', 'artwork_feature');
function artwork_feature() {
register_post_type( 'artwork',
array(
'labels' => array(
'name' => __( 'Artwork' ),
'singular_name' => __( 'Artwork' )
),
'public' => true,
'exclude_from_search' => false,
'capability_type' => 'artwork',
'supports' => array('custom-fields', 'comments'),
'capabilities' => array(
'publish_posts' => 'publish_artworks',
'edit_posts' => 'edit_artworks',
'edit_others_posts' => 'edit_others_artwork',
'delete_posts' => 'delete_artworks',
'delete_others_posts' => 'delete_others_artwork',
'read_private_posts' => 'read_private_artwork',
'edit_post' => 'edit_artwork',
'delete_post' => 'delete_artwork',
'read_post' => 'read_artwork',
),
'map_meta_cap' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail')
)
);
}
Share
Improve this question
edited Mar 27, 2014 at 17:04
Nicolai Grossherr
18.9k8 gold badges64 silver badges109 bronze badges
asked Mar 25, 2014 at 20:33
BrianBrian
1501 silver badge8 bronze badges
9
|
Show 4 more comments
1 Answer
Reset to default 1WordPress has a save_post hook, which is an action triggered whenever a post or page is created or updated.
Add something like this below to your functions.php:
function my_project_updated_send_email( $post_id ) {
// If this is just a revision, don't send the email.
if ( wp_is_post_revision( $post_id ) )
return;
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';
$message = "A post has been updated on your website:\n\n";
$message .= $post_title . ": " . $post_url;
// Send email to admin.
wp_mail( '[email protected]', $subject, $message );
}
add_action( 'save_post', 'my_project_updated_send_email' );
One thing to note is that your localhost by default will not send out an email to an external source - unless you have configured it. There is however a couple of plugins that will allow you to send via SMTP, that way you can easily test from localhost.
The example above is taken from the save_post codex page, however in addition to the above, you would want to add filters to only send it out for your custom post type and not every post, as well as maybe just for a fresh create rather than all updates (by specifying which post status you want alerts for) - up to you to decide.
All the best,
Kat
本文标签: customizationCustom Post Type Alerts
版权声明:本文标题:customization - Custom Post Type Alerts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744515826a2610152.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'supports' => array('comments')
View Codex – Howdy_McGee ♦ Commented Mar 25, 2014 at 20:52Settings->Discussion
– Howdy_McGee ♦ Commented Mar 27, 2014 at 13:50