Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get the current username

  • @iwishiknew

    Participant

    Right now I have this function

    function bp_template_content_sub_function() {
        if ( is_user_logged_in() ) {
            //Add shortcode to display content in sub tab
    		if($_SERVER['REQUEST_URI']=="/members/lolno1/mystocks/activity/")
    		{
    		echo do_shortcode('[user-activity]');}
        } else {
            wp_login_form( array( 'echo' => true ) );
        }
    }

    in my functions.php. lolno1 is the username. So if I go to that url, with that username, the correct information displays, however, if I’m logged in as another user, I have to go to that url to get the current users info to display, which of course is incorrect. The url should be /members/[current user]/mystocks/activity/

    How do I change the above code to have the current logged in user URI work correctly?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @shanebp

    Moderator

    It probably be easier to add the shortcode to whatever template is loaded for this screen:
    /members/[current user]/mystocks/activity/

    @iwishiknew

    Participant

    Well this is in functions.php I dont think I can use a shortcode within a function

    @iwishiknew

    Participant

    Ya I cant that doesnt work. Basically just trying to say something like if you are on this url, echo the shortcode. But it only works when I hardcode the url like /members/lolno1/mystocks/activity/ but that doesnt account for if its a different user logged in

    thanks for any help!

    @iwishiknew

    Participant

    Fixed it by changing it to this:

    function bp_template_content_sub_function() {
        if ( is_user_logged_in() ) {
            //Add shortcode to display content in sub tab
    		if ( bp_loggedin_user_domain() . '/mystocks/activity/' )
    		{
    		echo do_shortcode('[user-activity]');}
        } else {
            wp_login_form( array( 'echo' => true ) );
        }
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get the current username’ is closed to new replies.
Skip to toolbar