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>
<?php _e('Upload banner', 'awesome'); ?>
<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">
Upgrade Account
</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">
Upgrade Account
</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>
<?php _e('Upload banner', 'awesome'); ?>
<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">
Upgrade Account
</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>
<?php _e('Upload banner', 'awesome'); ?>
<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;
} ?>
Related
I have some working PHP code and I have recently added a button that allows the user to download the image form the root directory, in the database we put the file name e.g. example.png / example.jpeg and when the user clicks download it opens the image in a new tab
what we need is: if the [proof] is= NULL , the download button disables, otherwise it will be enabled and they can click the button
<?php
// output data of each row
while($row=mysqli_fetch_assoc($designresult)) {
?>
<div class="card mb-4 box-shadow"><div class="card-header">
<h4 class="my-0 font-weight-normal">Job Reference: <?php echo $row["jobRef"]; ?></h4>
</div>
<div class="card-body">
<p><b>Company Name:</b><br> <?php echo $row["companyName"]; ?> </p>
<p><b>Requested:</b><br> <?php echo $row["dateReq"]; ?> </p>
<p><b>Request By:</b><br> <?php echo $row["yourName"]; ?> </p>
<p><b>Graphic Type:</b><br> <?php echo $row["graphicType"]; ?> </p>
<p><b>Double Sided:</b><br> <?php echo $row["doubleS"]; ?> </p>
<p><b>Design Info:</b><br> <?php echo $row["info"]; ?> </p>
<p><b>Purpose:</b><br> <?php echo $row["purpose"]; ?> </p>
<p><b>Proof:</b><br> <?php echo $row["approved"]; ?> </p>
<p><b>Proof Date:</b><br> <?php echo $row["appDate"]; ?> </p>
<a class="btn btn-success" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>">Download</a>
</div>
</div>
<?php
}
?>
To my knowledge the link tag does not have a "disabled" attribute. But you can "disable" the link by removing the href attribute.
Something like this: It checks if $row['proof'] has some value (by negating the empty), then it prints out the href if result is true.
<a class="btn btn-success" target="_blank" <?php if(!empty($row['proof'])): ?> href="<?php echo IMAGE_DIR . $row['proof']; ?>" <?php endif; ?> >Download</a>
Or maybe better: Check if variable is empty and give the user a hint that it's not available. I think this is the better solution, because then your users will know what's going on.
<?php if(empty($row['proof'])): ?>
<span>No proof available</span>
<?php else: ?>
<a class="btn btn-success" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>">
Download
</a>
<?php endif; ?>
<a
class="btn btn-success"
target="_blank"
<?php if(empty($row['proof'])) echo "disabled"; ?>
href="<?php if(!empty($row['proof'])) echo IMAGE_DIR . $row['proof']; ?>">
Download
</a>
try above code. and add disabled class using this condition
<?php
$state = (empty($row['proof'])) ? "disabled='disabled'" : "";
$class = (empty($row['proof'])) ? "disabled" : "";
?>
<a class="btn btn-success <?php echo $class; ?>" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>" <?php echo $state; ?>>Download</a>
To disabled the button, you need to use disabled HTML attribute. The code above checks $row['proof'] == NULL. If this statement is true it prints disabled = "disabled" in the button element and it isn't true, it prints nothing.
Assuming that you are using bootstrap, .disabled will grayed out the button.
I created this plugin for a Wordpress site, in the admin page i've insert a modal that can change a specific #color in css only if it's pressed the specific color button.
With the code below, i need to reload two times the admin page for see the change, so i think it's not the correct way to insert - update values displayed. This code it's placed on the same file where modal it's declare.
Please, can you show me the wordpress right way to update or insert data into database then show the change in admin page?
Thanks.
function recensility_system_action_color_fest($id , $title, $footer )
{
global $wpdb;
$colors = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'recensility_color_fest', ARRAY_A);
?>
<!-- The Modal -->
<div id="<?php echo $id; ?>" class="recensility-modal">
<!-- Modal content -->
<div id="<?php echo $id.'-insert'; ?>" class="recensility-modal-content">
<div class="recensility-modal-header">
<span id="<?php echo $id.'-close'; ?>" class="recensility-modal-close" onclick="close_modal('<?php echo $id; ?>')">×</span>
<h2 class="recensility-modal-title"><i class="fas fa-swatchbook"></i><?php echo $title; ?></h2>
</div>
<div class="recensility-modal-body">
<center>
<h2>Clicca sul colore da impostare</h2>
<div class="recensility-color-fest-chooser">
<form id="recensility-color-fest-form" method="post">
<div class="recensility-color-fest-chooser-body">
<div class="recensility-color-fest-chooser-items">
<?php
foreach ($colors as $color){
?>
<div class="dot-container <?php echo ($color['is_active']=='true') ? 'dot-active' : 'dot-inactive'; ?>">
<?php
echo
($color['is_active']=='true')
?
'<p class="dot-active-text">Attivo</p>'
:
'<button id="recensility-color-fest-form-submit" name="recensility-color-fest-form-submit" class="recensility-color-fest-form-button" value="'. $color['value'].'" type="submit" form="recensility-color-fest-form">';
?>
<span class="dot" style="background-color:<?php echo $color['value'] ?>"></span>
<?php echo ($color['is_active']=='false') ? '</button>' : ''; ?>
<p><?php echo $color['name'] ?></p>
</div>
<?php
}
?>
</div>
</div>
</form>
</div>
</center>
</div>
<div class="recensility-modal-footer">
<h3 class="recensility-modal-footer-content"><?php echo $footer; ?></h3>
</div>
<?php
print_r($_POST);
if (!empty($_POST['recensility-color-fest-form-submit'])){
$activeColor = ($wpdb->get_results('SELECT `value` FROM '.$wpdb->prefix.'recensility_color_fest'.' WHERE `is_active` = "true"', ARRAY_A)[0])['value'];
$wpdb->update
(
$wpdb->prefix.'recensility_color_fest',
array('is_active' => 'false'),
array('is_active' => 'true')
);
recensility_color_fest_apply($activeColor, $_POST['recensility-color-fest-form-submit']);
$wpdb->update
(
$wpdb->prefix.'recensility_color_fest',
array('is_active' => 'true'),
array('value' => $_POST['recensility-color-fest-form-submit'])
);
}
?>
</div>
</div>
<?php
}
I'm working with Magento EE v1.14 and i'm looking for a solution for when a user is viewing a product page to then drop swatches of related product colors if they are out of stock.
Screenshot: Highlighted out of stock related product color
Screenshot of HTML
PHP + HTML code:
<?php
$_base_product = $this->getProduct();
$base_product = Mage::getModel('catalog/product')->load($_base_product->getId());
$base_product_id = $base_product->getId();
$base_name = $base_product->getName();
$base_url = Mage::getBaseUrl();
$product_colors = Mage::getModel('catalog/product')->getCollection();
$product_colors->addAttributeToFilter('status',1); // 1 or 2
$product_colors->addAttributeToFilter('visibility',4); // 1.2.3.4
$product_colors->addAttributeToFilter('name', array('eq' => $base_name));
$product_colors->addAttributeToFilter('sku', array('neq' => $base_product->getSku()));
$product_colors_ids = $product_colors->getAllIds(); // get all products from the category
sort($product_colors_ids);
?>
<?php if(count($product_colors_ids) > 0) : ?>
<div id="product-color-options-wrapper">
<div id="product-color-options-container">
<label><?php echo $this->__('Color') ?> / <span style="font-weight: normal;"><?php echo $base_product->getAttributeText('color'); ?></span></label>
<div id="color-options-wrapper">
<?php $_swatch_img = $base_product->getMediaGalleryImages(false)->getItemByColumnValue('label', 'swatch') ?>
<?php if($_swatch_img) : ?>
<div class="current-product-wash-wrapper wash-wrapper">
<div class="current-product-wash-container wash-container">
<img src="<?php echo $this->helper('catalog/image')->init($base_product, 'small_image', $_swatch_img->getFile())->resize(33,30) ?>" alt="" title="<?php echo $base_product->getAttributeText('color') ?>" />
</div>
</div>
<?php else : ?>
<!-- <span><?php echo $base_product->getColor() ?></span> -->
<?php endif ?>
<?php foreach($product_colors_ids as $prod_id) : ?>
<?php $_sister_product = Mage::getModel('catalog/product')->load($prod_id) ?>
<?php
$_sister_prod_imgs = $_sister_product->getMediaGallery('images');
foreach($_sister_prod_imgs as $_sister_prod_img):
if($_sister_prod_img['label'] == 'swatch'):
$_swatch_img = $_sister_prod_img['file'];
endif;
endforeach;
?>
<?php if($_swatch_img): ?>
<div class="sister-product-wrapper wash-wrapper">
<div class="sister-product-container wash-container">
<a href="<?php echo $base_url ?><?php echo $_sister_product->getUrlKey() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_sister_product, 'small_image', $_swatch_img)->resize(33,30); ?>" alt="" title="<?php echo $_sister_product->getAttributeText('color') ?>">
</a>
</div>
</div>
<?php endif; ?>
<?php endforeach ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php endif ?>
Any help would be appreciated! :D
**Solution:**Added an if statement to check for stock availability using the isAvailable() function, shown in screenshot.
Link to screenshot: https://gyazo.com/abf07ba0373877836571858ee129cc22
//In PHP fetch content and truncate the string or variable, till 3rd breakline then display
//when i use this method the entire div deallocated and the its not displaying properly...hope the fetch content contain some image tags too // ...
<div class="mid-blks-cont">
<!-- Block1 -->
<div class="mid-block-1 boxgrid caption">
<?php
foreach ($querypost as $row) {
$content = $row->post_content;
$pcontent_overview = (strlen($content) > 300) ? substr($content,0,300).'... Read More' : $content;
if($img == "No Image Uploaded" ) {
?>
<img alt="" src="<?php echo base_url(); ?>assets/img/samples/sample1.jpg"style="width: 391px; height:231px"/>
<?php } else { ?>
<img alt="" src="<?php echo base_url(); ?>uploads/<?php echo $row->post_media ;?>" style="width: 391px; height:231px" />
<?php }?>
<h4 class="cat-label cat-label2"><?php echo $row->category;?></h4>
<div class="cover boxcaption">
<h3><?php echo $row->post_title;?><span class="topic-icn"><?php echo $row->comment_count;?></span></h3>
<p> <?php echo $pcontent_overview;?>....</p>
MORE <i class="fa fa-angle-double-right"></i>
</div>
<?php } ?>
</div>
</div>
this code out put is here....(look at the footer subscribe section )
<?php if(!empty($this->items))foreach($this->items as $level): ?>
<?php
$formatedPrice = sprintf('%1.02f',$level->price);
$dotpos = strpos($formatedPrice, '.');
$price_integer = substr($formatedPrice,0,$dotpos);
$price_fractional = substr($formatedPrice,$dotpos+1);
?>
<div class="level akeebasubs-level-<?php echo $level->akeebasubs_level_id ?>">
<p class="level-title">
<span class="level-price">
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'before'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
<span class="level-price-integer"><?php echo $price_integer ?></span><?php if((int)$price_fractional > 0): ?><span class="level-price-separator">.</span><span class="level-price-decimal"><?php echo $price_fractional ?></span><?php endif; ?>
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'after'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
</span>
<span class="level-title-text">
<a href="<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>">
<?php echo $this->escape($level->title)?>
</a>
</span>
</p>
<div class="level-inner">
<div class="level-description">
<div class="level-description-inner">
<?php if(!empty($level->image)):?>
<img class="level-image" src="<?php echo JURI::base()?><?php echo trim(AkeebasubsHelperCparams::getParam('imagedir','images/'),'/') ?>/<?php echo $level->image?>" />
<?php endif;?>
<?php echo JHTML::_('content.prepare', AkeebasubsHelperMessage::processLanguage($level->description));?>
</div>
</div>
<div class="level-clear"></div>
<div >
<button onclick="window.location='<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>'">
<?php echo JText::_('COM_AKEEBASUBS_LEVELS_SUBSCRIBE')?>
</button>
</div>
</div>
</div>
<?php endforeach; ?>
this is the language file contain that name
COM_AKEEBASUBS_LEVELS_SUBSCRIBE="Subscribe Now"
I want to name those three sections butons as 6month,12month,24month
How will change the code ?
If you are unable to get the value using PHP, try changing the value of the button's name on page load
Here is the JQUERY
$(document).ready(function){
$('div.akeebasubs-awesome-description').each(function(
substription = $(this).children('H4').html()
button = $(this).parent().next().children('button')
$(button).attr(name,substription.split(' ')[0]+'month')
})
})
and the JAVASCRIPT
divs = document.getElementsByClassName('akeebasubs-awesome-description');
for (var i in divs){
divs[i].parentElement.nextElementSibling.children[0].name = divs[i].children[0].innerHTML.split(' ')[0] + 'month'
}
This will take the text of the H4 and make that the corresponding button's name