Skip to content

Instantly share code, notes, and snippets.

@sardbaba
sardbaba / wordpress-functions.php
Created May 14, 2013
Add a checkbox for the terms agreement and hooks into wp_authenticate to allow authentication or to display an error message.
View wordpress-functions.php
/**
* Add the terms agreement field
*/
function sardbaba_add_login_field() {
?>
<p class="forgetmenot">
<label for="terms-agreement">
<input name="terms-agreement" type="checkbox" id="terms-agreement" value="agree"> <?php _e( 'I Agree to the terms and conditions' ) ?>
</label>
</p>
@sardbaba
sardbaba / functions.js
Created Jun 13, 2013
Fallback to PNG if SVG is not supported. Note: of course, you must create the PNG version of the SVG image. Reference: http://toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script/
View functions.js
( function( $ ) {
$( window ).load( function() {
function supportsSVG() {
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect;
}
if (!supportsSVG()) {
var imgs = document.getElementsByTagName('img');
var dotSVG = /.*\.svg$/;
@sardbaba
sardbaba / functions.php
Created Jan 30, 2015
Wordpress - List all hooks
View functions.php
//LIST ALL HOOKS
function dump_hook( $tag, $hook ) {
ksort($hook);
echo "<pre>>>>>>\t$tag<br>";
foreach( $hook as $priority => $functions ) {
echo $priority;
@sardbaba
sardbaba / gist:f822604e53aab4769771
Created Jan 26, 2016
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)
View gist:f822604e53aab4769771
/* Produces a dump on the state of WordPress when a not found error occurs */
/* useful when debugging permalink issues, rewrite rule trouble, place inside functions.php */
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<pre>';
add_action( 'parse_request', 'debug_404_rewrite_dump' );
function debug_404_rewrite_dump( &$wp ) {
@sardbaba
sardbaba / local-storage-size.js
Created Mar 2, 2016
One line calculate browser local storage size.
View local-storage-size.js
var total = 0; for(var x in localStorage) { var amount = (localStorage[x].length*2)/1024/1024; total += amount; } console.log("Total: "+total.toFixed(10)+" MB");
@sardbaba
sardbaba / woocommerce-functions.php
Created Mar 1, 2016
Woocommerce - Aggiunge verifica email ai campi billing
View woocommerce-functions.php
class My_Class {
public function __construct () {
// Aggiunge verifica email ai campi billing
add_filter( 'woocommerce_billing_fields' , array($this, 'woocommerce_billing_fields'), 10, 1 );
add_action( 'woocommerce_checkout_process', array($this, 'woocommerce_checkout_process'), 9 );
}
function array_insert(&$array, $position, $insert) {
$pos = array_search($position, array_keys($array));
@sardbaba
sardbaba / wordpress-function.php
Last active Apr 23, 2018 — forked from GaryJones/gist:1258784
An improved version of the original Jared/Gary version which checks for, in order, the presence of: 1) subcategory template ID 2) subcategory template slug 3) parent category ID 4) parent category slug 5) general category (category.php) You can use it in the function.php file of your theme.
View wordpress-function.php
/**
* Apply a template to all subcategories of a certain parent category.
*
* Initial work by Jared Atchison.
* http://www.jaredatchison.com/2011/10/02/taking-advantage-of-the-template_include-filter/
*
* Revisited by GaryJones https://gist.github.com/GaryJones/1258784
* https://gist.github.com/GaryJones/1258784
*
* An improved version of the original Jared/Gary version which checks for, in order, the presence of the templates:
@sardbaba
sardbaba / MultiMP3s-to-1MP3
Last active Feb 4, 2020
Converts multiple mp3 to one single mp3
View MultiMP3s-to-1MP3
#!/bin/bash
for d in */ ; do
mp3PATH=$PWD/"$d"
OUTDIR=$(basename "${mp3PATH//\'}")
echo $mp3PATH $OUTDIR
if [ -d "$mp3PATH" ]; then
View flatten_json_pandas_df_column.py
def flatten_json(nested_json, name='', exclude=['']):
"""Flatten json object with nested keys into a single level.
Args:
nested_json: A nested json object.
name: A name to cancatenate to the sublevels keys
exclude: Keys to exclude from output.
Returns:
The flattened json object if successful, None otherwise.
"""
out = {}
You can’t perform that action at this time.