Skip to content

Instantly share code, notes, and snippets.

@sardbaba
sardbaba / backup_all_dbs.sh
Created November 18, 2012 20:35
Backup All DB's and transfer to S3 with s3cmd + Rolling on the days of the weeks and on the weeks of the months + a montly backup (for paranoiac guys)
#!/bin/bash
BACKUP_DIR="~/db_backups"
DBUSER=""
DBPASSWORD=""
BUCKET="your-unique-bucket-name"
FROM='"Backups" <backups@localhost>'
TO='"Admin" <admin@localhost>'
SUBJECT='Backup Log'
@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:
Drupal.settings.isTouchDevice = function() {
return "ontouchstart" in window;
}
if ( Drupal.settings.isTouchDevice() ) {
Drupal.behaviors.jQueryMobileSlideShowTouchAdvance = {
attach: function(context, settings) {
self = Drupal.behaviors.jQueryMobileSlideShowTouchAdvance;
jQuery.each(jQuery(".views_slideshow_cycle_main.viewsSlideshowCycle-processed"), function(idx, value) {
value.addEventListener("touchstart", self.handleTouchStart);
@sardbaba
sardbaba / jquery-outer.js
Last active August 29, 2015 14:01 — forked from tlync/jquery-outer.js
Setter for jQuery outerWidth/outerHeight, in a compact version
/** Get or set the current outer width/height for the first element in the set of matched elements. */
var origOuterWidth = $.fn.outerWidth;
$.fn.outerWidth = function(){
var value = arguments[0];
if (arguments.length === 0 || typeof value === 'boolean') { return origOuterWidth.apply(this, arguments); }
else if (typeof value !== 'number') { throw new Error('Invalid argument. The new outerWidth value must be an integer.'); }
var css = ['borderLeftWidth','borderRightWidth','paddingLeft','paddingRight'];
if (arguments[1] === true) { css.push('marginLeft'); css.push('marginRight'); }
var $el = $(this), exclude = 0, parse = parseFloat;
for (var i=0; i<css.length; i++) { exclude += parse($el.css(css[i])); }
@sardbaba
sardbaba / functions.php
Last active December 4, 2015 17:59 — forked from kloon/functions.php
<?php
// Add a date range to a datepicker field, replace #date with the id of the date field.
add_filter( 'wp_footer' , 'woo_add_checkout_field_date_range_limit' );
function woo_add_checkout_field_date_range_limit() {
if ( is_checkout() ) {
$js = 'jQuery( "#date" ).datepicker({ minDate: -5, maxDate: "+1M +10D" });';
// Check if WC 2.1+
if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
wc_enqueue_js( $js );
} else {
@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 ) {