Skip to content

Instantly share code, notes, and snippets.

View joshuafredrickson's full-sized avatar
🍊
Orange pineapple

Joshua Fredrickson joshuafredrickson

🍊
Orange pineapple
View GitHub Profile
@joshuafredrickson
joshuafredrickson / .env
Created November 3, 2024 21:35
Add Vite to a WordPress Theme
APP_URL=http://whatever-your-local-domain-is.test
@joshuafredrickson
joshuafredrickson / backup-mariadb.sh
Created June 26, 2024 18:46
Back up all MariaDB/MySQL databases and optionally exclude certain dbs
#!/bin/bash
# Set up variables
DBUSER=""
DBPASSWORD=""
DESTINATION="/volumes/external/mariadb"
EXCLUDE_DB="information_schema|performance_schema|mysql|sys" # Add any databases you want to exclude
# Get the list of databases
DBS=$(mysql -u $DBUSER -p$DBPASSWORD -e "SHOW DATABASES;" | grep -Ev "Database|$EXCLUDE_DB")
@joshuafredrickson
joshuafredrickson / gravityforms.php
Created June 17, 2024 13:51
Temporary fix for Gravity Forms merge tags on form notification edit screens
<?php
/**
* Temporary fix for Gravity Forms merge tags on form notification edit screens
*
* @see https://github.com/roots/acorn/issues/198
*/
add_action('admin_footer', function (): void {
// Only on GF admin pages
if (!class_exists('GFForms') || !isset($_GET['page']) || 'gf_edit_forms' !== $_GET['page']) {
return;
@joshuafredrickson
joshuafredrickson / solid-security.php
Created April 10, 2024 21:59
Change who receives Solid Security notifications based on environment type
<?php
/**
* Plugin Name: Solid Security configuration
* Plugin URI: https://joshuafredrickson.com
* Version: 1.0.0
* Description: Filter notifications in non-production environments.
* Author: Kinetic
* Author URI: https://joshuafredrickson.com
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
@joshuafredrickson
joshuafredrickson / gravity-forms.js
Created March 15, 2024 22:02
Gravity Forms: Perform an action while the form is submitting
/**
* Hook into the Gravity Forms submission process to show a loading state
*/
const wrapper = document.querySelector(
'.gform_wrapper'
);
const gfSubmitting = `gf_submitting_${
wrapper.querySelector('form').dataset.formid
}`;
@joshuafredrickson
joshuafredrickson / remove-slider-revolution-metabox.php
Last active January 15, 2024 16:02
WordPress: Remove Slider Revolution metabox from certain post types
<?php
/**
* Remove Slider Revolution metabox from certain post types.
* This includes removing it from the top of ACF field groups.
*/
add_action('do_meta_boxes', function (): void {
if (!is_admin()) {
return;
}
@joshuafredrickson
joshuafredrickson / csp-mu-plugin.php
Created December 5, 2023 01:33
Add CSP to WordPress, including nonces for inline scripts
<?php
/**
* Plugin Name: Content Security Policy
* Version: 1.0.0
* Description: Adds a Content-Security-Policy header to all non-admin requests.
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Original Inspiration: https://gist.github.com/westonruter/c8b49406391a8d86a5864fb41a523ae9
*/
@joshuafredrickson
joshuafredrickson / filters.php
Last active May 5, 2024 08:24
Preload font files found in Roots Sage 10 (bud.js) manifest.json
<?php
use Illuminate\Support\Str;
/**
* Add `rel="preload"` to font files found in the manifest
*/
add_filter('wp_head', function (): void {
echo collect(
json_decode(asset('manifest.json')->contents())
@joshuafredrickson
joshuafredrickson / remove-exif.php
Created September 7, 2023 16:23
WordPress MU Plugin: Strip EXIF data from images
<?php
/**
* Remove EXIF data from .jpg when uploaded.
*/
use Imagick;
/**
* Strip EXIF using Imagick, fallback to gd
@joshuafredrickson
joshuafredrickson / app.js
Created May 16, 2023 14:05
Dynamically loading Alpine components on page load.
import domReady from '@roots/sage/client/dom-ready';
/**
* Alpine components
*/
import Alpine from 'alpinejs';
import * as components from './components/index.js';
/**