[wp-trac] [WordPress Trac] #60281: Cannot unset comment_notes_before

WordPress Trac noreply at wordpress.org
Thu Jan 18 12:11:15 UTC 2024


#60281: Cannot unset comment_notes_before
--------------------------+-----------------------------
 Reporter:  bugnumber9    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:  6.4.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I want to reorder comment fields by unsetting and setting them back in my
 chosen order. Here's my code:

 {{{
 function my_reorder_comments_fields( $fields ) {
         $comment_notes_before_field = $fields['comment_notes_before'];
         $comment_field = $fields['comment'];
         $author_field = $fields['author'];
         $email_field = $fields['email'];
         $url_field = $fields['url'];
         $cookies_field = $fields['cookies'];

         unset( $fields['comment_notes_before'] );
         unset( $fields['comment'] );
         unset( $fields['author'] );
         unset( $fields['email'] );
         unset( $fields['url'] );
         unset( $fields['cookies'] );

         $fields['author'] = $author_field;
         $fields['email'] = $email_field;
         $fields['comment_notes_before'] = $comment_notes_before_field;
         $fields['cookies'] = $cookies_field;
         $fields['comment'] = $comment_field;

         return $fields;
 }
 add_filter( 'comment_form_fields', 'my_reorder_comments_fields' );
 }}}

 Result - https://imgur.com/a/ebY1HBW
 You can see that `$fields['comment_notes_before']` remains on top.
 To prove the point, I changed my code to just unset all fields:

 {{{
 function my_unset_comments_fields( $fields ) {
         unset( $fields['comment_notes_before'] );
         unset( $fields['comment'] );
         unset( $fields['author'] );
         unset( $fields['email'] );
         unset( $fields['url'] );
         unset( $fields['cookies'] );

         return $fields;
 }
 add_filter( 'comment_form_fields', 'my_unset_comments_fields' );
 }}}

 Result: https://imgur.com/a/B5wNngj
 So `$fields['comment_notes_before']` isn't getting unset while all other
 fields do.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60281>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list