I am having problem with calling a function from another plugin it seems to return nothing tho this does work on other plugin
function caller_func()
{
if (!function_exists('form')) return;
return form($number = null);
}
function chrp1_get_popup(){
$chrp1_popup = '<div id="fullscre"></div>';
$chrp1__query= "post_type=popup-widget-details&showposts=1";
query_posts($chrp1__query);
if (have_posts()) : the_post();
$chrp1_mykey_values = get_post_custom_values('code');
$chrp1_descrip = get_the_content();
$chrp1_popup .= '<span onclick="chrp1_showall();">'.$chrp1_descrip.'</span>';
$chrp1_popup .= '<div id="newsox">';
$chrp1_popup .= '<img src="'.chrp1_PATH.'image/cross.png" class="ccross"
onclick="chrp1_getrid();" width="23"/>';
$getfunc = 'caller_func';
$chrp1_popup .= $getfunc();
$chrp1_popup .= '</div>';
endif; wp_reset_query();
return $chrp1_popup;
}
this code works on my other plugins I want to call but not this one below can anybody help
function form($number = null) {
if ($number == null)
return $this->subscription_form();
$options = get_option('newsletter_forms');
$form = $options['form_' . $number];
if (stripos($form, '<form') !== false) {
$form = str_replace('{newsletter_url}', plugins_url('newsletter/do/subscribe.php'), $form);
} else {
$form = '<form method="post" action="' . plugins_url('newsletter/do/subscribe.php') . '" onsubmit="return newsletter_check(this)">' .
$form . '</form>';
}
$form = $this->replace_lists($form);
return $form;
}
when I check the source code nothing from the form has loaded
Related
I am trying to make some information widget for the console on client sites (wordpress). The code below works as I need it, perfectly.
$url = 'https://example.site/wp-json/';
function _dashboard_clients_info()
{
global $url;
$request = wp_remote_get(esc_url_raw($url));
if (is_wp_error($request)) {
return false;
}
$html = wp_remote_retrieve_body($request);
$data = json_decode($html);
$head = current(array_filter($data, function ($current) {
return $current->_ID == 2;
}));
$posts = $data;
$foot = current(array_filter($data, function ($current) {
return $current->_ID == 3;
}));
$exclude = array(1, 2, 3, 4);
if (!empty($head->dash_description)) {
echo wpautop('<div class="dash_head">' . $head->dash_description . '</div>');
echo $head->html_css_js;
} else {
};
foreach ($posts as $post) {
if (!in_array($post->_ID, $exclude)) {
if (!empty($posts)) {
echo '<div class="dash_post">';
echo '<h3 class="dash_title">' . $post->dash_title . '</h3>';
echo wpautop('<div class="dash_description">' . $post->dash_description . '</div>');
echo $post->html_css_js;
echo '</div>';
}
} else {
};
}
if (!empty($foot->dash_description)) {
echo wpautop('<div class="dash_foot">' . $foot->dash_description . '</div>');
echo $foot->html_css_js;
} else {
};
}
function _add_dashboard_clients_widget()
{
global $url;
$request = wp_remote_get(esc_url_raw($url));
if (is_wp_error($request)) {
return false;
}
$html = wp_remote_retrieve_body($request);
$data = json_decode($html);
$title = current(array_filter($data, function ($current) {
return $current->_ID == 1;
}));
if (!empty($title->dash_description)) {
$title = '<div class="dash_title">' . $title->dash_description . '</div>';
} else {
};
add_meta_box('dashboard-clients-info', '' . $title . '', '_dashboard_clients_info', $screen, 'normal', 'high');
}
add_action('wp_dashboard_setup', '_add_dashboard_clients_widget');
But I understand that it is not perfect. In particular, I have to include $url twice to get the widget title and body.
I would like to make the $data variable global in order to get the $url once, and then take what me need. I tried it like this, but for some reason it doesn't work, it doesn't return anything.
$url = 'https://example.site/wp-json/';
$request = wp_remote_get(esc_url_raw($url));
if (is_wp_error($request)) {
return false;
}
$html = wp_remote_retrieve_body($request);
$data = json_decode($html);
function _dashboard_clients_info()
{
global $data;
$head = current(array_filter($data, function ($current) {
return $current->_ID == 2;
}));
$posts = $data;
$foot = current(array_filter($data, function ($current) {
return $current->_ID == 3;
}));
$exclude = array(1, 2, 3, 4);
if (!empty($head->dash_description)) {
echo wpautop('<div class="dash_head">' . $head->dash_description . '</div>');
echo $head->html_css_js;
} else {
};
foreach ($posts as $post) {
if (!in_array($post->_ID, $exclude)) {
if (!empty($posts)) {
echo '<div class="dash_post">';
echo '<h3 class="dash_title">' . $post->dash_title . '</h3>';
echo wpautop('<div class="dash_description">' . $post->dash_description . '</div>');
echo $post->html_css_js;
echo '</div>';
}
} else {
};
}
if (!empty($foot->dash_description)) {
echo wpautop('<div class="dash_foot">' . $foot->dash_description . '</div>');
echo $foot->html_css_js;
} else {
};
}
function _add_dashboard_clients_widget()
{
global $data;
$title = current(array_filter($data, function ($current) {
return $current->_ID == 1;
}));
if (!empty($title->dash_description)) {
$title = '<div class="dash_title">' . $title->dash_description . '</div>';
} else {
};
add_meta_box('dashboard-clients-info', 'test', '_dashboard_clients_info', $screen, 'normal', 'high');
}
add_action('wp_dashboard_setup', '_add_dashboard_clients_widget');
I will be grateful for any help in improving this. I'm just learning, I try to get knowledge in this way)))
You can easily define your API URL in wp-config.php, in the theme's functions.php or in a plugin's 'root' file (my-plugin.php for ex.):
define( 'DASHBOARD_API_URL', 'https://example.site/wp-json/' );
Then, create a method to receive the dashboard data making use of the defined DASHBOARD_API_URL:
function wp68412621_get_dashboard_data() {
$response = wp_remote_get( DASHBOARD_API_URL );
if ( is_wp_error( $response ) ) {
return false;
}
return wp_remote_retrieve_body( $response );
}
You should make use of transients to cache the API response in order to avoid excessive API calls. Let's adjust the previous method to:
function wp68412621_get_dashboard_data() {
$transient_key = 'dashboard_data';
$dashboard_data = get_transient( $transient_key );
if ( false === $dashboard_data ) {
$response = wp_remote_get( DASHBOARD_API_URL );
if ( is_wp_error( $response ) ) {
return false;
}
$dashboard_data = wp_remote_retrieve_body( $response );
set_transient( $transientKey, $dashboard_data, 900 );
}
return $dashboard_data;
}
Then, you can call the data method from any other method:
function wp68412621_dashboard_clients_info()
{
$data = wp68412621_get_dashboard_data();
if ( empty( $data ) ) {
return false;
}
// ...
}
function wp68412621_add_dashboard_clients_widget()
{
$data = wp68412621_get_dashboard_data();
if ( empty( $data ) ) {
return false;
}
// ...
}
add_action( 'wp_dashboard_setup', 'wp68412621_add_dashboard_clients_widget' );
This flash message helper is from traversymvc: a custom open-source php mvc.
My question is: is it necessary to check if ($_SESSION[$name]) is not empty on line 6(3rd if) when we've already made sure that it is not empty from the if condition before it.
Thanks.
<?php
session_start();
function flash($name = '', $message = '', $class = 'alert alert-success') {
if (!empty($name)) {
if (!empty($message) && empty($_SESSION[$name])) {
if (!empty($_SESSION[$name])) {
unset($_SESSION[$name]);
}
if (!empty($_SESSION[$name . '_class'])) {
unset($_SESSION[$name . '_class']);
}
$_SESSION[$name] = $message;
$_SESSION[$name . '_class'] = $class;
} elseif (empty($message) && !empty($_SESSION[$name])) {
$class = !empty($_SESSION[$name . '_class']) ? $_SESSION[$name . '_class'] : '';
echo '<div class= "' . $class . '" id="msg-flash">' . $_SESSION[$name] . '</div>';
unset($_SESSION[$name]);
unset($_SESSION[$name . '_class']);
}
}
}
I've inherited code from an old developer that was commented out and I've re-implemented it. A problem I've encountered is that the second item I'm putting in is registering the value as NULL.
The first two snippets of code are what I'm guessing is causing the issue for adding NULL for every second item being inserted into the database.
I have these three functions in the user model:
public function getDynamicVaribles() {
$string = null;
foreach ($this->userVariables as $var) {
$string .= $var->userTypeVariables->name . '=' . $var->value . "<br />";
}
return $string;
}
public function getDynamicVaribleValue($varName) {
foreach ($this->userVariables as $var) {
if ($var->userTypeVariables->name == $varName) {
return $var->value;
}
}
return null;
}
public function getDynamicVarible($varName) {
foreach ($this->userVariables as $userVariable) {
if ($userVariable->userTypeVariables->name == $varName) {
return $userVariable;
}
}
return null;
}
And I'm calling it like so in the _form view:
<?php
$varform = new DynamicForm();
$varform->attributes = $user->getDynamicFormConfig();
$varform->model_name = 'user';
echo $varform->run();
?>
And the function calling it in the my controller
foreach ($user->type->userTypeVariables as $userTypeVar) {
// Get fields for slide_varibles
// load Model here...
$slide_varible = $user->getDynamicVarible($userTypeVar->name);
// if ($slide_varible == null) {
// $slide_varible = new UserVariables;
// }
$slide_varible = new UserVariables;
$slide_varible->user_id = $user->id;
$slide_varible->value =
$_POST['user' . '_' . str_replace(' ', '_', $userTypeVar->name)];
$slide_varible->user_type_variables_id = $userTypeVar->id;
$slide_varible->save(false);
}
My attributes in the components (can probably be ignored):
foreach ($this->attributes as $attr) {
$attr['formname'] = $this->model_name . '_' . $attr['name'];
$attr['htmlOptions'] =
array('class' => 'span5', 'placeholder' => $attr['name']);
$attr['htmlOptions']['class'] .= ' form-control';
if ($attr['required'] === 1){
$attr['requiredfields'] = array('required' => true);
}else{
$attr['requiredfields'] = '';
}
// Per type input
// 'type'=>'text|radio|textarea|select'
if ($attr['type'] == 'text') {
echo '<div class="form-group">';
echo CHtml::label($attr['name'], $attr['formname'],
$attr['requiredfields']);
echo CHtml::textField($attr['formname'], $attr['value'],
$attr['htmlOptions']);
echo '</div>';
}
elseif ($attr['type'] == 'radio') {
echo '<div class="form-group">';
echo CHtml::label($attr['name'], $attr['formname'],
$attr['requiredfields']);
echo CHtml::radioButton($attr['formname'],
$attr['requiredfields']);
echo '</div>';
}
elseif ($attr['type'] == 'textarea') {
echo '<div class="form-group">';
echo CHtml::label($attr['name'], $attr['formname'],
$attr['requiredfields']);
echo CHtml::textArea($attr['formname'], $attr['value'],
$attr['htmlOptions']);
echo '</div>';
}
elseif ($attr['type'] == 'select') {
$items = explode(',', $attr['options']);
echo '<div class="form-group">';
echo CHtml::label($attr['name'], $attr['formname'],
$attr['requiredfields']);
echo CHtml::dropDownList($attr['formname'], $attr['value'],
array($items));
echo '</div>';
}
elseif ($attr['type'] == 'boolean') {
echo '<div class="form-group">';
echo CHtml::label($attr['name'], $attr['formname'],
$attr['requiredfields']);
echo CHtml::radioButtonList($attr['formname'], $attr['value'],
array('No' => 0, 'Yes' => 1));
echo '</div>';
}
}
The issue that I've encountered is that regardless of the dynamic form field type / or the input being put into this form, it's just adding NULL to the value field.
EDIT. The reason why the value was not being inserted is due to the full stop character "." was causing the database entry to go in as NULL.
After some testing and pure luck, I found out that the reason why the value was not posting to the database and resulting in a NULL Value, was the full stop character ".". Every other character I've tested results in the correct insert to the database.
As of posting I've not done any looking into why this is happening, but will update post if successful.
I have Magento 1.9.1 and I installed an extension that automatically add product to cart with ajax, after the product was successfully added to cart this extension display a notification: Your product "NAME" was added to cart. I want to change this notification with entire product details, like product image, sku, name, description ... Can anyone tell me where to start? My notification function look like this:
function notifyBar(msg) {
jQuery('.notification').show('fast');
jQuery('.notification').html("<div id='note'>"+msg+"</div>");
setTimeout(function(){
jQuery(".notification").hide('slow');
},1500);
}
I will add here the entire Observer.php code:
public function addToCartEvent($observer)
{
$request = Mage::app()->getFrontController()->getRequest();
if (!$request->getParam('in_cart') && !$request->getParam('is_checkout'))
{
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
$quote = Mage::getSingleton('checkout/cart')->getQuote();
$grandTotal = $quote->getGrandTotal();
$subTotal = $quote->getSubtotal();
$session = Mage::getSingleton('checkout/session');
$shippingTaxamount = Mage::helper('checkout')->getQuote()->getShippingAddress()->getData('tax_amount');
// get coupon discounted value
$totals = $quote->getTotals(); //Total object
if (isset($totals['discount']) && $totals['discount']->getValue())
{
$discount = Mage::helper('core')->currency($totals['discount']->getValue()); //Discount value if applied
}
else
{
$discount = '';
}
//get discount value end
$xitems = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
$max = 0;
$lastItem = null;
foreach ($xitems as $xitem)
{
if ($xitem->getId() > $max)
{
$max = $xitem->getId();
$lastItem = $xitem;
$attributeSetModel1 = Mage::getModel("eav/entity_attribute_set")->load($lastItem->getProduct()->getAttributeSetId());
$attributeSetName1 = $attributeSetModel1->getAttributeSetName();
$parentIds1 = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($lastItem->getProduct()->getId());
if ($lastItem->getProduct()->getTypeId() == 'simple' && empty($parentIds1) && $attributeSetName1 == 'Default')
{
$child = $lastItem;
}
else
{
$child = $lastItem->getOptionByCode('simple_product')->getProduct();
}
}
}
$html = '';
$productser = '';
foreach ($session->getQuote()->getAllVisibleItems() as $item)
{
if ($lastItem)
{
$xproduct = $lastItem->getProduct();
$xproductsku = $xproduct->getSku();
$xproductname = $xproduct->getName();
$xproductqty = $xproduct->getQty();
$xproductprice = $xproduct->getPrice();
$xproducturl = $xproduct->getUrl();
}
$productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
if ($productOptions)
{
if (isset($productOptions['options']))
{
foreach ($productOptions['options'] as $_option)
{
$productser = $_option['option_id'] . ',' . $_option['option_value'];
}
}
$superAttrString = '';
if (isset($productOptions['info_buyRequest']['super_attribute']))
{
foreach ($productOptions['info_buyRequest']['super_attribute'] as $key => $_superAttr)
{
$attr = Mage::getModel('catalog/resource_eav_attribute')->load($key);
$label = $attr->getSource()->getOptionText($_superAttr);
$superAttrString .= '<dt> ' . $attr->getAttributeCode() . ' </dt> <dd> ' . $label . ' </dd>';
}
}
if ($superAttrString):
$superAttrString . '&qty=1';
endif;
}
$productid = $item->getId();
$html .='<li id="li-' . $productid . '">';
$product_id = $item->getProduct()->getId();
$productsku = $item->getSku();
$productname = $item->getName();
$productqty = $item->getQty();
$_product = Mage::getModel('catalog/product')->load($product_id);
$url = Mage::getUrl(
'checkout/cart/deleteqty', array(
'id' => $productid,
Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core/url')->getEncodedUrl()
)
);
$count = $quote->getItemsCount();
$html .='<div class="item-thumbnail">';
if ($item->hasProductUrl()):
$html .='<img src="' . Mage::helper('catalog/image')->init($item->getProduct(), 'thumbnail') . '" width="50" height="50" alt="' . $this->escapeHtml($item->getName()) . '" />';
else:
$html .='<span><img src="' . Mage::helper('catalog/image')->init($item->getProduct(), 'thumbnail') . '" width="50" height="50" alt="' . $item->getName() . '" /></span>';
endif;
$html .='</div>';
$html .='<div class="mini-basket-content-wrapper">
<div class="mini-cart-name">
<a class="item-name" href="' . $item->getUrl() . '">' . $productname . '</a> <span class="item-price"><span class="price">$' . $item->getPrice() . '</span></span>
<div class="truncated_full_value">
<dl class="item-options">
<dd class="truncated">
<div class="truncated_full_value">
<dl class="item-options">
' . $superAttrString . '
</dl>
</div>
</dd>
</dl>
</div>
<div class="product-cart-sku">SKU: # ' . $productsku . '</div>
<div class="product-qty">Quantity: ' . $productqty . '</div>
</div>
</div>
<div class="clearfix"></div>';
$html .='</li>';
}
$_response = Mage::getModel('ajaxminicart/response')
->setProductName($observer->getProduct()->getName())
->setCarttotal($grandTotal)
->setCartsubtotal($subTotal)
->setCartcount($count)
->setDiscount($discount)
->setShippingtaxamount($shippingTaxamount)
->setCartitem($html)
->setMessage(Mage::helper('checkout')->__('%s was added into cart.', $observer->getProduct()->getName()));
//append updated blocks
$_response->addUpdatedBlocks($_response);
$_response->send();
}
if ($request->getParam('is_checkout'))
{
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
$_response = Mage::getModel('ajaxminicart/response')
->setProductName($observer->getProduct()->getName())
->setMessage(Mage::helper('checkout')->__('%s was added into cart.', $observer->getProduct()->getName()));
$_response->send();
}
}
public function updateItemEvent($observer)
{
$request = Mage::app()->getFrontController()->getRequest();
if (!$request->getParam('in_cart') && !$request->getParam('is_checkout'))
{
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
$quote = Mage::getSingleton('checkout/cart')->getQuote();
$grandTotal = $quote->getGrandTotal();
$subTotal = $quote->getSubtotal();
$shippingTaxamount = Mage::helper('checkout')->getQuote()->getShippingAddress()->getData('tax_amount');
// get coupon discounted value
$totals = $quote->getTotals(); //Total object
if (isset($totals['discount']) && $totals['discount']->getValue())
{
$discount = Mage::helper('core')->currency($totals['discount']->getValue()); //Discount value if applied
}
else
{
$discount = '';
}
//get discount value end
$_response = Mage::getModel('ajaxminicart/response')
->setCarttotal($grandTotal)
->setCartsubtotal($subTotal)
->setShippingtaxamount($shippingTaxamount)
->setDiscount($discount)
->setMessage(Mage::helper('checkout')->__('Item was updated'));
//append updated blocks
$_response->addUpdatedBlocks($_response);
$_response->send();
}
if ($request->getParam('is_checkout'))
{
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
$_response = Mage::getModel('ajaxminicart/response')
->setMessage(Mage::helper('checkout')->__('Item was updated'));
$_response->send();
}
}
public function getConfigurableOptions($observer)
{
$is_ajax = Mage::app()->getFrontController()->getRequest()->getParam('ajax');
if ($is_ajax)
{
$_response = Mage::getModel('ajaxminicart/response');
$_response = Mage::getModel('ajaxminicart/response');
$product = Mage::registry('current_product');
if (!$product->isConfigurable() && !$product->getTypeId() == 'bundle')
{
return false;
exit;
}
//append configurable options block
$_response->addConfigurableOptionsBlock($_response);
$_response->send();
}
return;
}
public function getGroupProductOptions()
{
$id = Mage::app()->getFrontController()->getRequest()->getParam('product');
$options = Mage::app()->getFrontController()->getRequest()->getParam('super_group');
if ($id)
{
$product = Mage::getModel('catalog/product')->load($id);
if ($product->getData())
{
if ($product->getTypeId() == 'grouped' && !$options)
{
$_response = Mage::getModel('ajaxminicart/response');
Mage::register('product', $product);
Mage::register('current_product', $product);
//add group product's items block
$_response->addGroupProductItemsBlock($_response);
$_response->send();
}
}
}
}
Thank you
please try this
Mage::getModel('ajaxminicart/response')
->setProductName($observer->getProduct()->getName())
->setMessage(Mage::helper('checkout')
->__('%s was added into cart. Description : %s', $observer->getProduct()->getName(),$observer->getProduct()->getDescription()));
below list can be used for different product attributes
getShortDescription(); //product's short description
getDescription(); // product's long description
getName(); //product name
getPrice(); //product's regular Price
getSpecialPrice(); //product's special Price
getProductUrl(); //product url
getImageUrl(); //product's image url
getSmallImageUrl(); //product's small image url
getThumbnailUrl(); //product's thumbnail image url
let me know it works or not.. regards
I'm such a noob at PHP. I'm really stuck on this and could do with some help!
I'm using the following code to control if a div class and span ID appears when a variable (e.g. $project1title and $project1description) is empty/not empty.
$html = '<div class="infobar"><div class="infobar-close"></div>';
$content = false;
if ($project1title !== '' && $project1description !== '')
{
$html .= '<span id="title"></span><span id="description"></span>';
$content = true;
}
// etc.
$html .= '</div>';
if ($content)
{
echo $html;
}
The code works fine when I've only got one project title & description there but when I start adding ($project2title !== '' && $project2description !== '') if ($project3title !== '' && $project3description !== ''), etc it messes up because I need a unique ID for each project title & description. My question is, how can I make each of them have a unique ID? (Would I need to use arrays?) And once I've given each project a unique ID, where in the code above would I need to declare each unique ID?
What about this :
<?php
$projects = array(
array(
'title' => 'myTitle',
'description' => 'my description',
),
array(
'title' => 'myTitle2',
'description' => 'my description2',
),
);
$html = '<div class="infobar"><div class="infobar-close"></div>';
$content = false;
$id = 1;
foreach($projects as $project){
if(!empty($project['title']) && !empty($project['description'])){
$html .= '<span id="title'. $id .'"></span><span id="description'. $id .'"></span>';
$content = true;
}
$id++;
}
$html .= '</div>';
if ($content) {
echo $html;
}
Note that if id is important for you, you can add an id key in the projects array.
Does that help ?
Alternatively, I think you should take a look at dynamic vars :
here is simple example of what you can do with them :
<?php
$html = '<div class="infobar"><div class="infobar-close"></div>';
$content = false;
for($i = 1;$i<=10;$i++){
$title = 'project' . $i . 'title';
$description = 'project' . $i . 'description';
if (isset($$title) && isset($$description) && $$title !== '' && $$description !== '')
{
$html .= '<span id="title'. $i .'"></span><span id="description'. $i .'"></span>';
$content = true;
}
}
$html .= '</div>';
if ($content)
{
echo $html;
}
Shouldn't the operations be:
!=
instead of
!==
?