[英]Notify guest author by email on WordPress website
我在 WordPress 網站上使用了一個名為 User Submitted Posts 的插件。 該插件使用簡碼創建表單。 當用戶填寫表單時,提交的信息用於創建帖子。 通過表單提交的姓名作為來賓作者存儲在數據庫中。 提交的 email 存儲為 user_submit_email。
我遇到的問題是,當有人評論他們的帖子時,來賓作者沒有收到通知。 我試圖弄清楚如何設置它,以便通過 email 將通知發送給來賓作者,而無需網站所有者對每個帖子提交進行手動操作來設置它。
下面的代碼是我從用戶提交的帖子插件中找到的。 我將它定位在網站子主題中的 functions.php 文件中。
add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );
function guest_author_name( $name ) {
global $post;
$author = get_post_meta( $post->ID, 'guest-author', true );
if ( $author )
$name = $author;
return $name;
}
你需要把它交給一個動作鈎子,而不是一個過濾器。 如果要處理提交評論的用戶,請使用 wp_insert_comment_hook。
假設您存儲了 post meta guest_author
,您將執行類似的操作
function wpr_authorNotification( $comment_id, $comment_object) {
$post = get_post($comment_object->comment_post_ID);
if ( ! isset($post->guest_author) ) {
return;
}
$message = "";
$subject = "";;
wp_mail($post->guest_author, $subject, $message);
}
add_action('wp_insert_comment', 'wpr_authorNotification', 99, 2);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.