Skip to content

Instantly share code, notes, and snippets.

View davemac's full-sized avatar

davemac davemac

View GitHub Profile
@davemac
davemac / WP pull prod
Created February 22, 2018 23:18
bash script to pull a production WP database to an existing local site
# pull a production WP database to an existing local site
# uses current directory as theme path and ssh alias
pullprod() {
START=$(date +%s)
# get current directory name, used for database and URL
# TODO: use echo get_template_directory() and get characters from right to first /
current=${PWD##*/}
cd ~/Sites/$current
# make a backup of the current local database
wp db export _db.sql
@davemac
davemac / WP deploy stage
Last active March 27, 2018 08:18
bash script to deploy a local WordPress database to an existing staging site
# push a local WP database to an existing staging site
# uses current directory as theme path and ssh alias
pushstage() {
START=$(date +%s)
# make a backup of the current local database
# get current directory name, used for database and URL
current=${PWD##*/}
cd ~/Sites/$current || return
# rsync the local database to staging site
@davemac
davemac / WP first deploy
Last active March 27, 2018 03:39
bash script for first deployment of WordPress site to staging server, excludes dev tools and build files
# for initial site deployment to staging server, excludes dev tools and build files
# uses current directory as theme path and ssh alias
# 3 user inputs: dbname, dbuser, dbpass
firstdeploy() {
current=${PWD##*/}
cd ~/Sites/$current || return
echo "Database name:"
read dbname
echo "Database user:"
<?php
/* Thanks to http://steindom.com/articles/shortest-php-code-convert-csv-associative-array */
ini_set('auto_detect_line_endings', TRUE);
$rows = array_map('str_getcsv', file('myfile.csv'));
$header = array_shift($rows);
$csv = array();
foreach ($rows as $row) {
@davemac
davemac / getlinks
Last active April 4, 2023 04:32
bash wget a remote URL, then extract the URLs from the anchor tags in that URL
@davemac
davemac / example flexbox content grid
Last active October 5, 2017 04:00
Responsive content grid with flexbox and scss
.flex-row{
display: flex;
// shorthand for flex-direction & flex-wrap
flex-flow: row wrap;
justify-content: space-between;
align-items: flex-start;
@media #{$small-only} {
display: block;
}
@davemac
davemac / gf_custom_checkbox
Created September 18, 2017 03:36
SCSS for Gravity Forms custom checkbox, styles from https://codepen.io/CreativeJuiz/pen/BiHzp
.ginput_container {
overflow: hidden;
margin: 5px 0 0;
padding: 1rem;
background-color: #dcdcdc;
border-radius: 4px;
ul.gfield_checkbox li input{
&[type="checkbox"]:not(:checked),
@davemac
davemac / WordPress MU generate site nav with current site highlighted
Last active August 30, 2017 07:59
WordPress MU generate site nav with current site highlighted
<?php
$dmc_current_site = get_current_blog_id();
$dmc_sites = get_sites();
if ( $dmc_sites ) {
ob_start();
?>
<ul class="inline-list global-tabs show-for-medium-up">
<?php
foreach ( $dmc_sites as $dmc_site ) {
@davemac
davemac / sort custom post type by ACF date field
Created August 15, 2017 23:26
sort custom post type by ACF date field
// sort by date field showing events after today
function dmc_training_cpt_pre_get_posts( $query ) {
if ( is_admin() || ! $query->is_main_query() ) { return;
}
if ( is_post_type_archive( 'dmc-offer' ) )
{
$date_now = date( 'Y-m-d H:i' );
$query->set( 'posts_per_page', -1 );