• I want to collect Name, Email and Rating (for which I have a set of radio buttons) when a user comments a post. Based on Codex page for comment_form() I constructed the following code for my custom fields:

    $fields =  array(
                                        'author' => '<p class="comment-form-author"><label for="author">' . __( 'Name', 'domainreference' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
                                        'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'domainreference' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
                                        'rating' => '<p class="comment-form-rating"><label for="rating">Ваша оценка:</label><br/> ' . ( $req ? '<span class="required">*</span>' : '' ) . 'Хорошо <input type="radio" name="rating" value="positive"' . $aria_req . ' /><br/>Плохо <input type="radio" name="rating" value="negative"' . $aria_req . ' /><br/>Нейтрально<input type="radio" name="rating" value="neutral"' . $aria_req . ' checked /></p>'
                                    );

    Then I make a list of arguments for the comment_form(), also based on the Codex page:

    $args = array('fields' => apply_filters('comment_form_default_fields',$fields),
                                            'comment_field' => '<p class="comment-form-comment"><label for="comment">Ваш отзыв</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
                                            'comment_notes_after' => '',
                                            'label_submit' => 'Оставить отзыв',
                                            'title_reply' => 'Оставить отзыв'
                                    );

    Then comment_form($args) is being called. As a result I see what was intended if I look at the post as an unlogged user and I don’t see my custom fields if the user is logged. I can understand if WordPress somehow screens the Name and Email fields for a logged in user, but the Rating section must be shown even for those logged in users. How do I do that?

  • The topic ‘Cusom fields for comment_for() are not displayed if logged in’ is closed to new replies.