Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use this in functions.php to change "howdy" to "Logged in as...." But now under 3.1 I get "Logged in as Your Profile" rather than "Logged in as <current user>"

What needs to be changed so that "user" below (commented below as //get current user?) returns the current user in 3.1?

if (is_admin()) {
    add_action('init', 'better_howdy_h');
    add_action('admin_footer', 'better_howdy_f');

    function better_howdy_h() {
        wp_enqueue_script('jquery');
    }

    function better_howdy_f() {
?>
<script type="text/javascript">
/* <![CDATA[ */
    var user = jQuery('#user_info p a:first').text();
    var howdy = jQuery('#user_info p')
        .html()
        .replace(/<.+>/ig,'')
        .replace(/\ \|\n/ig,'');
    jQuery('#user_info p')
        .html(
            jQuery('#user_info p')
                .html()
                .replace(user,'My Profile')
        .replace(howdy,'Logged in as ' + user + ' | ') //get current user?
                .replace('!',' |')
                .replace('| |','|')
        );
/* ]]> */
</script>
<?php 
    } 
}
share|improve this question
    
Don't you have it already in the user variable you extracted from the text? –  hakre Jul 8 '11 at 14:23
    
I don't know; that's the complete function I am using. I don't see in the first place where user is grabbed. –  songdogtech Jul 8 '11 at 14:25
    
Just some lines above: var user = jQuery('#user_info p a:first').text(); –  hakre Jul 8 '11 at 14:27
add comment

2 Answers

up vote 4 down vote accepted

Why fiddle around with jQuery when you could just run a filter on gettext to specifically target that text? Perhaps you simply don't know you can do that, so here's how..

add_filter( 'gettext', 'change_howdy_text', 10, 2 );
function change_howdy_text( $translation, $original ) {
    if( 'Howdy, %1$s' == $original )
        $translation = 'Logged in as %1$s';
    return $translation;
}

Hope that helps. :)

share|improve this answer
    
Ah, very smart. I was using the original function as I stole it from a plugin called "Better Howdy." Didn't realize there was an easier way. Thanks! –  songdogtech Jul 8 '11 at 17:54
    
Could you explain what the %1$s is please? I carn't seem to find anything on wordpress about it. –  Elliott Jul 9 '11 at 16:36
    
They are placeholders for variable data used in translation strings, see I18n_for_WordPress_Developers. –  t31os Jul 10 '11 at 11:07
    
.. And Mark, you're welcome mate... ;) –  t31os Jul 10 '11 at 11:07
add comment
if (is_admin()) {
    add_action('init', 'better_howdy_h');
    add_action('admin_footer', 'better_howdy_f');

    function better_howdy_h() {
        wp_enqueue_script('jquery');
    }

    function better_howdy_f() {
?>
<script type="text/javascript">
/* <![CDATA[ */
    jQuery(document).ready(function(){
        var user = jQuery('#user_info div p').text();
        user = user.substr(7);
        jQuery('#user_info div p').html("Logged in as "+user);
    });
/* ]]> */
</script>
<?php 
    } 
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.