I was wondering if there is a way of refining my If Else statement in the following code:
<?php if ( ms_has_membership(01) ): ?>
// HTML - USER PROFILE
<?php global $current_user;
get_currentuserinfo();
elseif (is_user_logged_in() && $current_user->ID == $post->post_author): ?>
// HTML - USER PROFILE - (Same as above)
<?php else: ?>
// LINK - Upgrade Your Subscription
<?php endif; ?>
Basically, I need to say that if the user has a required membership ( in the first statement, then user profiles will be visible.
If the user doesn't have a required membership, but is logged in and is visiting his own profile ( is the author ), then only his own profile will be accessible.
And If the user is not logged in, nor is author, nor has a valid membership, no profiles will be visible, instead a link to upgrade subscription will show up.
My problem is that the HTML of the user profile is pretty long and I don't want to repeat the whole thing again in the second statement.
So is there a way to refine the statement, so it reads:
If the user is logged in AND has a valid membership OR is and author, then display the profile?
Could I use || and && in one single statement??
As you said:- So is there a way to refine the statement, so it reads: If the user is logged in AND has a valid membership OR is and author, then display the profile?
You can do it in following way:-
<?php
global $current_user;
get_currentuserinfo();
?>
<?php if ( is_user_logged_in() && (ms_has_membership(01) || $current_user->ID == $post->post_author) ): ?>
// HTML - USER PROFILE
<?php else: ?>
// LINK - Upgrade Your Subscription
<?php endif; ?>
Related
I need three different pages showing different parts of one user profile on wordpress. Author.php is a standard feature and is great is loads on my website www.website.com/site1/user/nicename. However I want to have one profile which is sorted, but display the profile over three different areas of the website.
PLEASE NOTE: Username in this example would be joe-blogs1990 what ever the user decides, the nicename will be formatted joebloggs, first and surname combined for nice permalinks on wordpress.
www.website.com/site1/author/username
www.website.com/site2/agency/nicename
www.website.com/site3/meet-the-team/nicename
I simply wish to call user profile information in three different places, but they will have different information on each one, I’ve managed to create a place where everything is edited in one place, however to display information based on the URL is slightly bewildered me.
Here is what I have so far, but nothing is loading on any of the pages what im trying to achieve above.
<?php get_header(); ?>
<?php $blogname = get_bloginfo('name'); if ( $blogname == 'site1' ) {
get_the_author_meta('description');
} ?>
<?php $blogname = get_bloginfo('name'); if ( $blogname == 'site2' ) {
get_the_author_meta('first_name');
get_the_author_meta('last_name');
} ?>
<?php $blogname = get_bloginfo('name'); if ( $blogname == 'site3' ) {
get_the_author_meta('facebook_profile');
get_the_author_meta('twitter_profile');
} ?>
<?php get_footer(); ?>
Try adding echo in Front of the get_the_whatever methods. All methods prefixed with get_ just return strings; in order to see something you have to echo it.
Most of the code I can find are about specific content being showed to the logged in user based on their role.
I want to do the opposite.
This is basically what I want to do:
If author has "Subscriber" role, show some html A. If author has "Customer" role, show html B.
I think this should be possible but I am not sure where to begin.
Here's the snippet I am using but not working so might have error somewhere?
<?php $current_author_roles = get_the_author_meta('roles');?>
<?php if ( in_array('Customer', $current_author_roles) ) { ?>
//do something
<?php } else { ?>
//do something else
<?php } ?>
Use a conditional. For example:
$current_author_roles = get_the_author_meta('roles');
if ( in_array('Customer', $current_author_roles) ) {
// do something
}
You can read more about get_the_author_meta() in the Codex.
I would like to change to homepage of a wordpress website depending on the role of the user who is logged in.
For the simple case ( i.e. whether a user is logged in or not ) I have tried using the function is_user_logged_in()
the code is as below:
if(!is_user_logged_in()){
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
endwhile;
}else{
echo "you are logged in";
}
But the problem is that it changes the content in the each and every page. I would like to do that for a particular page only.. ( i.e. homepage ). How do i do that? Any help would be greatly appreciated.
To do it you would have to add another condition(s), e.g. for the homepage:
if(!is_user_logged_in() && is_home()){
...
}
And similarly for the other type of the content: is_page(), is_category(), is_author(), etc. Check out the docs here.
check for the Id of the page and compare it to your wanted specific page
also you could set a category for the pages you want to alter and check for that
I have a line that prints the contact information of a user in his profile. Only logged in user can see the contact information.
<?php
// Contact Info
?>
I have 2 user roles - supervisor, manager
What I am trying to achieve is that if the logged in user is a supervisor then he can see his own contact info, but he cannot see manager's contact.
But If the logged in user is a manager then he can see his own contact info, but he can also see supervisor's contact info.
I have been trying to use the standard if current_user_is function, but this will only display one or the other.
<?php global $current_user;
get_currentuserinfo();
if(current_user_is("manager"))
echo 'Contact Info Here';
else if(current_user_is("supervisor"))
echo 'Contact Info Here';
else if(current_user_is_not("manager"))
echo 'Restricted contact, must be a manager';
?>
I just can't figure out how to make this work, so it displays conditionally.
I also have these rules in the global rule, not sure how relevant it is :
$store_user = get_userdata( get_query_var( 'author' ) );
$store_info = get_store_info( $store_user->ID );
$user_meta = get_user_meta($store_user->ID);
From the question, it looks like you'll need to call the get_users function and pass the "supervisor" role to get users of that type and display their contact info to the "manager" role.
As you've written it, the contact info being displayed is for the current user. You'll need to grab another role's contact info if that's what you want to display.
Untested but this may be close...
//if current user is the manager...
$supervisors = get_users( 'role=supervisor' );
foreach ($supervisors as $supervisor) {
echo '<span>' . esc_html( $supervisor->user_email ) . '</span>';
}
I'm nothing more than a beginner with php but using 'OR' may help you aggregate roles' conditions on a single piece of content:
<?php global $current_user;
get_currentuserinfo();
if(current_user_is("manager") OR current_user_is("supervisor"))
echo 'Contact Info Here';
else()
echo 'Restricted contact, must be a manager';
?>
On my site when a user is registering there is an option to pick from 3 values (House, car, boat). Once the user has registered and viewing their profile, I want to show a button on the front-end based on what meta value they have selected when registering. If they have no meta key, then nothing is shown.
Here is my code attempt, but does not work!
<?php global $current_user;
get_currentuserinfo(); //wordpress global variable to fetch logged in user info
$userID = $current_user->ID; //logged in user's ID
$havemeta1 = get_user_meta($userID,'house',true); //stores the value of logged in user's meta data for 'house'
$havemeta2 = get_user_meta($userID,'car',true); //stores the value of logged in user's meta data for 'car'
$havemeta3 = get_user_meta($userID,'boat',true); //stores the value of logged in user's meta data for 'boat'
?>
<!--add if statement to figure out what button to show to logged in user-->
<?php if ($havemeta1) { ?>
<div class="Button1"></div>
<?php } elseif ($havemeta2) { ?>
<div class="Button2"></div>
<?php } elseif ($havemeta3) { ?>
<div class="Button3"></div>
<?php } else { ?>
<div></div>
<?php }?>
In short - The expected result is, if the user has choose House when registering, then show the DIV with the class=Button1 etc etc
Update:
This code above now works!