Dear support!
I'm creating a member profile page. This page is displayed by a Content Template for a Member custom post type. I would like some sensitive information like a phone number be shown only to a member himself, not to other users who'd be viewing the profile.
Is there any way to do it using shortcodes like [wpv-if]? Something like display this only if wpv-post-author equals to the currently logged in user? Does a shortcode to get a currenly logged in user exist?
If it is not possible with shortcodes, are there any other way to do that?
Thank you in advance!
Dear Kirill,
It is not possible within Views, you can try create a WP shortcode for it, like this:
1) add codes in your theme/functions.php :
add_shortcode( 'is_logged', 'is_logged_func');
function is_logged_func($atts){
if(is_user_logged_in()){
return '1';
}else{
return '0';
}
}
2) Then use this shortcode in your view:
[wpv-if evaluate="'[is_logged]' = ''1"] //LOGGED
[wpv-if evaluate="'[is_logged]' = ''0"] //NOT LOGGED
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Can you confirm the syntax when calling your own shortcode:
[wpv-if evaluate="'[is_logged]' = '1'"]
IS LOGGED
[/wpv-if]
I found this example, trying to do the same thing and am getting no content when for either IF case when i run:
logged status: [is_logged]<br>
[wpv-if evaluate="'[is_logged]' = '1'"]
IS LOGGED
[/wpv-if]
[wpv-if evaluate="'[is_logged]' = '0'"]
NOT IS LOGGED
[/wpv-if]
* Is there any cacheing within the wpv-if ?
Dear Adriano!
Thanks for your response!
The shortcode alone works for me.
This: Login status is [is_logged]
prints either 1 or 0 for logged in or logged out users respectively.
However,
[wpv-if evaluate="'[is_logged]' = '1'"] This user is logged in [/wpv-if]
[wpv-if evaluate="'[is_logged]' = '0'"] The user is logged out [/wpv-if]
does not work, it prints nothing for both logged in and logged out users.
To double check the statement,
[wpv-if evaluate="'1' = '1'"] This user is logged in [/wpv-if] works (as stupid as it may sound). Considering the only difference with the previous statement is the lack of [is_logged] shortcode, I believe Views cannot resolve a shortcode within a [wpv-if] shortcode. Is this the case? Is there any way around it?
Maybe I can create a shortcode that will take content of the if statement as an additional parameter? Can I use [wpv-...] shortcodes within my own shortcode via do_shortcode()?
Many thanks,
Kirill
Dear Kirill,
Please let me see your complete code.
Dear Adriano,
here is what I have in functions.php:
add_shortcode( 'is_logged', 'is_logged_func');
function is_logged_func($atts){
if(is_user_logged_in()){
return '1';
}else{
return '0';
}
}
and here is a content of my Content Template:
Login status: [is_logged]<br />
[wpv-if evaluate="'[is_logged]' = '1'"] The user is logged in [/wpv-if]
[wpv-if evaluate="'[is_logged]' = '0'"] The user is logged out [/wpv-if]
The output is:
Login status: 1 for logged in users and
Login status: 0 if user is logged out.
You can see that it outputs login status correctly but fails to evaluate condition within [wpv-if] statement.
I would like to reproduce it on Discover WP server but looks like I cannot edit theme files there so this is not an option :-(.
Please let me know if you need any additional information.
Thank you!
@Kirill and @justin,
Please replace the shortcode name to add_shortcode( 'wpv-post-is-logged', 'is_logged_func') and use like this [wpv-if evaluate="'[wpv-post-is-logged]' = '1'"].
This works! Thanks so much
This works for me too!
Sorry for late response, was having trouble with access to the forum.
Thank you for your excellent (as usual) support!
Just what I was looking for too! Just implemented it and it works perfectly.