Skip to content

Instantly share code, notes, and snippets.

@fitzhaile
fitzhaile / capistrano_wordpress_db_push_pull.rb
Created Mar 20, 2014
Push / Pull Wordpress Databases to / from remote and dev environments
View capistrano_wordpress_db_push_pull.rb
namespace :db do
desc "Pull (dump) the remote database and replace the local database with it"
task :pull do
on roles(:app) do
within release_path do
with path: "#{fetch(:path)}:$PATH" do
execute :mysqldump, "-u #{fetch(:wpdb)[fetch(:stage)][:user]} -p\"#{fetch(:wpdb)[fetch(:stage)][:password]}\" -h #{fetch(:wpdb)[fetch(:stage)][:host]} #{fetch(:wpdb)[fetch(:stage)][:name]} > #{fetch(:tmp_dir)}/database.sql"
download! "#{fetch(:tmp_dir)}/database.sql", "database.sql"
execute :rm, "#{fetch(:tmp_dir)}/database.sql"
end
@fitzhaile
fitzhaile / wordpress-varnish3.vcl
Last active Aug 1, 2017
Varnish VCL for WP and W3 Total Cache
View wordpress-varnish3.vcl
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
#
# BACKEND
backend default {
.host = "127.0.0.1";
@fitzhaile
fitzhaile / bem-nav.php
Last active Apr 17, 2017
Alternative BEM-based lib/nav.php for Roots Theme
View bem-nav.php
<?php
/**
* Cleaner, BEM-based walker for wp_nav_menu()
*
* (Attempts to adhere more to http://cssguidelin.es.)
*
* NOTE: This apprroach requires substitute arguments to be passed to wp_nav_menu().
*
* 'nav_class' - Class attached to the <nav> element that contains the menu.
* It is used to generate classes for the ul, li and anchor elements. For example,
@fitzhaile
fitzhaile / custom_excerpt.php
Last active Mar 24, 2016
Custom excerpt options for Wordpress.
View custom_excerpt.php
<?php
/**
* A replacement for the default wp_trim_excerpt().
*
* Generates an excerpt from the_content, if needed.
*
* It is similar (identical) to the default to allow filters other than our own to work,
* with the exception that it uses our default my_trim_words() function.
*
@fitzhaile
fitzhaile / config.php
Created Dec 28, 2013
Fix media directory location to be outside of wordpress root.
View config.php
<?php
/**
* Fix media directory location to be outside of wordpress root
*/
if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
update_option( 'upload_path', untrailingslashit( str_replace( 'wp', 'media', ABSPATH ) ) );
update_option( 'upload_url_path', home_url( 'media' ) );
}
@fitzhaile
fitzhaile / tiny-mce.php
Created Nov 15, 2013
Config for Tiny MCE in Wordpress.
View tiny-mce.php
<?php
/**
* Add custom styles to the styleselect dropdown
*
* @since required+ Foundation 0.5.0
*
* @param array $settings
* @return array
*/
@fitzhaile
fitzhaile / enable_tags.php
Last active Dec 20, 2015
WP: Enable Page tags
View enable_tags.php
<?php
// Include the following in functions.php
//-------------------------------------------
// add tag support to pages
function tags_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
}
// ensure all tags are included in queries
@fitzhaile
fitzhaile / script.rb
Created Jun 5, 2013
Base 64 encode Sass script
View script.rb
# Additional SASS Script functions
require 'sass'
require 'base64'
module Sass::Script::Functions
def base64encode(string)
assert_type string, :String
file = "."+string.value
data = File.open(file, "rb") {|io| io.read}
data = [data].flatten.pack("m").gsub("\n","")
@fitzhaile
fitzhaile / svg-png-fallback.js
Created Mar 26, 2013
Modernizr PNG SVG Fallback
View svg-png-fallback.js
if(!Modernizr.svg){
$("img.svg").each(function(){
var src = this.src.replace('.svg', '.png');
this.src = src;
});
}
View multiple-3rd-party-widgets.js
(function() {
var script,
scripts = document.getElementsByTagName('script')[0];
function load(url) {
script = document.createElement('script');
script.async = true;
script.src = url;
scripts.parentNode.insertBefore(script, scripts);
You can’t perform that action at this time.