Overwriting PHP if statement - php

My company is working on a CRM with the Wordpress plugin CQPIM.
There are two issues with it, but I'll just address one, for now.
The plugin functions off of User Roles, and will show ALL the active projects for anyone with the capability: cqpim_view_all_projects.
We need to rewrite the following snippet so that the dashboard only shows the projects assigned to the current user.
original code: there are no hooks to filters to modify
if(current_user_can('cqpim_view_all_projects')) {
$index++; ?>
<li>
<script>
jQuery(document).ready(function() {
jQuery("#progressbar-<?php echo $project->ID; ?>").progressbar({
value: <?php echo number_format((float)$pc_complete, 2, '.', ''); ?>
});
});
</script>
<div class="title">
<?php if(!empty($project->post_title)) { echo $project->post_title; } else { _e('Untitled', 'cqpim'); } ?>
<?php echo $project_status; ?>
</div>
<div class="progress">
<div id="progressbar-<?php echo $project->ID; ?>"></div>
</div>
<ul class="project_stats">
<li><span class="project_stat_head"><?php _e('Open Tasks' , 'cqpim') ?></span><span class="project_stat"><?php echo $task_count; ?></span></li>
<li><span class="project_stat_head"><?php _e('Complete' , 'cqpim') ?></span><span class="project_stat"><?php echo number_format((float)$pc_complete, 2, '.', ''); ?>%</span></li>
<li><span class="project_stat_head"><?php _e('Deadline' , 'cqpim') ?></span><span class="project_stat"><?php echo $finish_date; ?></span></li>
</ul>
</li>
<?php
} else {
$access = false;
$project_contributors = get_post_meta($project->ID, 'project_contributors', true);
if(empty($project_contributors)) {
$project_contributors = array();
}
foreach($project_contributors as $contributor) {
if(!empty($contributor['team_id']) && $assigned == $contributor['team_id']) {
$access = true;
}
}
if($access == true) {
$index++; ?>
<li>
<script>
jQuery(document).ready(function() {
jQuery("#progressbar-<?php echo $project->ID; ?>").progressbar({
value: <?php echo number_format((float)$pc_complete, 2, '.', ''); ?>
});
});
</script>
<div class="title">
<?php if(!empty($project->post_title)) { echo $project->post_title; } else { _e('Untitled', 'cqpim'); } ?>
<?php echo $project_status; ?>
</div>
<div class="progress">
<div id="progressbar-<?php echo $project->ID; ?>"></div>
</div>
<ul class="project_stats">
<li><span class="project_stat_head"><?php _e('Open Tasks', 'cqpim'); ?></span><span class="project_stat"><?php echo $task_count; ?></span></li>
<li><span class="project_stat_head"><?php _e('Complete' , 'cqpim') ?></span><span class="project_stat"><?php echo number_format((float)$pc_complete, 2, '.', ''); ?>%</span></li>
<li><span class="project_stat_head"><?php _e('Deadline' , 'cqpim') ?></span><span class="project_stat"><?php echo $finish_date; ?></span></li>
</ul>
</li>
<?php
}
}
My modified code: it works when in the plugin root, but I would like to update this plugin at some point without losing all my files, so need a way to overwrite the original IF statement
if(current_user_can('cqpim_view_all_projects')) {
$index++;
$access = false;
$project_contributors = get_post_meta($project->ID, 'project_contributors', true);
if(empty($project_contributors)) {
$project_contributors = array();
}
foreach($project_contributors as $contributor) {
if(!empty($contributor['team_id']) && $assigned == $contributor['team_id']) {
$access = true;
}
}
if($access == true) {
$index++; ?>
<li>
<script>
jQuery(document).ready(function() {
jQuery("#progressbar-<?php echo $project->ID; ?>").progressbar({
value: <?php echo number_format((float)$pc_complete, 2, '.', ''); ?>
});
});
</script>
<div class="title">
<?php if(!empty($project->post_title)) { echo $project->post_title; } else { _e('Untitled', 'cqpim'); } ?>
<?php echo $project_status; ?>
</div>
<div class="progress">
<div id="progressbar-<?php echo $project->ID; ?>"></div>
</div>
<ul class="project_stats">
<li><span class="project_stat_head"><?php _e('Open Tasks', 'cqpim'); ?></span><span class="project_stat"><?php echo $task_count; ?></span></li>
<li><span class="project_stat_head"><?php _e('Complete' , 'cqpim') ?></span><span class="project_stat"><?php echo number_format((float)$pc_complete, 2, '.', ''); ?>%</span></li>
<li><span class="project_stat_head"><?php _e('Deadline' , 'cqpim') ?></span><span class="project_stat"><?php echo $finish_date; ?></span></li>
</ul>
</li>
<?php
}
}

