LoginSignup
1

More than 3 years have passed since last update.

WordPressでコメントを強制的に承認済みとする

Posted at

はじめに

普通のWordPressのサイトであれば、管理画面のディスカッション設定の「コメント表示条件」でチェックを外せばいいのですが、マルチサイトだと面倒でそんなことできません。
という場合に、コメントが入力されたら強制的に承認済みとするコードを紹介します。

コード

add_filter('wp_insert_comment', 'force_approved_comment', 10, 2);
function force_approved_comment($commentID, $comment) {
    wp_set_comment_status($commentID, 'approve');
}

コメントが挿入されるときのwp_insert_commentフックで、強制的にコメントのステータスを承認済みにしています。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1