2015-03-31 14:17:52 +00:00
< ? php
2016-11-21 16:25:56 +00:00
/**
* Comment layout .
*
* @ package understrap
*/
2015-03-31 14:17:52 +00:00
2018-09-10 21:59:04 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly.
}
2016-11-21 16:25:56 +00:00
// Comments form.
2017-11-27 08:02:16 +00:00
add_filter ( 'comment_form_default_fields' , 'understrap_bootstrap_comment_form_fields' );
2015-03-31 14:17:52 +00:00
2016-11-21 16:25:56 +00:00
/**
* Creates the comments form .
*
* @ param string $fields Form fields .
*
* @ return array
*/
2018-03-05 06:29:00 +00:00
if ( ! function_exists ( 'understrap_bootstrap_comment_form_fields' ) ) {
function understrap_bootstrap_comment_form_fields ( $fields ) {
$commenter = wp_get_current_commenter ();
$req = get_option ( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true' " : '' );
$html5 = current_theme_supports ( 'html5' , 'comment-form' ) ? 1 : 0 ;
2018-05-26 08:43:34 +00:00
$consent = empty ( $commenter [ 'comment_author_email' ] ) ? '' : ' checked="checked"' ;
2018-03-05 06:29:00 +00:00
$fields = array (
2018-05-18 08:47:48 +00:00
'author' => '<div class="form-group comment-form-author"><label for="author">' . __ ( 'Name' ,
2018-03-05 06:29:00 +00:00
'understrap' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input class="form-control" id="author" name="author" type="text" value="' . esc_attr ( $commenter [ 'comment_author' ] ) . '" size="30"' . $aria_req . '></div>' ,
2018-05-18 08:47:48 +00:00
'email' => '<div class="form-group comment-form-email"><label for="email">' . __ ( 'Email' ,
2018-03-05 06:29:00 +00:00
'understrap' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr ( $commenter [ 'comment_author_email' ] ) . '" size="30"' . $aria_req . '></div>' ,
2018-05-18 08:47:48 +00:00
'url' => '<div class="form-group comment-form-url"><label for="url">' . __ ( 'Website' ,
2018-03-05 06:29:00 +00:00
'understrap' ) . '</label> ' .
'<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr ( $commenter [ 'comment_author_url' ] ) . '" size="30"></div>' ,
2018-05-26 08:43:34 +00:00
'cookies' => '<div class="form-group form-check comment-form-cookies-consent"><input class="form-check-input" id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' /> ' .
2018-07-06 07:48:49 +00:00
'<label class="form-check-label" for="wp-comment-cookies-consent">' . __ ( 'Save my name, email, and website in this browser for the next time I comment' , 'understrap' ) . '</label></div>' ,
2018-03-05 06:29:00 +00:00
);
return $fields ;
}
} // endif function_exists( 'understrap_bootstrap_comment_form_fields' )
2016-11-21 16:25:56 +00:00
2017-11-27 08:02:16 +00:00
add_filter ( 'comment_form_defaults' , 'understrap_bootstrap_comment_form' );
2016-11-21 16:25:56 +00:00
/**
* Builds the form .
*
* @ param string $args Arguments for form ' s fields .
*
* @ return mixed
*/
2018-03-05 06:29:00 +00:00
if ( ! function_exists ( 'understrap_bootstrap_comment_form' ) ) {
function understrap_bootstrap_comment_form ( $args ) {
$args [ 'comment_field' ] = ' < div class = " form-group comment-form-comment " >
< label for = " comment " > ' . _x( ' Comment ', ' noun ', ' understrap ' ) . ( ' < span class = " required " >*</ span > ' ) . ' </ label >
< textarea class = " form-control " id = " comment " name = " comment " aria - required = " true " cols = " 45 " rows = " 8 " ></ textarea >
</ div > ' ;
$args [ 'class_submit' ] = 'btn btn-secondary' ; // since WP 4.1.
return $args ;
}
} // endif function_exists( 'understrap_bootstrap_comment_form' )