問題描述
當我們發表評論時,我希望向訂閲者發送電子郵件。
Codex 中的兩個操作是:
1 。
add_action('comment_post', 'callback', $priority, $accepted_args);
參數是 comment_ID
和 approval status
(0 或 1) 。
2 。
add_action('edit_comment', 'callback', $priority, $accepted_args);
用參數 comment_ID
默認情況下,評論在發佈時不被批准,所以我認為我會在批准它們時進行編輯,但在食典中卻不清楚。當我批准評論時,應該使用哪個選項?
最佳解決方案
就像帖子一樣,註釋可以有一個不同狀態的數組,所以不用命名每個狀態的鈎子,它們有過渡掛鈎,它告訴你以前有什麼狀態,什麼是新的狀態。在你的情況下,這可能是訣竅:
add_action('transition_comment_status', 'my_approve_comment_callback', 10, 3);
function my_approve_comment_callback($new_status, $old_status, $comment) {
if($old_status != $new_status) {
if($new_status == 'approved') {
// Your code here
}
}
}
讓我們知道怎麼回事?
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。