Identify Visitor and User on Wordpress

1

I'm working on a wordpress plugin, and I need to change the Login menu name to My Account when the user is logged in.

I also need to change the title of the page. I've tried using the filter below, but it ends up changing all the links in the site.

add_filter('the_title', 'function_name');

And how much to change the name of the menu, I did not find anything about it, does anyone have any suggestions about something?

Thank you in advance ...

THE CODE

Trying to add a shortcode to be used as above!

if ( !function_exists('custom_login_form') )
{
    function custom_login_form()
    {
        $args=array(
            "echo" => false,
            "label_log_in" => "Entrar",
            "remember"  => true,
        );
        if ( !is_user_logged_in() ){
            return wp_login_form($args);
        }else{
            return 'Logado em Minha conta! <br />' . wp_loginout('index.php');
        }
    }
}
add_shortcode('login_form', 'custom_login_form');

This works perfectly, I would now like to make changes to the menu and page title!

RESOLUTION

After many searches I was able to find a solution to the problem, which by coincidence I had tried and did not work at all.

Using the following filter.

add_filter('wp_nav_menu_items', 'function_name', 10, 2);
function func_name_wp_nav($items, $args){
    return $items;
}

Then you add items according to the menu, which is usually LI it adds as the last element, example.

$item .= "<li><a href='#'>Item 1</a></li>";

This worked perfectly for me! Any questions regarding the post, comment and I will try to answer as I know.

Thank you ...

    
asked by anonymous 16.02.2015 / 05:32

1 answer

1

You should be looking to use the is_user_logged_in() function, if the user is logged in the return value is true , otherwise it is false .

if ( is_user_logged_in() ) {
    // Fazer algo quando esse usuário estiver logado
} else {
    // Fazer algo caso seja um visitante
}

On the second question, the function the_title should work, however if you prefer to use something clean , use the_title_attribute , both have pretty much the same goal, but the latter has one more parameter which is $post that allows you to specify the ID or object of a post, change, by default the current post is fetched.

To change the menu name, here ( Changing Admin Menu Labels - WordPress Development SE) have a solution that maybe works for you.

    
16.02.2015 / 12:13