2015-03-31 14:17:52 +00:00
|
|
|
<?php
|
2016-11-21 16:25:56 +00:00
|
|
|
/**
|
2019-11-14 17:16:31 +00:00
|
|
|
* Comment layout
|
2016-11-21 16:25:56 +00:00
|
|
|
*
|
|
|
|
* @package understrap
|
|
|
|
*/
|
2015-03-31 14:17:52 +00:00
|
|
|
|
2019-06-20 08:57:12 +00:00
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
2018-09-10 21:59:04 +00:00
|
|
|
|
2020-04-18 18:55:25 +00:00
|
|
|
// Add Bootstrap classes to comment form fields.
|
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
|
|
|
|
2018-03-05 06:29:00 +00:00
|
|
|
if ( ! function_exists( 'understrap_bootstrap_comment_form_fields' ) ) {
|
2020-04-18 18:55:25 +00:00
|
|
|
/**
|
|
|
|
* Add Bootstrap classes to WP's comment form default fields.
|
|
|
|
*
|
|
|
|
* @param array $fields {
|
|
|
|
* Default comment fields.
|
|
|
|
*
|
|
|
|
* @type string $author Comment author field HTML.
|
|
|
|
* @type string $email Comment author email field HTML.
|
|
|
|
* @type string $url Comment author URL field HTML.
|
|
|
|
* @type string $cookies Comment cookie opt-in field HTML.
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-03-05 06:29:00 +00:00
|
|
|
function understrap_bootstrap_comment_form_fields( $fields ) {
|
2020-04-18 18:55:25 +00:00
|
|
|
|
|
|
|
$replace = array(
|
|
|
|
'<p class="' => '<div class="form-group ',
|
|
|
|
'<input' => '<input class="form-control" ',
|
|
|
|
'</p>' => '</div>',
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( isset( $fields['author'] ) ) {
|
|
|
|
$fields['author'] = strtr( $fields['author'], $replace );
|
|
|
|
}
|
|
|
|
if ( isset( $fields['email'] ) ) {
|
|
|
|
$fields['email'] = strtr( $fields['email'], $replace );
|
|
|
|
}
|
|
|
|
if ( isset( $fields['url'] ) ) {
|
|
|
|
$fields['url'] = strtr( $fields['url'], $replace );
|
|
|
|
}
|
|
|
|
|
|
|
|
$replace = array(
|
|
|
|
'<p class="' => '<div class="form-group form-check ',
|
|
|
|
'<input' => '<input class="form-check-input" ',
|
|
|
|
'<label' => '<label class="form-check-label" ',
|
|
|
|
'</p>' => '</div>',
|
2018-03-05 06:29:00 +00:00
|
|
|
);
|
2020-04-18 18:55:25 +00:00
|
|
|
if ( isset( $fields['cookies'] ) ) {
|
|
|
|
$fields['cookies'] = strtr( $fields['cookies'], $replace );
|
|
|
|
}
|
2018-03-05 06:29:00 +00:00
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
2020-04-18 18:55:25 +00:00
|
|
|
} // End of if function_exists( 'understrap_bootstrap_comment_form_fields' )
|
2016-11-21 16:25:56 +00:00
|
|
|
|
2020-04-18 18:55:25 +00:00
|
|
|
// Add Bootstrap classes to comment form submit button and comment field.
|
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
|
|
|
|
2018-03-05 06:29:00 +00:00
|
|
|
if ( ! function_exists( 'understrap_bootstrap_comment_form' ) ) {
|
2020-04-18 18:55:25 +00:00
|
|
|
/**
|
|
|
|
* Builds the form.
|
|
|
|
*
|
|
|
|
* @param string[] $args Comment form arguments and fields.
|
|
|
|
*
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2018-03-05 06:29:00 +00:00
|
|
|
function understrap_bootstrap_comment_form( $args ) {
|
2020-04-18 18:55:25 +00:00
|
|
|
$replace = array(
|
|
|
|
'<p class="' => '<div class="form-group ',
|
|
|
|
'<textarea' => '<textarea class="form-control" ',
|
|
|
|
'</p>' => '</div>',
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( isset( $args['comment_field'] ) ) {
|
|
|
|
$args['comment_field'] = strtr( $args['comment_field'], $replace );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $args['class_submit'] ) ) {
|
|
|
|
$args['class_submit'] = 'btn btn-secondary';
|
|
|
|
}
|
|
|
|
|
2018-03-05 06:29:00 +00:00
|
|
|
return $args;
|
|
|
|
}
|
2020-04-18 18:55:25 +00:00
|
|
|
} // End of if function_exists( 'understrap_bootstrap_comment_form' ).
|