If hooks or actions are not available for this plugin, check if the plugin makes use of the function get_template_part/locate_template or something like it. An example is woocommerce, which uses both actions/filters and locate_template so you can either hook into it or overwrite the templates in the theme folder.
Have you tried asking the developer? The plugin is paid, so it would make sense you have some kind of support there. Ask them to include hooks or the ability to overrule templates in your own theme.

Related

How to split Contao variable into several HTML Elements

I´ve got this template from my Contao CMS:
<?php $helper = new \ContaoBootstrap\Navbar\Helper\NavigationHelper($this); ?>
<?php foreach ($this->items as $item) : ?>
<?php
$currentLevelStringParts = explode('_', $this->level);
$currentLevelNumber = $currentLevelStringParts[1];
?>
<?php $itemHelper = $helper->getItemHelper($item); ?>
<li class="<?php echo str_replace(array('_'), array('-'), $itemHelper->getItemClass());
if (!empty($item['subitems'])) {echo ' subnav';} ?>
">
<<?= str_replace(array('strong'), array('a'), $itemHelper->getTag()); ?>
<?= str_replace(array('dropdown-item', 'dropdown-toggle', 'nav-link', 'data-toggle="dropdown"'), array(' ', ' ', ' ', ' '), $itemHelper) ?>>
<?php if ($item['isActive']) : ?>
<?= $item['link']?>
<?php else : ?>
<span itemprop="name"><?= $item['link']?></span>
<?php endif; ?>
</<?= str_replace(array('strong'), array('a'), $itemHelper->getTag()); ?>>
<?php if (!empty($item['subitems'])) { ?>
<span class="subnav-pull-down hidden-lg-up <?php if ($item['isTrail']) : ?>active<?php endif; ?>"></span>
<div class="subnav-container <?php if ($item['isTrail']) : ?>open<?php endif; ?>">
<div class="relative">
<ul class="nav sub-nav level-<?php echo (int)$currentLevelNumber+1 ?>">
<?= $item['subitems'] ?>
<div class="clear"></div>
</ul>
</div>
</div>
<?php } ?>
</li>
<?php endforeach; ?>
My problem is, I need a HTML structure like:
<ul>
<li><a></a></li>
<li><a></a></li>
<li>
<ul>
<li><a></a></li>
</ul>
</ul>
To change link () and description for my navigation. I tried to work the the bootstrap API but I´m kind of new to PHP and Bootstrap.
I hope you guys can help me.

Pagination on Wp-Property not working

