問題描述

當我們發表評論時,我希望向訂閱者傳送電子郵件。

Codex 中的兩個操作是:

1 。

add_action('comment_post', 'callback', $priority, $accepted_args);

引數是 comment_IDapproval 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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。