[wp-trac] [WordPress Trac] #16576: comment_form() fields being displayed only for non logged in users

WordPress Trac noreply at wordpress.org
Sun Oct 26 08:31:42 UTC 2014


#16576: comment_form() fields being displayed only for non logged in users
--------------------------+------------------------------
 Reporter:  maorb         |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Comments      |     Version:  3.0.5
 Severity:  normal        |  Resolution:
 Keywords:  dev-feedback  |     Focuses:
--------------------------+------------------------------

Comment (by valendesigns):

 Actually, an alternative to the above would be to change up the if/else
 block. This would assume that there is an argument called
 `$args['show_fields_logged_in']` to work, but the argument could be named
 anything. I think this would be a better solution because there is very
 little meddling in the code and very little needs to be changed in the
 docs to support it.

 {{{
 <?php if ( is_user_logged_in() ) : ?>
         <?php
         /**
          * Filter the 'logged in' message for the comment form for
 display.
          *
          * @since 3.0.0
          *
          * @param string $args_logged_in The logged-in-as HTML-formatted
 message.
          * @param array  $commenter      An array containing the comment
 author's
          *                               username, email, and URL.
          * @param string $user_identity  If the commenter is a registered
 user,
          *                               the display name, blank
 otherwise.
          */
         echo apply_filters( 'comment_form_logged_in',
 $args['logged_in_as'], $commenter, $user_identity );
         ?>
         <?php
         /**
          * Fires after the is_user_logged_in() check in the comment form.
          *
          * @since 3.0.0
          *
          * @param array  $commenter     An array containing the comment
 author's
          *                              username, email, and URL.
          * @param string $user_identity If the commenter is a registered
 user,
          *                              the display name, blank otherwise.
          */
         do_action( 'comment_form_logged_in_after', $commenter,
 $user_identity );
         ?>
 <?php endif; ?>
 <?php if ( ! is_user_logged_in() || true ===
 $args['show_fields_logged_in'] ) : ?>
         <?php echo $args['comment_notes_before']; ?>
         <?php
         /**
          * Fires before the comment fields in the comment form.
          *
          * @since 3.0.0
          */
         do_action( 'comment_form_before_fields' );
         foreach ( (array) $args['fields'] as $name => $field ) {
                 /**
                  * Filter a comment form field for display.
                  *
                  * The dynamic portion of the filter hook, $name, refers
 to the name
                  * of the comment form field. Such as 'author', 'email',
 or 'url'.
                  *
                  * @since 3.0.0
                  *
                  * @param string $field The HTML-formatted output of the
 comment form field.
                  */
                 echo apply_filters( "comment_form_field_{$name}", $field )
 . "\n";
         }
         /**
          * Fires after the comment fields in the comment form.
          *
          * @since 3.0.0
          */
         do_action( 'comment_form_after_fields' );
         ?>
 <?php endif; ?>
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/16576#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list