Undefined variable on comments wordpress

Im tidying up my custom theme and in debug mode I am getting a undefined variable in my comments section. This is my custom comment section and the undefined variables showing up are aria_req, req and commenter. This custom comment function is within my functions file. How would I fix this?

// Edit Comment Forms
function alter_comment_form_fields($fields){

    $fields['author'] = '<div class="row"><div class="col-md-4"><p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                    '<input id="author" name="author" type="text" placeholder="Name" value="' . esc_attr( $commenter['comment_author'] ) . '"' . $aria_req . ' /></p></div>';
//Edit Email Field
$fields['email'] = '<div class="col-md-4"><p class="comment-form-author">' . '<label for="email">' . __( 'Email' ) . '</label> ' .                  ( $req ? '<span class="required">*</span>' : '' ) .
                    '<input id="email" name="email" type="text" placeholder="Email" value="' . esc_attr( $commenter['comment_author_url'] ) . '" "' . $aria_req . ' /></p></div>';
//Edit Website Field
$fields['url'] = '<div class="col-md-4"><p class="comment-form-author">' . '<label for="url">' . __( 'Website' ) . '</label> ' .                        ( $req ? '<span class="required">*</span>' : '' ) .
                    '<input id="url" name="url" type="text" placeholder="Website" value="' . esc_attr( $commenter['comment_author_url'] ) . '"' . $aria_req . ' /></p></div></div>';               

    return $fields;
}

add_filter('comment_form_default_fields','alter_comment_form_fields');

Related posts

Leave a Reply

3 comments

  1. try to put

    $aria_req = ($req) ? " aria-required='true'" : '' ;
    

    just before $comments_args. it works for me.

    erros comes up because $aria_req undefined or null.
    when $req is empty/null, $aria_req will be defined as ”.

  2. Undefined index errors occur when a variable which has not yet been initialized is used in an expression. What you can do is use isset() to check whether or not the variable is null before you attempt to use it.