Skip to content

Instantly share code, notes, and snippets.

@jmarreros
Last active February 21, 2018 05:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmarreros/ab39193904aae699fe4308520b954889 to your computer and use it in GitHub Desktop.
Save jmarreros/ab39193904aae699fe4308520b954889 to your computer and use it in GitHub Desktop.
Modificar el formulario de comentarios de WordPress
<?php
//Filtro para modificar la estructura
//de los campos del formulario de comentarios
add_filter( 'comment_form_defaults', 'dcms_modify_fields_form' );
function dcms_modify_fields_form( $args ){
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$author = '<input placeholder="'.__( 'Name' ) . ( $req ? ' *' : '' ).'" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .'" size="30"' . $aria_req . ' />';
$email = '<div class="fields-wrap"><input placeholder="'.__( 'Email' ) . ( $req ? ' *' : '' ).'" id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .'" size="30"' . $aria_req . ' />';
$url = '<input placeholder="'.__( 'Website' ).'" id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .'" size="30" /></div>';
$comment = '<textarea placeholder="'. _x( 'Comment', 'noun' ).'" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>';
$args['fields']['author'] = $author;
$args['fields']['email'] = $email;
$args['fields']['url'] = $url;
$args['comment_field'] = $comment;
return $args;
}
//Filtro para modificar el orden de los campos
//del formulario de comentarios
add_filter( 'comment_form_fields', 'dcms_modify_order_fields' );
function dcms_modify_order_fields( $fields ){
$val = $fields['comment'];
unset($fields['comment']);
$fields += array('comment' => $val );
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment