1

I want to include a link to a profile of the current user who's filling out the form on a frontend of my website.

That is, to place automatically a current user's author link like this in the "Author Profile" field in a form: example.com/author/username

What should I include in the form field?

  • You mean the url is example.com/author/username or you want to reconstitute example.com/author/username from the currently logged in user? – codiiv Mar 5 '17 at 16:19
  • To get a author URL profile from the currently logged in user, the one who's filling out the form.. – Marko I. Mar 5 '17 at 16:24
0
<?php 

$currentUser = get_current_user_id();   //get  currently logged user ID  

$user = get_user_by( 'id', $currentUser );   // Get the user Object by id

$userUrl = get_bloginfo('home').'/author/'.$user->user_login; //Formulate the outout 

echo $userUrl; //echo the output 
?>
  • Please edit your answer, and add an explanation: why could that solve the problem? – fuxia Mar 5 '17 at 16:57
  • @toscho : 1) What needs to be edited? 2) Why do I need to explain anything? The code I put generate a user url in the form of example.com/author/username where username is the username of the currently logged in user. – codiiv Mar 5 '17 at 17:02
  • For example: why get_current_user_id() and a manual query for the user instead of wp_get_current_user()? Why the deprecated get_bloginfo('home') instead of home_url( $path )? Where does the author part in URL come from? That's open for customization, so the URL might not work. Why don't you think the resulting URL needs to be escaped? As you can see, good explanations matter. :) – fuxia Mar 5 '17 at 17:17
  • @tosco: 1) get_bloginfo() is not depricated (developer.wordpress.org/reference/functions/get_bloginfo) , 2) "author" part is from the structure given in the question (assuming they have permalink structured accordingly) 3) Why escape the URL ? – codiiv Mar 5 '17 at 17:33
  • The 'home' argument is deprecated, answers should take common customizations into account, the URL contains dynamic parts that can be filtered and are therefore not trustworthy.. – fuxia Mar 5 '17 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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