• Hi,

    I try to make some changes in the comment_form() – want to add a own class and change the “labels”.
    I really found good informations at Otto′s site, but it doesn′t work for my site…

    Here′s some code, that I added to the functions.php

    function my_comment_fields ( $fields ) {
        $commenter = wp_get_current_commenter();
    
        $fields = array(
                        'author' => '<p>' . '<input class="commentinput" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' .
                                    '<label for="author"><small>' . __( 'Name' ) .  ( $req ? '<span class="required">*</span> </small> </label> </p>' : ''  ),
                        'email'  => '<p><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                                    '<input class="commentinput" id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
                        'url'    => '<p><label for="url">' . __( 'Website' ) . '</label>' .
                                    '<input class="commentinput" id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
                        );
        return $fields;
        }
        add_filter( 'comments_form_default_fields', 'my_comment_fields' );

    And to make some changes in the “Output-Form”

    function my_comment_form ( $defaults ) {
        $defaults = array (
                            'fields'               => apply_filters( 'comments_form_default_fields', 'my_comment_fields' ),
                            'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea class="commenttext" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
                            'must_log_in'          => '<p class="must-log-in">' .  sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
                            'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
                            'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
                            'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
                            'id_form'              => 'commentform',
                            'id_submit'            => 'submit',
                            'title_reply'          => __( 'Leave a Reply' ),
                            'title_reply_to'       => __( 'Leave a Reply to %s' ),
                            'cancel_reply_link'    => __( 'Cancel reply' ),
                            'label_submit'         => __( 'Post Comment' ),
    );
        return $defaults;
        }
    
        add_filter( 'comments_form_defaults', 'my_comment_form' );

    But whatever I do, the basic form will be displayed in my blog. Where is the mistake?
    Thanks for help or a simple tip!
    Thomas

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter JakoThAn

    (@jakothan)

    So I found a way to make some changes, but now I have to fight with dozens of Warnings and Notices like;

    Notice: Undefined variable: post_id in D:\xampp\htdocs\wordpress\wp-content\themes\testtheme\functions.php on line 377

    This Variables and Values are already defined in the comment-template.php, isn′t it?
    Or did I have to define them again? Is there another (better) way to do this?

    Thanks a lot for any suggestion.
    Thomas

    That filter should be ‘comment_form_default_fields’ not ‘comments_form_default_fields’. Remove the “s” on “comments”. That was an error (I believe) with the codex. I updated it.

    hi, JakoThAn

    try to add these lines above the $fields definition:

    $commenter = wp_get_current_commenter();
    $req = get_option( 'require_name_email' );
    $aria_req = ( $req ? " aria-required='true'" : '' );

    and then, the notice about the ‘Undefined variable’ of post_id, you could just leave the get_permalink() function with no parameters, which means throw the ‘post_id’ away!

    hope this will help~

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to configure the comment_form under WP 3.0.x ?’ is closed to new replies.