Skip to content

Instantly share code, notes, and snippets.

View wpscholar's full-sized avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
@wpscholar
wpscholar / array-insert-before.php
Created November 7, 2015 13:08
Insert a value or key/value pair before a specific key in an array. If key doesn't exist, value is prepended to the beginning of the array.
<?php
/**
* Insert a value or key/value pair before a specific key in an array. If key doesn't exist, value is prepended
* to the beginning of the array.
*
* @param array $array
* @param string $key
* @param array $new
*
@wpscholar
wpscholar / array-insert-after.php
Created November 7, 2015 13:04
Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended to the end of the array.
<?php
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* @param array $array
* @param string $key
* @param array $new
*
@wpscholar
wpscholar / vvv-provision.sh
Last active December 29, 2018 14:30
Provision a new site in VVV without having to run `vagrant reload --provision`
#!/bin/sh
# Run with `sudo bash vvv-provision.sh`
DIR=$(basename $PWD)
find /etc/nginx/custom-sites -name "vvv-auto-$DIR-*.conf" -exec rm {} \;
CONF="vvv-auto-$DIR-$(md5sum <<< vvv-nginx.conf | cut -c1-32).conf"
sed "s#{vvv_path_to_folder}#$PWD#" vvv-nginx.conf > /etc/nginx/custom-sites/"$CONF"
echo "Added nginx config file: $CONF"
<?php
/**
* Drop this code into your main plugin file to hide plugin deactivation from the WordPress admin.
*/
add_filter( 'plugin_action_links', function ( $actions, $plugin_file ) {
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
unset( $actions['deactivate'] );
}
<?php
/**
* Ensure that a specific theme is never updated. This works by removing the
* theme from the list of available updates.
*/
add_filter( 'http_request_args', function ( $response, $url ) {
if ( 0 === strpos( $url, 'https://api.wordpress.org/themes/update-check' ) ) {
$themes = json_decode( $response['body']['themes'] );
<?php
/**
* Ensure that a specific plugin is never updated. This works by removing the
* plugin from the list of available updates.
*/
add_filter( 'http_request_args', function ( $response, $url ) {
if ( 0 === strpos( $url, 'https://api.wordpress.org/plugins/update-check' ) ) {
$basename = plugin_basename( __FILE__ );
@wpscholar
wpscholar / cookies.js
Created July 12, 2015 02:25
Functions for setting, getting and deleting cookies via JavaScript
/**
* Set a cookie
*
* @param {string} cookieName
* @param {string} cookieValue
* @param {object} cookieOptions (expires, domain, path)
*/
function setCookie(cookieName, cookieValue, cookieOptions) {
cookieOptions = cookieOptions || {};
if (cookieValue) {
@wpscholar
wpscholar / terminus-search-replace.sh
Created June 27, 2015 04:44
WP-CLI Search and Replace via Terminus (on Pantheon)
terminus wp search-replace 'mysite.local' 'dev-mysite.pantheon.io' --site=mysite
@wpscholar
wpscholar / vagrant-cheat-sheet.md
Last active August 19, 2025 05:43
Vagrant Cheat Sheet

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)