Skip to content

Instantly share code, notes, and snippets.

View felixzapata's full-sized avatar

Félix Zapata felixzapata

View GitHub Profile
@felixzapata
felixzapata / gist:b8acf86ab74b04514ae4
Created July 5, 2014 18:42
Debug white screen page error WordPress
error_reporting(E_ALL); ini_set('display_errors', 1);
define( 'WP_DEBUG', true);
@felixzapata
felixzapata / gist:d2554b5a7cb695f0dfd9
Created June 29, 2014 08:34
Extensión de un fichero
// http://stackoverflow.com/questions/8231058/file-type-validation-with-javascript
return fname.substr((Math.max(0, fname.lastIndexOf(".")) || Infinity) + 1);
return fname.substr((~-fname.lastIndexOf(".") >>> 0) + 2);
@felixzapata
felixzapata / gist:83a621322ce67e1acdde
Created June 25, 2014 15:36
handle the swanky navigation/section stuff
// http://speckyboy.com/2014/06/25/content-overlays-css3-transitions/
(function(){
// handle the swanky navigation/section stuff
////////////////////////////////////////////////////////////
var nav_links = document.querySelectorAll("nav.cmn-overlays-nav a");
@felixzapata
felixzapata / gist:7eebb2e901c231c77857
Created May 31, 2014 20:26
View all WP query variables
global $wp_query;
var_dump($wp_query->query_vars);
@felixzapata
felixzapata / gist:a711b31278dfcb41a908
Created May 13, 2014 06:40
How to pass arguments to addEventListener listener function?
var someInput = document.querySelector('input');
someInput.addEventListener('click', myFunc, false);
someInput.myParam = 'This is my parameter';
function myFunc(evt){
window.alert( evt.target.myParam );
}
@felixzapata
felixzapata / gist:9989468
Created April 5, 2014 09:15
WordPress - Category list order in post edit page
function taxonomy_checklist_checked_ontop_filter ($args)
{
$args['checked_ontop'] = false;
return $args;
}
add_filter('wp_terms_checklist_args','taxonomy_checklist_checked_ontop_filter');
@felixzapata
felixzapata / gist:9721335
Created March 23, 2014 10:34
Show all terms from a taxonomy named 'taxonomy, from post with id 136
SELECT t.*, tt.* FROM ss_terms AS t
INNER JOIN ss_term_taxonomy AS tt ON (tt.term_id = t.term_id)
INNER JOIN ss_term_relationships AS tr ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.taxonomy IN ('taxonomy') AND tr.object_id IN (136)
ORDER BY t.name ASC;
@felixzapata
felixzapata / gist:9481628
Created March 11, 2014 08:28
Display a JSON
console.log(JSON.stringify(data,true," "));
@felixzapata
felixzapata / gist:9320651
Created March 3, 2014 08:19
generate a random number and convert it to base 36
var rand = function() {
return Math.random().toString(36).substr(2); // remove `0.`
};
var token = function() {
return rand() + rand(); // to make it longer
};
token(); // "bnh5yzdirjinqaorq0ox1tf383nb3xr"
@felixzapata
felixzapata / gist:9144986
Created February 21, 2014 22:32
How to create a clone role in WordPress
<?php
add_action('init', 'cloneRole');
function cloneRole()
{
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
$adm = $wp_roles->get_role('administrator');