Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Luke Janicke on "$user_identity in comment_form_defaults filter not working"

$
0
0

In my comments template, I have customized the comment form using the two filters comment_form_defaults and comment_form_default_field.

It seems the variable $user_identity isn’t working. It’s returning an empty string. I’m using the filter, not arguments, so $user_identity is already set in the comment_form() function before the filter is performed.

Here’s my filter…

function my_comment_form_defaults( $defaults ) {
    $defaults['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>', get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>';
    return $defaults;
}
add_filter( 'comment_form_defaults', 'my_comment_form_defaults' );

Note:
The codex says to use admin_url( 'profile.php' ).
But in the code for comment_form() it now uses get_edit_user_link().
That’s not relevant to my question but I point it out in case anyone notices that difference.

The only difference between my filtered code and the default code is that I’ve removed the translation function __(). That will be restored later. Before I further customize my code, I need the variable $user_identity to work properly.

Here’s the HTML output…

<p class="logged-in-as">Logged in as <a href="http://www.mydomain.com/wp-admin/profile.php"></a>. …

Can anyone see why $user_identity is returning an empty string?


Viewing all articles
Browse latest Browse all 8245

Trending Articles