Skip to content

Instantly share code, notes, and snippets.

@sardbaba
sardbaba / wordpress-functions.php
Created May 14, 2013 17:55
Add a checkbox for the terms agreement and hooks into wp_authenticate to allow authentication or to display an error message.
/**
* 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 June 13, 2013 20:16
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/
( 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 January 30, 2015 11:19
Wordpress - List all hooks
//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 January 26, 2016 17:16
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)
/* 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 March 2, 2016 16:39
One line calculate browser local storage size.
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 March 1, 2016 19:27
Woocommerce - Aggiunge verifica email ai campi billing
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 April 23, 2018 07:04 — 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.
/**
* 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:
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 = {}
@sardbaba
sardbaba / order_list_by_dependencies.py
Created November 14, 2020 08:03
order_list_by_dependencies.py
import json
views = {
"a1": {"position":0,"depends": []},
"a2": {"position":0,"depends": ["a1"]},
"a3": {"position":0,"depends": ["a2"]},
"a5": {"position":0,"depends": ["a9"]},
"a9": {"position":0,"depends": ["a7","a8"]},
"a7": {"position":0,"depends": []},
"a8": {"position":0,"depends": []},
@sardbaba
sardbaba / s3_delete_obj_tags.py
Last active May 3, 2021 13:08
AWS Boto3 delete object tags from all objects in a S3 bucket/prefix
import boto3
import time
start_time = time.time()
boto3.setup_default_session(profile_name='YOUR_AWS_PROFILE')
s3 = boto3.client('s3')
s3_paginator = s3.get_paginator('list_objects_v2')
BUCKET = 'YOUR-BUCKET-NAME'