Hello. The output of profiles (they are available to all visitors for viewing) is done through the author.php template. It is necessary to make a condition: if an authorized person has opened a page with his profile, then show him some content, if not, do not show it. There was an idea to compare the author’s ID of the page with the ID of the user who visited it, but I can’t do the condition. Help is needed.
1 answer
Well, it's not entirely clear how your template works. How is determined by which user this page. If standard, then most likely through the GET string. Then in the template you need to get information about the user, whose page we show:
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); In the $ curauth variable, we will have all the information about the user:
$curauth->aim; $curauth->description; $curauth->display_name; $curauth->first_name; $curauth->ID; $curauth->jabber; $curauth->last_name; $curauth->nickname; $curauth->user_email; $curauth->user_login; $curauth->user_nicename; $curauth->user_registered; $curauth->user_url; $curauth->yim; Now you need to get information about the authorized user:
$current_user = wp_get_current_user(); Now you can write the conditions:
if($curauth->ID == $current_user->ID){ echo "secret information"; } - oneStarting with version 4.5,
get_currentuserinfo()condemnsget_currentuserinfo()and recommends usingwp_get_current_user(). Correct the code in the answer, please. - Gleb Kemarsky pm - If I understand you correctly, then the_author_meta is used in the data output template: first name, last name, etc. and the page is formed simply by domen / author / nickname - Aaron
- Then this method should suit you - Nikita Bale
- Yes, I have already started, it really works, thanks. Although the algorithm is based on the Slug, to determine the user and then later pull out the data) - Aaron
|