Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Logged-In User Profile Link URL

Viewing 12 replies - 26 through 37 (of 37 total)

  • bp-help
    Participant

    @bphelp


    bp-help
    Participant

    @bphelp

    Let me know if it worked for you as well!


    struth
    Participant

    @struth

    I just hijacked Mr Jacoby code:

    add_action('after_setup_theme', 'remove_admin_bar');     // remove admin bar for users
    
    function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
      show_admin_bar(false);
    }
    }
    
     function redirect2profile(){
    	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    	if($_SERVER['REQUEST_URI'] == '/profile/' && is_plugin_active('buddypress/bp-loader.php') && is_user_logged_in()){     //show buddypress user profile page
    		global $current_user;
    		wp_redirect( get_bloginfo('url') . '/members/'. $current_user->user_login . '/profile/'); 
    		exit();
    	}
     }
    add_action('init', 'redirect2profile');
    
    ?>

    Into a plugin for those who don’t know how, or just don’t want to add this code to the functions.php file. you can download it HERE

    Removes the admin bar for all users except Administrators and gets “global $current_user;” profile to a page you create called Profile as described by jackreichert

    I’ve said it before but I’m going to say it again – you’re a genius Mr Jacoby


    xiot
    Participant

    @xiot

    @bphelp

    This looks nice but wasn’t what I was looking for since I have a frontpage already and don’t want to change it!
    But the link within the code was pretty helpfull! I couldn’t find out where to find the bp-custom.php. Now I know that it has to be created 😀 Thanks anyway!

    And also thanks to @struth !
    Cause of you i found out how to switch the result of is_user_logged_in() . It’s a simple “!” that needs to be in front of the function!

    But I still can’t imagine why the snippet was named to direct visitors to the registration page! It doesn’t do that.

    Now the code is modded and it DOES redirect not logged in users to the registration page!

    Feel free to use it 🙂

     function redirect2profile(){
    	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    	if($_SERVER['REQUEST_URI'] == '/profile/' && is_plugin_active('buddypress/bp-loader.php') && is_user_logged_in()){ 
    		global $current_user;
    		wp_redirect( get_bloginfo('url') . '/member/'. $current_user->user_login . '/profile/'); 
    		exit();
    	} else {
    		if ($_SERVER['REQUEST_URI'] == '/profile/' && is_plugin_active('buddypress/bp-loader.php') && !is_user_logged_in()) {
    		wp_redirect( get_bloginfo('url') . '/register/'); 
    		exit();
    		}}
    			
     }
    add_action('init', 'redirect2profile');
    

    Cheers, Lars


    struth
    Participant

    @struth

    I was quietly hoping you would figure this out, well done Lars.

    Will test it out in adminbarbegone tomorrow, looks good, Thanks for being open with you code and posting, this will help me alot. I couldn’t get this code to redirect not logged in users to the registration page but then, I’m a n00b with php; lol

    s2Members uses ! a lot in short code
    [s2If !is_user_logged_in()]if user is not logged in show this [/s2If]


    @paintermommy
    might find s2Members quite useful at soulwomansanctuary but it looks like she has sorted it out

    Next I need to work on an admin page to switch functions on and off, should be fun but I keep getting side tracked with responsibilities.


    bp-help
    Participant

    @bphelp

    @xiot
    You said:

    I want the code to redirect the not logged in user to a register page

    Next time you request help please make sure you are more specific. One minute you say you want the logged out users to be redirected to the register page, then you flip and say you have a front page and don’t want to change it. When we offer code here a lot of times it is dependent on what you specifically ask for.


    xiot
    Participant

    @xiot

    @bphelp

    Yeah sorry, I thought it would be clear because i referred to a certain code. The whole block I wrote above the quote you posted was about the code I also posted.

    Sooo.. let’s just handle it as a communication problem! Then again, thanks for the idea and the help and sorry that I wasn’t specific enough. I am not a native of the english language.

    Regards, Lars


    bp-help
    Participant

    @bphelp

    @xiot
    There is no problem, I simply meant that by being more specific it will help all of the volunteers help you more efficiently next time around! 🙂


    xiot
    Participant

    @xiot

    @bphelp

    🙂 yeah sorry, I’ll keep that in mind. I will be more specific next time so the helping hands can actually help 😉

    Thanks bphelp 🙂


    bridieamelia
    Participant

    @bridieamelia

    Hi, this thread was really helpful to me trying to add a link on my homepage to the logged in user’s profile page.

    I ended up writing it up as a shortcode so thought I’d post here for future seekers.

    function myprofile_shortcode() {
    	global $current_user;
    	get_currentuserinfo(); 
    	$myprofileurl = '<a href="'. home_url() . '/members/' . $current_user->user_login . '/profile/">My Profile</a>';
    	return $myprofileurl;
    }
    add_shortcode('myprofileurl', 'myprofile_shortcode');

    Happy days 🙂


    zwrodgers
    Participant

    @zwrodgers

    @bridieamelia

    I’m not a developer and don’t know a ton about coding. Where do I paste this for it to work?

    And then how do I use it?


    danbp
    Moderator

    @danbp

    Shortcodes are used by WordPress since version 2.5.

    https://codex.wordpress.org/Shortcode
    https://codex.wordpress.org/Shortcode_API

    To use the above snippet, you copy/paste it into your child-theme functions.php.
    And you use the shortcode like this [myprofileurl] within post or comments.

    Bla bla bla [myprofileurl] bla bla… will print out Bla bla bla My Profile bla bla…

    I hope for you that you want to write something else before My profile as bla bla bla 😉

Viewing 12 replies - 26 through 37 (of 37 total)
  • The topic ‘[Resolved] Logged-In User Profile Link URL’ is closed to new replies.
Skip to toolbar