I am having a problem placing the IF / ELSE statement without breaking the rest of the page.
I have a following banner on my page :
<div class="awesome-banner">
<div class="image-wrap<?php echo $banner ? '' : ' awesome-hide'; ?>">
<?php $banner_url = $banner ? wp_get_attachment_url($banner) : ''; ?>
<input type="hidden" class="awesome-file-field" value="<?php echo $banner; ?>" name="awesome_banner">
<img class="awesome-banner-img" src="<?php echo esc_url($banner_url); ?>">
<a class="close awesome-remove-banner-image">×</a>
</div>
<div class="button-area<?php echo $banner ? ' awesome-hide' : ''; ?>">
<i class="fa fa-cloud-upload"></i>
<a href="#" class="awesome-banner-drag awesome-btn awesome-btn-info"><?php _e('Upload banner', 'awesome'); ?></a>
<p class="help-block"><?php _e('(Upload a banner for your profile. Banner size is (825x300) pixel. )', 'awesome'); ?></p>
</div>
</div> <!-- .awesome-banner -->
<?php do_action('awesome_settings_after_banner', $current_user, $profile_info); ?>
I need to place in the following statement inside this banner ( PLEASE CORRECT IF WRONG ):
<?
if ((current_user_can('manager')) )
{ ?>
<div class="access-restricted">
<h5>Sign In Or Sign Up</h5>
<p class="non-manager-notice">You need to be a manager to upload a banner</p>
<div class="upgrade-button">
<a href="#" class="button-green-upgrade">Upgrade Account</a>
</div>
</div>
<?
return;
} else{
return false;
}
?>
So basically it should state the following inside this banner :
If the current user is user role "manager"
then instead of the <div class="button-area">
it should display <div class="access-restricted">
Otherwise just go on as normally.
I am trying to place the statement directly inside like this :
<div class="awesome-banner">
<div class="image-wrap<?php echo $banner ? '' : ' awesome-hide'; ?>">
<?php $banner_url = $banner ? wp_get_attachment_url($banner) : ''; ?>
<input type="hidden" class="awesome-file-field" value="<?php echo $banner; ?>" name="awesome_banner">
<img class="awesome-banner-img" src="<?php echo esc_url($banner_url); ?>">
<a class="close awesome-remove-banner-image">×</a>
</div>
// Here I am placing my statement like this
<?
if ((current_user_can('manager')) )
{ ?>
<div class="access-restricted">
<h5>Sign In Or Sign Up</h5>
<p class="non-manager-notice">You need to be a manager to upload a banner</p>
<div class="upgrade-button">
<a href="#" class="button-green-upgrade">Upgrade Account</a>
</div>
</div>
<?
return;
} else{
return false;
}
?>
// End of my statement
<div class="button-area<?php echo $banner ? ' awesome-hide' : ''; ?>">
<i class="fa fa-cloud-upload"></i>
<a href="#" class="awesome-banner-drag awesome-btn awesome-btn-info"><?php _e('Upload banner', 'awesome'); ?></a>
<p class="help-block"><?php _e('(Upload a banner for your profile. Banner size is (825x300) pixel. )', 'awesome'); ?></p>
</div>
</div> <!-- .awesome-banner -->
<?php do_action('awesome_settings_after_banner', $current_user, $profile_info); ?>
It displays the content correctly for the role, but it breaks the rest of the content on the page behind the awesome banner div.
Am I closing my statement and everything else correctly ?? Thanks
Further to my (and @maiorano84's comments), the return
will stop your code if either condition is met (true or false):
if(current_user_can('manager')) { ?>
<div class="access-restricted">
<h5>Sign In Or Sign Up</h5>
<p class="non-manager-notice">You need to be a manager to upload a banner</p>
<div class="upgrade-button">
<a href="#" class="button-green-upgrade">Upgrade Account</a>
</div>
</div><?
// If you need to record a true or false here, assign to a variable.
// Don't return or your code will stop here.
$manager = true;
}
else { ?>
<div class="button-area<?php if($banner) echo ' awesome-hide'; ?>">
<i class="fa fa-cloud-upload"></i>
<a href="#" class="awesome-banner-drag awesome-btn awesome-btn-info"><?php _e('Upload banner', 'awesome'); ?></a>
<p class="help-block"><?php _e('(Upload a banner for your profile. Banner size is (825x300) pixel. )', 'awesome'); ?></p>
</div><?php
// If you need true/false, assign here
$manager = false;
} ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.