custom-comments.php ➔ spurs_bootstrap_comment_form()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Comment layout.
4
 *
5
 * @package spurs
6
 */
7
8
// Exit if accessed directly.
9
defined( 'ABSPATH' ) || exit;
10
11
// Comments form.
12
add_filter( 'comment_form_default_fields', 'spurs_bootstrap_comment_form_fields' );
13
14
/**
15
 * Creates the comments form.
16
 *
17
 * @param string $fields Form fields.
18
 *
19
 * @return array
20
 */
21
22
if ( ! function_exists( 'spurs_bootstrap_comment_form_fields' ) ) {
23
24
	function spurs_bootstrap_comment_form_fields( $fields ) {
25
		$commenter = wp_get_current_commenter();
26
		$req       = get_option( 'require_name_email' );
27
		$aria_req  = ( $req ? " aria-required='true'" : '' );
28
		$html5     = current_theme_supports( 'html5', 'comment-form' ) ? 1 : 0;
29
		$consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
30
		$fields    = array(
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $fields. This often makes code more readable.
Loading history...
31
			'author'  => '<div class="form-group comment-form-author"><label for="author">' . __( 'Name',
32
					'spurs' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
33
			             '<input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . '></div>',
34
			'email'   => '<div class="form-group comment-form-email"><label for="email">' . __( 'Email',
35
					'spurs' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
36
			             '<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>',
37
			'url'     => '<div class="form-group comment-form-url"><label for="url">' . __( 'Website',
38
					'spurs' ) . '</label> ' .
39
			             '<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"></div>',
40
			'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 . ' /> ' .
41
			             '<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', 'spurs' ) . '</label></div>',
42
		);
43
44
		return $fields;
45
	}
46
} // endif function_exists( 'spurs_bootstrap_comment_form_fields' )
47
48
add_filter( 'comment_form_defaults', 'spurs_bootstrap_comment_form' );
49
50
/**
51
 * Builds the form.
52
 *
53
 * @param string $args Arguments for form's fields.
54
 *
55
 * @return mixed
56
 */
57
58
if ( ! function_exists( 'spurs_bootstrap_comment_form' ) ) {
59
60
	function spurs_bootstrap_comment_form( $args ) {
61
		$args['comment_field'] = '<div class="form-group comment-form-comment">
62
	    <label for="comment">' . _x( 'Comment', 'noun', 'spurs' ) . ( ' <span class="required">*</span>' ) . '</label>
63
	    <textarea class="form-control" id="comment" name="comment" aria-required="true" cols="45" rows="8"></textarea>
64
	    </div>';
65
		$args['class_submit']  = 'btn btn-secondary'; // since WP 4.1.
66
67
		return $args;
68
	}
69
70
} // endif function_exists( 'spurs_bootstrap_comment_form' )
71