Skip to content

Instantly share code, notes, and snippets.

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

Travis Wagner trvswgnr

:octocat:
hardly workin'
View GitHub Profile
@trvswgnr
trvswgnr / fix-permissions.sh
Last active September 25, 2020 03:39
Bash - Recursively change permissions to recommended default.
#!/bin/bash
# Check if sudo.
if [ "$EUID" -ne 0 ]
then echo "Please run as root."
exit
fi
# Change permissions of directories and all subdirectories.
find ./ -type d -exec chmod 755 {} \;
@trvswgnr
trvswgnr / search.php
Created May 14, 2020 02:30
Find array item by key value in multilevel array.
function search($array, $key, $value) {
$results = array();
if (is_array($array)) {
if (isset($array[$key]) && $array[$key] == $value) {
$results[] = $array;
}
foreach ($array as $subarray) {
$results = array_merge($results, search($subarray, $key, $value));
@trvswgnr
trvswgnr / set-low-storage-limit
Last active August 5, 2020 17:41
Set MacOS low storage notification limit.
#!/usr/bin/env bash
if [[ -z $1 ]]; then
echo 'Please set a disk space limit to trigger the low disk space warning'
exit 1;
else
LIMIT=$1
fi
defaults write com.apple.diskspaced minFreeSpace $LIMIT
@trvswgnr
trvswgnr / deploy.sh
Last active August 11, 2020 15:53
Codeship to WPEngine CI/CD Deploy Script
rm .gitignore
mv .gitignore-deploy .gitignore
cd wp-content/themes/standupstations/
npm install
npm run dev
git config --global user.name "CodeShip deployment"
git config --global user.email "[email protected]"
git remote add staging [email protected]:production/standupstaging.git
git add -A
git commit -m "Codeship deploy"
@trvswgnr
trvswgnr / get-product-primary-category.php
Created August 14, 2020 03:21
WooCommerce get primary category for product
<?php
/**
* Get a product's primary category using Yoast when available.
*/
function get_product_primary_category() {
global $product;
// if Yoast is being used, utilize it to get the primary category.
if ( function_exists( 'yoast_get_primary_term_id' ) ) {
$primary_category_id = yoast_get_primary_term_id( 'product_cat' );
$category = get_term( $primary_category_id );
@trvswgnr
trvswgnr / disable-updates-specific-plugins.php
Created August 14, 2020 03:30
WordPress disable updates for specific plugins
<?php
/**
* Disable updates for specied plugins.
*
* @param object $value Plugins update list.
*/
function taw_disable_specified_plugin_updates( $value ) {
unset( $value->response['some-plugin/some-plugin.php'] );
return $value;
}
@trvswgnr
trvswgnr / update-all-users.php
Created August 15, 2020 22:10
WordPress - Update All Users
<?php
function taw_update_all_users() {
$users = get_users();
foreach ( $users as $user ) {
wp_update_user( array( 'ID' => $user->ID ) );
}
}
add_action('admin_init', 'taw_update_all_users');
@trvswgnr
trvswgnr / update-postkey.php
Created August 15, 2020 22:25
WordPress - Update postkey once
function change_postkey_only_once() {
$key = 1;
$option = 'change_postkey_only_once_' . $key;
if ( ! get_option( $option ) ) {
global $wpdb;
$query = "UPDATE " . $wpdb->prefix . "postmeta
SET meta_key = 'new_key_name'
WHERE meta_key = 'old_key_name'";
$results = $wpdb->get_results($query, ARRAY_A);
return $results;
@trvswgnr
trvswgnr / remove_filter_with_class_function.php
Last active August 21, 2020 01:27
WordPress - Remove filter that was added using a class function
<?php
/**
* Remove filter that was added using a class function
*
* @param string $filter_name The filter hook to which the function to be removed is hooked.
* @param string $class_name The name of the class where the function resides.
* @param string $function_name The name of the function which should be removed.
*/
function remove_filter_with_class_function( $filter_name, $class_name, $function_name ) {
global $wp_filter;
@trvswgnr
trvswgnr / replace_table_prefixes.php
Last active August 21, 2020 04:03
WordPress - Replace Table Prefixes
<?php
/**
* Replace and rename table prefixes
*
* @param string $old The old table prefix to be replaced.
* @param string $new The new table prefix.
* @author Travis Aaron Wagner
*/
function taw_replace_table_prefixes( $old, $new ) {
global $wpdb;