I have a Wordpress site that is using Wp-Property and the pagination isn't working, can anyone help fix this please. Please see below the pagination part from the function page.
<?php if($use_pagination) { ?>
if(!wpp_pagination_<?php echo $unique_hash; ?>) {
jQuery("#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider_wrapper").each(function() {
var this_parent = this;
/* Slider */
jQuery('.wpp_pagination_slider', this).slider({
value:1,
min: 1,
max: <?php echo $pages; ?>,
step: 1,
slide: function( event, ui ) {
/* Update page counter - we do it here because we want it to be instant */
jQuery("#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_current_page_count").text(ui.value);
jQuery("#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider .slider_page_info .val").text(ui.value);
},
stop: function(event, ui) {
wpp_query_<?php echo $unique_hash; ?> = changeAddressValue(ui.value, wpp_query_<?php echo $unique_hash; ?>);
}
});
/* Fix slider width based on button width */
var slider_width = (jQuery(this_parent).width() - jQuery(".wpp_pagination_back", this_parent).outerWidth() - jQuery(".wpp_pagination_forward", this_parent).outerWidth() - 30);
jQuery(".wpp_pagination_slider", this_parent).css('width', slider_width);
jQuery('.wpp_pagination_slider .ui-slider-handle', this).append('<div class="slider_page_info"><div class="val">1</div><div class="arrow"></div></div>');
});
wpp_pagination_<?php echo $unique_hash; ?> = true;
}
<?php } ?>
});
</script>
<?php
$js_result = ob_get_contents();
ob_end_clean();
ob_start(); ?>
<div class="properties_pagination <?php echo $settings['class']; ?> wpp_slider_pagination" id="properties_pagination_<?php echo $unique_hash; ?>">
<div class="wpp_pagination_slider_status">
<?php
if(function_exists('WPPFL_getNumberOfFavorites')) {
$num_of_favorites = WPPFL_getNumberOfFavorites();
} else{
$num_of_favorites = 0;
}
$currentTemplate = "";
if (isset($wpp_query['template'])) {
$currentTemplate = $wpp_query['template'];
}
?>
<?php if ($currentTemplate==TEMPLATEPATH . "/list-my-property-content.php") { ?>
<div class="wppcs-sub-menu">
<?php global $post;
$post_name = $post->post_name; ?>
<?php $class='class="active"'; ?>
<ul>
<li <?php if($post_name == 'list-my-property') { echo $class; } ?>>
<a href="<?php echo get_bloginfo('url'); ?>/list-my-property/">
View Listed Properties
</a>
</li>
<li <?php if($post_name == 'add-new-property') { echo $class; } ?>>
<a href="<?php echo get_bloginfo('url'); ?>/list-my-property/add-new-property/">
Add New Property
</a>
</li>
</ul>
</div>
<?php } else { ?>
<ul class="top_part">
<li><a>Search results</a></li>
<li class="favor">My Favourites(<span class="number_of_favorites"><?php echo $num_of_favorites; ?></span>)</li>
</ul>
<?php } ?>
<div class="clear"></div>
</div>
<?php if($use_pagination) { ?>
<div class="wpp_pagination_slider_wrapper">
<div class="wpp_page_numbers_block">
<span class="numbers-title">Pages</span>
<?php
if ($pages < 10) {
for($i=1; $i<=$pages; $i++) {
echo '<span class="page_numbers" data-value="'.$i.'">'.$i.'</span>';
}
} else {
for($i=1; $i<=$pages; $i++) {
if (($i < 4) || ($i>$pages-3)) {
echo '<span class="page_numbers" data-value="'.$i.'">'.$i.'</span>';
}
if ($i==4) {
echo '<span class="middle-pages"><span class="dotted-separator">...</span></span>';
}
}
}?>
</div>
<div class="wpp_pagination_back wpp_pagination_button"><?php _e('Prev', 'wpp'); ?></div>
<div class="wpp_pagination_forward wpp_pagination_button"><?php _e('Next', 'wpp'); ?></div>
<div class="wpp_pagination_slider"></div>
</div>
<?php } ?>
</div>
<div class="ajax_loader"></div>
<?php
$html_result = ob_get_contents();
ob_end_clean();
Thank you in anticaption.
The first thing which can cause your issue is some of third party plugins or your theme. So try firstly to deactivate third party plugins and switch theme to default one to be sure that issue doesn't relate to any of them.
Such request you can also send here
https://wordpress.org/support/plugin/wp-property
or on our site
https://usabilitydynamics.com/contact-us/
Regards.
Usability Dynamics Support

Magento - How to show realted products block in my product page?

