http://shopify.github.io/Timber/
editing wordpress
“ Great person, highly recommended ”
— Sn3s — Kuwait
Creëer een WordPress Template
Great Job again! Hope to work together in future again!
— KoenandJan — Netherlands
get wordpress menu custom css classes and add it to body classes
add_filter('body_class','add_nav_menu_css'); function add_nav_menu_css($classes) { $menu_name = 'primary'; // menu theme location global $wp_query; $queried_object = $wp_query->get_queried_object(); $current_id = $queried_object->ID; if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) { $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $items = wp_get_nav_menu_items($menu->term_id); foreach ($items as $i) { if($current_id == $i->object_id){ $menuClasses .= $i->classes[0].' '; } } $classes[] = $menuClasses; } return $classes; }
force scripts into the footer in wordpress
function custom_clean_head() { remove_action('wp_head', 'wp_print_scripts'); remove_action('wp_head', 'wp_print_head_scripts', 9); remove_action('wp_head', 'wp_enqueue_scripts', 1); add_action('wp_footer', 'wp_print_scripts', 5); add_action('wp_footer', 'wp_enqueue_scripts', 5); add_action('wp_footer', 'wp_print_head_scripts', 5); } add_action( 'wp_enqueue_scripts', 'custom_clean_head' );
know your client from his password
if the client password is too complicated then he is not feeling safe or secure and he needs assurance or he uses lastpass . if the password is too simple and silly then he is not totally into the web thing. the web is a game for him. if it is really simple and gues free, either he have a lot to remember already or he is just lazy
code to exclude posts on homepage
this code in function.php
function get_hidden_posts() { global $WP_Query; $now_minus2 = date('Y-m-d H:i:s', strtotime('-120 minute', current_time('timestamp'))); $args = array( 'date_query' => array( array( 'before' => $now_minus2 ) ), 'meta_query' => array( array( 'key' => '¿directo?', 'value' => 'Si', 'compare' => '=' ) ), 'posts_per_page' => -1, 'fields' => 'ids' ); $query_post_to_hide = new WP_Query($args); $post_to_hide = array(); while ( $query_post_to_hide->have_posts() ) { $query_post_to_hide->the_post(); $post_to_hide[] = get_the_ID(); } return $post_to_hide; } function exclude_hidden_posts( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'post__not_in', get_hidden_posts() ); } } add_action( 'pre_get_posts', 'exclude_hidden_posts' );
how to fix wordpress http error on image upload
install the default to gd wordpress plugin
https://github.com/alhoseany/default-to-gd As of WordPress 3.5, GD has been abstracted out into WP_Image_Editor, and Imagick has been made the default image manipulation engine.
In most cases, this is what you want. However, if you’re having issues with Imagick, or just prefer the way that GD handles your images, this plugin sets GD as the default WP_Image_Editor class for WordPress.
other fixes:
1- change permission on async-upload.php
usually this is done when the normal browser uploader is working and the multiple file uploader or the flash uploader is not working
chmod 644 /public_html/wp-admin/async-upload.php
2- htaccess solution in wp-admin folder
# Exclude the file upload and WP CRON scripts from authentication <FilesMatch "(async-upload.php|wp-cron.php|xmlrpc.php)$"> Satisfy Any Order allow,deny Allow from all Deny from none </FilesMatch> <IfModule mod_security.c> SecFilterEngine Off SecFilterScanPOST Off </IfModule>
3- htaccess above the web root or in “public_html”
<IfModule mod_security.c> <Files async-upload.php> SecFilterEngine Off SecFilterScanPOST Off </Files> </IfModule>
import sql data into wordpress
use phpmyadmin to export sql as csv then use this plugin:
Really Simple CSV Importer
http://wordpress.org/plugins/really-simple-csv-importer/
add coupon code to whmcs order form
1- add smarty plugin in this path includes/smarty/plugins
<?php /* * Smarty plugin * ------------------------------------------------------------- * File: function.check_coupon.php * Type: function * Name: check_coupon * Purpose: check coupon code and return info * ------------------------------------------------------------- */ function smarty_function_check_coupon($params, $smarty) { global $smarty; if ($_GET['promocode']) { $command = "getpromotions"; $adminuser = "admincpo"; $values["code"] = $_GET['promocode']; $results = localAPI($command, $values, $adminuser); //print_r(strtotime($results['promotions']['promotion'][0]['expirationdate'])); $coupon_types = array("Percentage", "Fixed Amount", "Price Override"); if(time() > strtotime($results['promotions']['promotion'][0]['expirationdate']) && strtotime($results['promotions']['promotion'][0]['expirationdate']) > 0){ $expired = true; echo '<div class="alert alert-block alert-error"> <strong>Oh!</strong> This coupon code has Expired. </div> '; } if ($results['totalresults'] > 0 && in_array($results['promotions']['promotion'][0]['type'], $coupon_types) && !$expired) { echo '<div class="alert alert-block alert-success"> <strong>Congratulations!</strong> You have selected our most valuable offer. </div> '; $coupon_recurring = ''; if ($results['promotions']['promotion'][0]['recurring'] == 1) { $coupon_recurring = 'Recurring'; } else { $coupon_recurring = 'One time'; } $products_appliesto = array(); $products_appliesto = explode(",", $results['promotions']['promotion'][0]['appliesto']); $coupon_type = $results['promotions']['promotion'][0]['type']; $coupon_value = $results['promotions']['promotion'][0]['value']; $myproducts = array(); $myproducts = $smarty->get_template_vars('products'); $mycurrency = $smarty->get_template_vars('currency'); foreach ($myproducts as $key => $myproduct) { if (in_array($myproduct['pid'], $products_appliesto)) { switch ($coupon_type) { case 'Percentage': $old_price = $myproduct['pricing']['minprice']['price']; $new_price = $myproduct['pricing']['rawpricing'][$myproduct['pricing']['minprice']['cycle']] - (($coupon_value / 100) * $myproduct['pricing']['rawpricing'][$myproduct['pricing']['minprice']['cycle']]); $coupon_phrase = $coupon_recurring . " " . number_format($coupon_value) . "% Discount"; break; case 'Fixed Amount': $old_price = $myproduct['pricing']['minprice']['price']; $new_price = ($myproduct['pricing']['rawpricing'][$myproduct['pricing']['minprice']['cycle']] - $coupon_value); $coupon_phrase = $coupon_recurring . " " . $mycurrency['prefix'] . number_format($coupon_value) . " off"; break; case 'Price Override': $old_price = $myproduct['pricing']['minprice']['price']; $new_price = $coupon_value; break; } $cycling = '<br /><span style="font-size: 12px;line-height: 22px;">' . ucfirst($myproduct['pricing']['minprice']['cycle']) . '</span>'; if ($results['promotions']['promotion'][0]['recurring'] != 1) { $cycling = '<br /><span style="font-size: 12px;line-height: 22px;">First Month</span>'; } $myproducts[$key]['pricing']['minprice']['price'] = '<span style="font-size: 12px;line-height: 22px;">' . $coupon_phrase . '</span><br /><span style="background-color: rgb(255, 255, 255); border: 1px solid rgb(204, 204, 204); border-radius: 5px 5px 5px 5px; color: rgb(255, 102, 0); padding: 5px; margin: 5px 0px 5px 5px; line-height: 50px; text-align: center;">' . $mycurrency['prefix'] . $new_price . ' ' . $mycurrency['suffix'] . '</span>' . $cycling . '<br /><br /><span style="font-size: 14px; color: red;"><del>' . $old_price . '</del></span>'; } } $smarty->assign('products', $myproducts); } } } ?>
then in the file