Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#33482 closed defect (bug) (invalid)

Filter "comment_form_default_fields" removes all fields except textarea for comment

Reported by: bhdzllr's profile bhdzllr Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3
Component: Comments Keywords:
Focuses: template Cc:

Description

When trying to use the filter "comment_form_default_fields" just the textarea for the comment is displayed. Other fields (Name, E-Mail, etc.) disappear.
Tried with own template and also with the following snippet in "Twenty Fifteen". Works before updating to WordPress 4.3. Maybe it has something to do with #30157?

function my_comment_form() {
	// Code
}

add_filter( 'comment_form_default_fields', 'my_comment_form' );

Change History (3)

#1 @swissspidy
9 years ago

  • Focuses ui removed
  • Keywords reporter-feedback added

Hey there, thanks for your report!

Just wanna confirm you're correctly using the comment_form_default_fields filter. Unlike actions, it's important that you return the data passed to the callback specified in your add_filter call again. Like this:

function my_comment_form( $fields ) {
  // Modify $fields here. Add a new field for example:
  $fields['my-new-field'] = '…';

  // Remove the website field
  unset( $fields['url'] );

  // You must return the $fields again
  return $fields;
}
add_filter( 'comment_form_default_fields', 'my_comment_form' );

Otherwise this won't work. I can't reproduce any problems with this filter on a clean install and there haven't been any changes to the default comment fields recently. #30157 would only have an impact on the comment_form_defaults filter. If your filter looks like the example above, try disabling all plugins & using the default themes to reproduce this.

Have a look at the source code for details.

If you have more questions regarding the comment form fields, I suggest asking in the support forums.

#2 @bhdzllr
9 years ago

You are right. Works when returning the fields.
Thought it worked on an previous version of WordPress and therefore is a bug.
Sorry for the issue. Thank you for your help.

#3 @swissspidy
9 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.