I have this and i think this is a code for block which displays releated products for the product in the product page here it is.
/template/catalog/product/list/releated_products.phtml :
<?php if($this->getItems()->getSize()): ?>
<div class="related-products">
<h2><?php echo $this->__('Related Products') ?></h2>
<ol class="products-grid row" id="block-related">
<?php foreach($this->getItems() as $_item): ?>
<li class="item span3">
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
<?php endif; ?>
<div class="product"> <img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(590,714) ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" />
<div class="product-details">
<p class="product-name"><?php echo $this->htmlEscape($_item->getName()) ?></p>
<?php echo $this->getPriceHtml($_item, true, '-related') ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<?php echo $this->__('Add to Wishlist') ?>
<?php endif; ?>
</div>
</div>
</li>
<?php endforeach ?>
</ol>
<script type="text/javascript">decorateList('block-related', 'none-recursive')</script>
<script type="text/javascript">
//<![CDATA[
$$('.related-checkbox').each(function(elem){
Event.observe(elem, 'click', addRelatedToProduct)
});
var relatedProductsCheckFlag = false;
function selectAllRelated(txt){
if (relatedProductsCheckFlag == false) {
$$('.related-checkbox').each(function(elem){
elem.checked = true;
});
relatedProductsCheckFlag = true;
txt.innerHTML="<?php echo $this->__('unselect all') ?>";
} else {
$$('.related-checkbox').each(function(elem){
elem.checked = false;
});
relatedProductsCheckFlag = false;
txt.innerHTML="<?php echo $this->__('select all') ?>";
}
addRelatedToProduct();
}
function addRelatedToProduct(){
var checkboxes = $$('.related-checkbox');
var values = [];
for(var i=0;i<checkboxes.length;i++){
if(checkboxes[i].checked) values.push(checkboxes[i].value);
}
if($('related-products-field')){
$('related-products-field').value = values.join(',');
}
}
//]]>
</script>
</div>
<?php endif ?>
So how i can display this block in my view.phtml which display the info for the product view page. I want to paste it bellow the product description.
Thanks in advance!
Try this https://magento.stackexchange.com/questions/3177/showing-related-products-in-product-view-page
Make sure your current product has related product.

menu by default should hidden

Hey guys i want the sensor to be hidden by default and it show when i click on the particular node..and should be the same on page reload
Here is my code
<ul >
<?php if(isset($nodes)): ?>
<?php $count = 0; ?>
<?php foreach($nodes as $node) { ?>
<?php $node_id=$node['node_id']; ?>
<?php $sensors = config_sensor_model::getsensors($node_id); ?>
<?php $count++; ?>
<li onclick="menu(<?php echo $count; ?>)"><?php echo $node['node_name']; ?> </li>
<ul id="<?php echo "sub_".$count; ?>">
<?php foreach($sensors as $sensorlog) { ?>
<li> <?php echo $sensorlog->sensor_name; ?></li>
<?php } ?>
</ul>
<?php } ?>
<?php endif; ?>
</ul>
</div>
this is the javascript presently i am using
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
function menu(count)
{
$("#sub_"+count).toggle("fast");
}
</script>
As mentioned in my comment just use CSS to hide the node initially like this:
<style type="text/css">
.hidden { display: none; }
</style>
<ul>
if(isset($nodes)):
$count = 0;
foreach($nodes as $node) {
$node_id = $node['node_id'];
$sensors = config_sensor_model::getsensors($node_id);
$count++;
?>
<li onclick="menu(<?php echo $count; ?>)"><?php echo $node['node_name']; ?> </li>
<ul id="<?php echo "sub_".$count; ?>" class="hidden">
<?php foreach($sensors as $sensorlog) { ?>
<li> <?php echo $sensorlog->sensor_name; ?></li>
<?php } ?>
</ul>
<?php }
endif; ?>
</ul>
</div>
When menu is clicked, the display value will be toggled by Javascript.
Set style='display:none' for the <ul>

CSS Dropdown menu through PHP, logic defeats me

