Skip to content

Instantly share code, notes, and snippets.

@dalethedeveloper
dalethedeveloper / gist:5826076
Created June 20, 2013 19:56
WP Network Site Move SQL
-- Make sure ZZZ is the number of the site in the `wp_sites` table. Your root site has no entry so it would be `wp_posts`
-- but your first site in the Network Admin > Sites list would be `wp_1_posts`
-- OLDSITE.TLD and NEWSITE.TLD should be complete FQDNs. If a site was www.olddomain.com make sure you replace it
-- completely so that you don't end up with www.www.newsite.com
UPDATE wp_ZZZ_postmeta SET meta_value = replace(meta_value,'OLDSITE.TLD','NEWSITE.TLD') WHERE meta_value like '%OLDSITE.TLD%';
UPDATE wp_ZZZ_posts SET guid = replace(guid, 'OLDSITE.TLD','NEWSITE.TLD');
UPDATE wp_ZZZ_posts SET post_content = replace(post_content, 'OLDSITE.TLD','NEWSITE.TLD');
-- Close comments on all existsing posts and pages
UPDATE wp_ZZZ_posts SET ping_status = 'closed', comment_status = 'closed' WHERE post_type IN ('post,'page');
@dalethedeveloper
dalethedeveloper / gist:6511417
Created September 10, 2013 15:49
Override jQuery Mobile page change/show methods to hack in support for #anchor links in the content fragment loaded. Tested with JQM 1.2 to 1.3.2.
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
if (window.location.hash == '#_=_') // Darn it, Facebook
window.location.hash = '';
$(document).bind("mobileinit", function(){
// Enable anchor links to behave like you think they would
$(document).on('pagechange',function(e,ui){
$('a[href^="#"]',ui.toPage).on('click',function(){
var selector = 'a[name="'+($(this).attr('href').substring(1))+'"]',
@dalethedeveloper
dalethedeveloper / gist:7539297
Created November 19, 2013 02:32
Hackery to migrate existing GIT repositories to BitBucket as the master origin. Say you have a directory of folders, each with a git repository, that need to be created as private repositories and pushed up. This does that.
#!/bin/bash
# Get your credentials set in your environment before you run:
# export BB_USER="my_username"
# export BB_P="MySERCRETP4ss"
# export BB_OWNER="my_username_or_team"
for f in $(find -type d -path '.*git' |cut -d'.' -f2|sed 's:/::g'); do
g=$(curl -s -u $BB_USER:$BB_P "https://bitbucket.org/api/1.0/repositories/$BB_OWNER/$f")
rg=$(echo "$g" | grep -c error)
@dalethedeveloper
dalethedeveloper / gist:8336483
Created January 9, 2014 15:57
WordPress wp-config.php hack to force a WP site to respond to whatever domain you access it from, database wp_options be damned. Thanks Rackspace Cloud Sites!
// Anywhere in the wp-config.php before the last include
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST']);
@dalethedeveloper
dalethedeveloper / .htaccess
Created January 16, 2014 15:34
Power up PHP on Rackspace Cloudsites, WordPress is hungry
# append to existing .htaccess
# PHP Settings http://www.rackspace.com/knowledge_center/product-faq/cloud-sites
php_value memory_limit 512M
php_value upload_max_filesize 32M
php_value post_max_size 32M
php_value max_execution_time 200
php_value max_input_time 200
@dalethedeveloper
dalethedeveloper / functions.php
Created January 20, 2014 22:55
Remove height= and width= attributes on IMG tags generaged by WordPress :: the_thumbnail() calls.
function strip_img_hwattr($html) {
return preg_replace('/(width|height)=\"\d+\"\s/','',$html);
}
add_filter('post_thumbnail_html','strip_img_hwattr',100);
@dalethedeveloper
dalethedeveloper / .htaccess
Created May 15, 2014 19:21
WordPress .htacces redirect to shift to new domain but allow wp-admin access
# Drop at the end of your base .htaccess or virtualhost, hooray for negative lookaheads
RedirectMatch ^\/(?!wp\-admin)(.*)$ http://newdomain.com/$1
@dalethedeveloper
dalethedeveloper / gist:0ce24d86cf4c4a12e277
Created October 1, 2014 15:17
Poor Mans Image Rotator (multiple slides, minimal jquery)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
var rollem = function() {
var si = $('#slide ul.current');
si.removeClass('current').fadeOut(
@dalethedeveloper
dalethedeveloper / gist:460e7c72c1d1e9f55a94
Created December 12, 2014 16:33
Check the Google Tag Manager dataLayer for an Ecommerce transaction and do something only once (cookie enforced)
if (typeof (window.dataLayer) !== 'undefined' && window.dataLayer.length) {
for (var d = 0; d < window.dataLayer.length; d++) {
var obj = window.dataLayer[d],
keys = Object.keys(obj);
for (var k = 0; k < keys.length; k++) {
var key = keys[k],
val = obj[key];
@dalethedeveloper
dalethedeveloper / gist:cc1f482f5ebdf07ccf26
Last active August 29, 2015 14:11
Prepare a Tab Delimited flat file for SQL Import where text fields contain newlines that cause records fall to the next line
# Assumes a tab delimited flat file and the first field being a numeric key
BEGIN {
FS = OFS = "\t";
p = "";
}
# Strategy is to readline, check for key in first field, store to print
# on next readline if the next record has a key in first field, otherwise
# append our fragmented line to the stored line
{
sub(/\r/,""); # also scrub those pesky carriage returns