Skip to content

Instantly share code, notes, and snippets.

View trvswgnr's full-sized avatar
:octocat:
hardly workin'

Travis A. Wagner trvswgnr

:octocat:
hardly workin'
View GitHub Profile
@trvswgnr
trvswgnr / .bash_profile
Last active May 23, 2018 04:07
My Bash Profile
# TAW Bash Profile
# @author: Travis A. Wagner
# @website: http://travisawagner.com
# -- BASE --#
# Set default blocksize for ls, df, du
# http://hints.macworld.com/comment.php?mode=view&cid=24491
export BLOCKSIZE=1k
@trvswgnr
trvswgnr / generate-wp-pages.php
Last active January 30, 2019 04:00
Programmatically Generate WordPress Pages
<?php
/**
* Generate WordPress Pages
* @example: taw_generate_pages('page one', 'Page Two', 'page-three');
*/
function taw_generate_pages($names) {
if (!$names) { return false; }
$list = func_get_args();
foreach ($list as $item) {
@trvswgnr
trvswgnr / .travis.yml
Last active February 12, 2019 04:03
Travis CI Automated NPM Build & SSH Deploy
language: node_js # use 'generic' if not compiling anything
node_js:
- "node"
cache: npm
env:
global:
- DEVELOPMENT_PATH="/full/path/to/dev/deployment/directory"
- PRODUCTION_PATH="/full/path/to/production/deployment/directory"
- SSH_USER="username"
- SSH_HOST="example.com"
@trvswgnr
trvswgnr / deploy.sh
Last active August 31, 2020 06:26
Bash - rsync Deploy Script
#!/usr/bin/env bash
# NOTE: this file needs to have write and execute permissions (chmod u+x ./deploy.sh)
set -e
DEV_PATH="/home/wpe-user/sites/corpmember3/wp-content"
PRO_PATH="/home/wpe-user/sites/corpmember/wp-content"
DEV_SSH="corpmember3@corpmember3.ssh.wpengine.net"
PRO_SSH="corpmember@corpmember.ssh.wpengine.net"
DEPLOY_IGNORE="./.deployignore"
@trvswgnr
trvswgnr / paragraph-excerpt.php
Created February 27, 2019 22:46
use first paragraph for wordpress excerpt
add_filter( 'wp_trim_excerpt', 'awesome_excerpt', 10, 2 );
function awesome_excerpt($text, $raw_excerpt) {
if( ! $raw_excerpt ) {
$content = apply_filters( 'the_content', get_the_content() );
$text = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
}
return $text;
}
@trvswgnr
trvswgnr / parse-args.php
Last active August 31, 2020 06:23
PHP - parse args array with default
<?php
function parse_args( $args, $defaults = '' ) {
if ( is_object( $args ) ) {
$r = get_object_vars( $args );
} elseif ( is_array( $args ) ) {
$r =& $args;
} else {
parse_str( $args, $r );
}
@trvswgnr
trvswgnr / class-example-module.php
Last active April 11, 2019 04:07
Create a reusable WordPress module with OOP.
<?php
/**
* Class: Example Module
*
* @package projectname
* @subpackage modules
*/
/**
* Example Module
@trvswgnr
trvswgnr / add-wp-user.php
Last active October 14, 2020 17:13
Create a new WordPress user.
<?php
/**
* Add WordPress User
*
* @package taw
*/
/**
* Add WordPress Admin User
*/
@trvswgnr
trvswgnr / fetch-all-branches.sh
Created April 5, 2020 04:03
Fetch all branches from GitHub
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
@trvswgnr
trvswgnr / autoloader.php
Created April 26, 2020 07:56
Automatically load plugins in folders inside the mu-plugins folder
<?php
/**
* Automatically loads plugins in folders
*
* @package mu-plugin-autoloader
*/
$dirs = array_filter( glob( WPMU_PLUGIN_DIR . '/*' ), 'is_dir' );
foreach ( $dirs as $dirpath ) {
$regex = '/([^\/]+$)/';