My brain doesn't seem to want to work this morning.. i have the following array:
private $nav_pages = [['0', 'Home', 'home'],
['0', 'About Us', 'about'],
['0', 'Our Services', 'services'],
['1', 'PROCURE TO PAY (P2P)', 'procure'],
['1', 'ORDER TO CASH (02C)', 'cash'],
['1', 'GENERAL ACCOUNTING', 'general'],
['2', 'Charting of Accounts', 'charting'],
['2', 'General Ledger Maintenance', 'maintenance'],
['2', 'Accounts Receivable Services', 'receivable'],
['2', 'Accounts Payable Services', 'payable'],
['2', 'Reconciliation of Bank Accounts and Credit Cards', 'reconciliation'],
['2', 'Preparing Financial Statements', 'statements'],
['2', 'Payroll Processing', 'payroll'],
['1', 'CLOSING & REPORTING', 'closing'],
['0', 'How It Works', 'how-it-works'],
['0', 'Contact Us','contact'],
['0', 'Careers', 'careers']];
This is then fed to a php page which is meant to lay out a multi-layered pure css drop down menu.. the php page code is:
<ul class="<?php echo $ul_class; ?>">
<?php $this_layer = 0;
// place array content into variables
foreach ($links as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
if ($item_layer > $this_layer) { ?>
<ul>
<?php $this_layer++; }
elseif ($item_layer == $this_layer) { ?>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
</li>
<?php }
elseif ($item_layer < $this_layer) { ?>
</li></ul>
<?php $this_layer--; } ?>
<?php } ?>
The output is not correct however as the above code always closes the list item containing the second layer before the second layer is ready to be closed. if that makes sense..
<ul class="pages_nav">
<li class="home">
<a class="home"
href="/home">
Home
</a>
</li>
<li class="about">
<a class="about"
href="/about">
About Us
</a>
</li>
<li class="services">
<a class="services"
href="/services">
Our Services
</a>
</li>
<ul>
<li class="cash">
<a class="cash"
href="/cash">
ORDER TO CASH (02C)
</a>
</li>
<li class="general">
<a class="general"
href="/general">
GENERAL ACCOUNTING
</a>
</li>
<ul>
<li class="maintenance">
<a class="maintenance"
href="/maintenance">
General Ledger Maintenance
</a>
</li>
<li class="receivable">
<a class="receivable"
href="/receivable">
Accounts Receivable Services
</a>
</li>
<li class="payable">
<a class="payable"
href="/payable">
Accounts Payable Services
</a>
</li>
<li class="reconciliation">
<a class="reconciliation"
href="/reconciliation">
Reconciliation of Bank Accounts and Credit Cards
</a>
</li>
<li class="statements">
<a class="statements"
href="/statements">
Preparing Financial Statements
</a>
</li>
<li class="payroll">
<a class="payroll"
href="/payroll">
Payroll Processing
</a>
</li>
</li></ul>
</li></ul>
<li class="contact">
<a class="contact"
href="/contact">
Contact Us
</a>
</li>
<li class="careers">
<a class="careers"
href="/careers">
Careers
</a>
</li>
SOLUTION:
<ul class="<?php echo $ul_class; ?>">
<?php $this_layer = 0;
// place array content into variables
foreach ($links as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
// check if link needs to be manipulated
switch($do) {
case 'strtolower':
$item_string = strtolower($item_string);
break;
case 'strtoupper':
$item_string = strtoupper($item_string);
break;
} ?>
<?php if ($item_layer > $this_layer) { ?>
<ul>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php $this_layer++; }
elseif ($item_layer == $this_layer) { ?>
</li><li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php }
elseif ($item_layer < $this_layer) { ?>
</li></ul></li><li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php $this_layer--; } ?>
<?php } ?>
Never close the the li tag, close it when you add something
foreach ($links as $link) {
if ($item_layer > $this_layer) {
echo '<ul><li> ......';
this_layer++;
}elseif ($item_layer == $this_layer) {
echo '</li><li>......';
}elseif ($item_layer < $this_layer) {
echo '</li></ul><li>......';
$this_layer--;
}
}
Last you probably need to add a echo '</li></ul>' outside of the foreach to close everything
Had to rework the code a little, usually i organize the php menu structure in tree form makes it easier to parse into html menus, but here it is:
<ul class="<?php echo $ul_class; ?>">
<?php
$this_layer = 0;
$closeit = false;
// place array content into variables
foreach ($nav_pages as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
if ($item_layer > $this_layer) {
// Changing level, dont close the previous li
?><ul><?php
$closeit = false;
$this_layer++;
}
if ($item_layer == $this_layer) {
// Same level, check if you need to close previous li
if ($closeit) {
?></li><?php
}
// Render the li
?>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php
// Close it on next loop
$closeit = true;
}
elseif ($item_layer < $this_layer) {
// Changing layer back down, close the previous li and the current level ul
?>
</li>
</ul>
<?php
$this_layer--;
}
}
// Finished loop, there should still be a li waiting to be closed
if ($closeit) {
?></li><?php
}
// Close menu
?>
</ul>
Should be working, let me know if it isnt
Suggested php menu structure:
$menu = array(
array(
"url"=>"/place.php",
"text"=>"Go to place"
),
array(
"url"=>"/place2.php", // not necessary
"text"=>"with submenu",
"children"=>array(
array(
"url"=>"/placewithinplace2.php",
"text"=>"submenu item"
)
)
)
);

Categories