Archive for 2月, 2013

wordpressのコメント欄は名前とEメールアドレスが必須となっていますが、
これを名前のみ必須にする方法です。

 

1.Eメールの入力チェックを変更する。

Eメールの入力チェックを実施しないように変更します。
「wp-comments-post.php」 を編集します。

77行目あたりの以下のコードをコメントアウトします。

if ( get_option('require_name_email') && !$user->exists() ) {
if ( 6 > strlen($comment_author_email) || '' == $comment_author )
wp_die( __('ERROR: please fill the required fields (name, email).') );
elseif ( !is_email($comment_author_email))
wp_die( __('ERROR: please enter a valid email address.') );
}

更に以下のコードを入力します。

if(!$user->ID){
if ('' == $comment_author)
wp_die('名前を入力して下さい。');
}

2.Eメールアドレス入力欄を削除する

Eメールアドレス入力欄を削除するには、wp-includes配下の「comment-template.php」を編集します。

1523行目あたりのコードを以下のように編集します。

■編集前

$fields = array(
'author' => '

' . ' ' . '

', 'email' => '', 'url' => '

' . '

', );

■編集後

$fields = array(
'author' => '

' . ' ' . '

', 'url' => '

' . '

' );

3.不要なメッセージを非表示にする

上記の編集を実施しても、「メールアドレスが公開されることはありません」という表記が残っていますので、

以下のように編集することで非表示になります。 wp-includes配下の「comment-template.php」を編集します。

1530行目あたり

$defaults = array(
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
'comment_field' => '

', 'must_log_in' => '', 'logged_in_as' => '

' . sprintf( __( 'Logged in as %2$s. Log out?' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '

', //コメントアウト 'comment_notes_before' => '

' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '

', 'comment_notes_after' => '

' . sprintf( __( 'You may use these HTML tags and attributes: %s' ), ' ' . allowed_tags() . '' ) . '

', 'id_form' => 'commentform', 'id_submit' => 'submit', 'title_reply' => __( 'Leave a Reply' ), 'title_reply_to' => __( 'Leave a Reply to %s' ), 'cancel_reply_link' => __( 'Cancel reply' ), 'label_submit' => __( 'Post Comment' ), );

上記の3つの作業で実現することができます。

編集結果は以下の通りです。

20130221