Skip to content

Instantly share code, notes, and snippets.

@jgarciaruiz
jgarciaruiz / gist:7a1af8dd94f2acb6bfd9
Last active December 9, 2015 13:12
wp-content/mu-plugins -> Disables plugins for API requests in order to speed up the API response times.
<?php
//wp_get_active_and_valid_plugins() is the function which fetches all the active plugins and load them.
//This function gets these active plugins from the database where the list of active plugins are stored
//as an array in the wpdb_options table with option name as “active_plugins”
foreach ( wp_get_active_and_valid_plugins() as $plugin )
include_once( $plugin );
unset( $plugin );
?>
@jgarciaruiz
jgarciaruiz / modal-share.js
Created December 16, 2015 14:27
Add the class social-button to the links you want to open on a modal window.
function modalPopup(url, width, height) {
var left = (screen.width / 2) - (width / 2),
top = (screen.height / 2) - (height / 2);
window.open(
url,
"",
"menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left
);
}
$(".social-button").on("click", function(e) {
function checkPalindrome(thestr) {
var reverseStr = thestr.split('').reverse().join('');
if (thestr == reverseStr){
return "yay";
}else{
return "nope"
}
}
//checkPalindrome("aba");
@jgarciaruiz
jgarciaruiz / js-apply-example.js
Last active December 29, 2015 20:53
Using apply function to find out the maximum/minimum value in an array
var numbers = [342, 16, 8, 345, 23, 436, 75];
highestVal(numbers);//436
lowestVal(numbers);//8
function highestVal(array){
var highestN = Math.max.apply(Math, array)
return highestN;
}
@jgarciaruiz
jgarciaruiz / class.yith-wc-coupon-email-system-premium
Last active January 26, 2016 12:40
Add bday field to register form using WP plugin yith-woocommerce-coupon-email-system-premium: lines 104-105
<?php
/**
* This file belongs to the YIT Plugin Framework.
*
* This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/gpl-3.0.txt
*/
@jgarciaruiz
jgarciaruiz / add2cartViaCoupon.php
Created February 4, 2016 17:17
WooCommerce add product to cart if coupon code matches existing coupon
//Adding a hidden product to cart with applied coupon woocommerce/wordpress
//a modified version of this:http://docs.woothemes.com/document/automatically-add-product-to-cart-on-visit/
add_action( 'init', 'add_product_to_cart' );
<?php
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 1211;
$found = false;
//@ http://jsfromhell.com/array/shuffle
shuffle = function(v){
for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};
//example:
var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
shuffle(a);
@jgarciaruiz
jgarciaruiz / remove_whitespaces_regex.js
Last active February 10, 2016 10:55
Remove leading and trailing white spaces from html string. [Polyfill]
//// http://stackoverflow.com/questions/10032024/how-to-remove-leading-and-trailing-white-spaces-from-a-given-html-string
//Running the following code before any other code will create trim() if it's not natively available.
if(!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g,'');
};
}
@jgarciaruiz
jgarciaruiz / functions.php
Created February 16, 2016 09:20
Add custom code to specific wp page snippet
function custom_code(){
if ( is_page( 102 )) {
?>
<!-- TRACKING CODE OR WHATEVER -->
<?php
}
}
add_action('wp_footer', 'custom_code');
@jgarciaruiz
jgarciaruiz / index.html
Created February 29, 2016 17:05
js fallback if CND fails to load
<!-- load script from CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<!-- if fails, fallback a local version -->
<script>window.angular || document.write('<script src="js/angular.min.js"><\/script>');</script>