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 / 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 / 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 / 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-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 / 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 / remove-exif.php
Last active December 21, 2023 10:10
WordPress Plugin: Automatically remove EXIF data from .jpgs when uploaded
<?php
/**
* Plugin Name: Remove EXIF data
* Plugin URI: https://gist.github.com/joshuafredrickson/cd5ab346992f533ecbe976d365fa36dd
* Version: 1.0.0
* Description: Remove EXIF data from .jpg when uploaded.
* Author: Joshua Fredrickson
* Author URI: https://joshuafredrickson.com
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
@joshuafredrickson
joshuafredrickson / no-nags.php
Created January 29, 2019 14:46
WordPress: Move all admin notices and plugin nags to console
add_action('plugins_loaded', function() {
$action = is_user_admin() ? 'user_admin_notices' : 'admin_notices';
add_action($action, function () {
ob_start();
});
add_action('all_admin_notices', function () {
$log = strip_tags(trim(ob_get_clean()));
@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';
/**
@joshuafredrickson
joshuafredrickson / rest-api-seo.php
Created December 13, 2022 20:05
The SEO Framework REST API endpoints for WordPress
<?php
/**
* REST API
* The SEO Framework
*
* @package scout_rest_theme
*
* List of title methods
* @link https://github.com/sybrew/the-seo-framework/issues/202#issuecomment-412781194
*