解锁BuddyPress中的评论表单

时间:2012-03-25 作者:Pollux Khafra

我正在尝试取消钩住在函数中找到的注释表单。deafault buddypress主题的php,所以我可以对其进行一些更改。我将这段代码放入我的子主题函数中。php,但它没有改变任何东西。我做错了什么?

remove_filter( \'comment_form_defaults\', \'bp_dtheme_comment_form\', 10 );
if ( !function_exists( \'my_dtheme_comment_form\' ) ) :
function my_dtheme_comment_form( $default_labels ) {
global $user_identity;

$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">\' . __( \'Name\', \'buddypress\' ) . ( $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">\' . __( \'Email\', \'buddypress\' ) . ( $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>\',
    \'url\'    => \'<p class="comment-form-url"><label for="url">\' . __( \'Website\', \'buddypress\' ) . \'</label>\' .
                \'<input id="url" name="url" type="text" value="\' . esc_attr( $commenter[\'comment_author_url\'] ) . \'" size="30" /></p>\',
);

$new_labels = array(
    \'comment_field\'  => \'<p class="form-textarea"><textarea name="comment" id="comment" cols="60" rows="10" aria-required="true"></textarea></p>\',
    \'fields\'         => apply_filters( \'comment_form_default_fields\', $fields ),
    \'logged_in_as\'   => \'\',
    \'must_log_in\'    => \'<p class="alert">\' . sprintf( __( \'You must be <a href="%1$s">logged in</a> to post a comment.\', \'buddypress\' ), wp_login_url( get_permalink() ) ) . \'</p>\',
    \'title_reply\'    => __( \'\', \'buddypress\' )
);

return apply_filters( \'my_dtheme_comment_form\', array_merge( $default_labels, $new_labels ) );
}
add_filter( \'comment_form_defaults\', \'my_dtheme_comment_form\', 10 );
endif;
为了测试没有任何变化,我删除了“title\\u reply”的标签文本

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

已解决-如果我将wordpress函数放在子主题函数中,我没有意识到wordpress会覆盖默认主题中的函数。php。所以我所要做的就是将它们粘贴到我的函数中。php和编辑我想要的方式。

SO网友:Thibaut

Better,

add_action( \'init\', \'remove_bp_comment_filter\' );
function remove_bp_comment_filter() {
    remove_filter( \'comment_form_defaults\', \'bp_dtheme_comment_form\', 10 );
    remove_action( \'comment_form_top\', \'bp_dtheme_before_comment_form\' );
    remove_action( \'comment_form\', \'bp_dtheme_after_comment_form\' );
}
结束