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 / 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 November 7, 2023 19:55
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';
/**
@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
*
@joshuafredrickson
joshuafredrickson / bud.config.js
Created March 5, 2022 18:38
Bud: Create additional entrypoint for conditional enqueuing
module.exports = async (app) => {
app
/**
* Application entrypoints
*
* Paths are relative to your resources directory
*/
.entry({
app: {
import: ['@scripts/app', '@styles/app'],
@joshuafredrickson
joshuafredrickson / block-editor-cleanup.php
Last active April 19, 2022 13:47
Block Editor Cleanup for WordPress 5.9 and Classic Editor (mu-plugin)
<?php
/**
* Plugin Name: Block Editor Cleanup
* Plugin URI: https://github.com/WordPress/gutenberg/issues/38299#issuecomment-1025520487
* Version: 1.0.1
* Description: Remove WP 5.9 default block editor styles when using Classic Editor
* Author: joshuafredrickson
* Author URI: https://joshuafredrickson.com
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html