Custom comments form

时间:2013-06-05 作者:Pieter Goosen

我有以下代码:

function pietergoosen_persoonlike_kommentaar_velde($fields) {

    $commenter = wp_get_current_commenter();
    $req = get_option( \'require_name_email\' );
    $aria_req = ( $req ? " aria-required=\'true\'" : \'\' );

    $fields =  array(

  \'author\' =>
\'<p class="comment-form-author"><label for="author">\' . __( \'Naam\', \'pietergoosen\' ) .
( $req ? \'<span class="required">*</span>\' : \'\' ) . \'</label> \' .
\'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) .
\'" size="30"\' . $aria_req . \' /></p>\',

  \'email\' =>
\'<p class="comment-form-email"><label for="email">\' . __( \'E-pos Adres\', \'pietergoosen\' ) .
( $req ? \'<span class="required">*</span>\' : \'\' ) . \'</label> \' .
\'<input id="email" name="email" type="text" value="\' . esc_attr(  $commenter[\'comment_author_email\'] ) .
\'" size="30"\' . $aria_req . \' /></p>\',

  \'verwysing\' =>
\'<p class="comment-form-verwysing"><label for="verwysing">\' . __( \'Waar het jy van die webtuiste gehoor\', \'pietergoosen\' ) . \'</label>\' .
\'<input id="verwysing" name="verwysing" type="text" value="\' . esc_attr( $commenter[\'comment_author_verwysing\'] ) .
\'" size="30" /></p>\',
);
return $fields;
}

 add_filter(\'comment_form_default_fields\',\'pietergoosen_persoonlike_kommentaar_velde\');
我从教程中获得了这段代码。我想编辑“留言”,您的电子邮件地址将不会发布。必填字段标记为*\',注释框和“发表注释”按钮。如何编辑此代码并包括我要做的更改。我很难理解如何实现法典中给出的内容。我用的是“十二个孩子”主题

2 个回复
最合适的回答,由SO网友:Pieter Goosen 整理而成

我为每个需要更改comment\\u表单输出的人制定了问题的解决方案>,下面是我的做法。把它改成你想要的任何语言,我的是南非荷兰语。只需添加一个注释,不要删除任何$arg,因为这可能会使您拥有的任何自定义验证方法崩溃

function pietergoosen_persoonlike_kommentaar_velde($args = array(), $post_id = null ) {
if ( null === $post_id )
    $post_id = get_the_ID();
else
    $id = $post_id;

$commenter = wp_get_current_commenter();
$user = wp_get_current_user();
$user_identity = $user->exists() ? $user->display_name : \'\';

$req      = get_option( \'require_name_email\' );
$aria_req = ( $req ? " aria-required=\'true\'" : \'\' );
$html5    = isset( $args[\'format\'] ) && \'html5\' === $args[\'format\'];
    $fields =  array(

    \'author\' =>
    \'<p class="comment-form-author"><label for="author">\' . __( \'Naam\', \'pietergoosen\' ) .
    ( $req ? \'<span class="required">*</span>\' : \'\' ) . \'</label> \' .
    \'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) .
    \'" size="30"\' . $aria_req . \' /></p>\',

    \'email\' =>
    \'<p class="comment-form-email"><label for="email">\' . __( \'E-pos Adres\', \'pietergoosen\' ) .
    ( $req ? \'<span class="required">*</span>\' : \'\' ) . \'</label> \' .
    \'<input id="email" name="email" type="text" value="\' . esc_attr(  $commenter[\'comment_author_email\'] ) .
    \'" size="30"\' . $aria_req . \' /></p>\',

    \'verwysing\' =>
    \'<p class="comment-form-verwysing"><label for="verwysing">\' . __( \'Waar het jy van die webtuiste gehoor\', \'pietergoosen\' ) . \'</label>\' .
    \'<input id="verwysing" name="verwysing" type="text" value="\' . esc_attr( $commenter[\'comment_author_verwysing\'] ) .
    \'" size="30" /></p>\',
);

$required_text = sprintf( \' \' . __(\'Velde wat verlang word is gemerk %s\'), \'<span class="required">*</span>\' );

$arg = array(
    \'fields\'               => apply_filters( \'comment_form_default_fields\', $fields ),
    \'comment_field\'        => \'<p class="comment-form-comment"><label for="comment">\' . _x( \'Deel jou mening oor die artikel\', \'noun\' ) . \'</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>\',
    \'must_log_in\'          => \'<p class="must-log-in">\' . sprintf( __( \'Jy moet <a href="%s">ingeteken</a> wees om jou mening te lig.\' ), wp_login_url( apply_filters( \'the_permalink\', get_permalink( $post_id ) ) ) ) . \'</p>\',
    \'logged_in_as\'         => \'<p class="logged-in-as">\' . sprintf( __( \'Jy is ingeteken as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Teken uit die rekening uit">Teken uit?</a>\' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( \'the_permalink\', get_permalink( $post_id ) ) ) ) . \'</p>\',
    \'comment_notes_before\' => \'<p class="comment-notes">\' . __( \'Jou e-pos adres sal onder geen omstandighede gedeel word met enige iemand nie.\' ) . ( $req ? $required_text : \'\' ) . \'</p>\',
    \'comment_notes_after\'  => \'<p class="form-allowed-tags">\' . sprintf( __( \'Baie dankie indien jy besluit het om jou mening te lig oor die artikel. Neem asseblief kennis dat alle menings op alle artikels eers gemodereer word voor dit geplaas word.\' )) . \'</p>\',
    \'id_form\'              => \'commentform\',
    \'id_submit\'            => \'submit\',
    \'title_reply\'          => __( \'Deel jou mening met ons\' ),
    \'title_reply_to\'       => __( \'Deel jou meningmet ons in verband met %s\' ),
    \'cancel_reply_link\'    => __( \'Verwyder mening\' ),
    \'label_submit\'         => __( \'Stuur jou mening\' ),
    );
return $arg;
}

add_filter(\'comment_form_defaults\', \'pietergoosen_persoonlike_kommentaar_velde\');

SO网友:tinyhook

我认为这不是您想要更改的代码/功能,此代码/功能只是创建表单字段。你应该看看你的评论。php文件,用于请求的更改。

结束

相关推荐