Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a custom theme that is based off of Starkers html5 3.0 and use that theme's comment system. I have followed custom_form tutorials by Otto, Soapbox Dave, forlogos, and Deluxe Blog Tips.

All of my code seems to be functioning properly except that I cannot get any of the fields outside of comment_form_default_fields to display. This theme is setup as a child theme but there is no comment code in the parent yet.

Can you help me find the issue?

Related functions.php code:

//   Custom Callback - Comments
if ( ! function_exists( 'starkers_comment' ) ) :
/**
 * Template for comments and pingbacks.
 *
 * @since Starkers HTML5 3.0
 */
function starkers_comment( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
        case '' :
    ?>


    <article <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">

        <?php comment_author_link() ?> <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> 
        <?php echo time_ago(); ?></a> ... <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?><br />

        <?php if ( $comment->comment_approved == '0' ) : _e( 'Your comment is awaiting moderation.', 'starkers' ); ?><br />
        <?php endif; 

        comment_text(); ?>


    <?php
            break;
        case 'pingback'  :
        case 'trackback' :
    ?>
    <article <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
        <p><?php _e( 'Pingback:', 'starkers' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'starkers'), ' ' ); ?></p>
    <?php
            break;
    endswitch;
}
endif;

/**
 * Closes comments and pingbacks with </article> instead of </li>.
 *
 * @since Starkers HTML5 3.0
 */
function starkers_comment_close() {
    echo '</article>';
}

/**
 * Adjusts the comment_form() input types for HTML5.
 *
 * @since Starkers HTML5 3.0
 */
function starkers_fields($fields) {
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields =  array(
    'author' => '<p><label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '*' : '' ) .
        '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
    'email'  => '<p><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '*' : '' ) .
        '<input id="email" name="email" type="email" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
    'url'    => '<p><label for="url">' . __( 'Website' ) . '</label>' .
        '<input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
);
return $fields;
}
add_filter('comment_form_default_fields','starkers_fields');

function my_fields($fields) {
$fields['new'] = '<p>red rover 1</p>';
return $fields;
}
add_filter('comment_form_top','my_fields');

comments.php code:

<?php if ( post_password_required() ) : ?>
    <p><?php _e( 'This post is password protected. Enter the password to view any comments.', 'starkers' ); ?></p>
<?php return; endif; ?>

<?php // You can start editing here -- including this comment! ?>

<?php if ( have_comments() ) : ?>

        <div class="trirow_875h" id="comments-title"><h4 class="cufon">Activities</h4></div>
        <div class="trirow_875m" style="padding:10px 15px;">


    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
    <nav>
        <?php previous_comments_link( __( '&larr; Older Comments', 'starkers' ) ); ?>
        <?php next_comments_link( __( 'Newer Comments &rarr;', 'starkers' ) ); ?>
    </nav>
    <?php endif; // check for comment navigation

    wp_list_comments( array( 'style' => 'div', 'callback' => 'starkers_comment', 'end-callback' => 'starkers_comment_close' ) );

    if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
    <nav>
        <?php previous_comments_link( __( '&larr; Older Comments', 'starkers' ) ); ?>
        <?php next_comments_link( __( 'Newer Comments &rarr;', 'starkers' ) ); ?>
    </nav>

    <?php endif; // check for comment navigation 
          else : // or, if we don't have comments:
            if ( ! comments_open() ) : ?>

    <p><?php _e( 'Comments are closed.', 'starkers' ); ?></p>
    <?php endif; // end ! comments_open() 
          endif; // end have_comments() 
          ?>

        </div>
        <div class="trirow_875b"></div>
    <div class="clear"></div>

<?php comment_form(); ?>
Is there anybody out there?
<input type="hidden" name="my_user_id" value="<?php echo $myid; ?>" />
share|improve this question

1 Answer 1

up vote 3 down vote accepted

This code makes no sense:

function my_fields($fields) {
$fields['new'] = '<p>red rover 1</p>';
return $fields;
}
add_filter('comment_form_top','my_fields');

I'm not even sure what it's supposed to do, because comment_form_top is an action, not a filter.

If you want to add extra fields, you should be using the comment_form_default_fields filter:

add_filter('comment_form_default_fields','my_fields'); 

However, this might not work or might work intermittently, because the starkers_fields function is written incorrectly. It should be this:

function starkers_fields($fields) {
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields['author'] = '<p><label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '*' : '' ) .
        '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
$fields['email'] = '<p><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '*' : '' ) .
        '<input id="email" name="email" type="email" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>';

$fields['url'] = '<p><label for="url">' . __( 'Website' ) . '</label>' .
        '<input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>';
);
return $fields;
}
add_filter('comment_form_default_fields','starkers_fields');

The difference here is that this version modifies the fields instead of replacing them outright. Thus allowing other fields to pass through it unaltered.

Assuming that you don't want to change the starkers_fields function, possibly because it's a parent theme that you don't control, then you can work around its brokenness by adjusting your filter priority to make sure my_fields runs after it, like so:

function my_fields($fields) {
$fields['new'] = '<p>red rover 1</p>';
return $fields;
}
add_filter('comment_form_default_fields','my_fields',20);
share|improve this answer
    
Awesome! Thanks so much @Otto ! –  mattrepublic Feb 26 '11 at 17:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.