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="https://www.mydomain.com/wp-admin/profile.php"></a>. …
Can anyone see why $user_identity
is returning an empty string?
Here is the code snippet that is responsible for doing this:
echo '<div class="login">' . $before_widget . $before_title . "Welcome ".$user_identity . $after_title . '</div>';
I tried to add $user_info->first_name in place of $user_identity but nothing shows up after “Welcome”
Any ideas what I’m doing wrong?
Thanks in advance
<?php ?>
within posts/pages which works like a charm.
I have been trying to add a string variable used in the header to my page. The following is a very simplified version.
<?php
if( $user_identity ) echo 'Welcome back';
else echo 'Welcome guest, please enjoy your stay';
?>
I am only receiving the else function because wp is stripping out the string variables. Which I found out by doing this…
<?php echo $user_identity;?>
there is no result but the same string can be found right next to ‘howdy’.
My question, how can I extend the use for the wp string variables beyond the header?
]]>if ($comment->user_id) {$user=$comment->user_id; echo $user}
to output a nice name instead of the ID?
I’ve tried using $user_identity
but haven’t been able to get it to work.
Basically if the commenter was a registered user I want to output their name on the comment.
Any help, please?
]]>Basically, I want to use the user_identity function on the header.php file for a user bar.
Here is my code:
<!-- User Start -->
<?php if ( $user_ID ) : ?>
Welcome <b><?php echo $user_identity; ?></b>!
( <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout">Log Out</a> | <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php">Profile</a><?php wp_register(); ?> )
<?php else : ?>
Welcome <b>Guest</b>!
( <a href="<?php echo get_option('siteurl'); ?>/wp-login.php">Log In</a><?php wp_register(); ?> )
<?php endif; ?>
<!-- User End -->
I know that my coding isn’t the most optimized but that wouldn’t be the reason for the function to not work.
I would be most grateful if someone could assist me in resolving this issue.
]]>