Skip to content

Instantly share code, notes, and snippets.

@joemcgill
joemcgill / README.md
Last active April 15, 2024 08:35
WPP Better Image Sizes is a proof of concept WordPress plugin that provides a better calculation for the default sizes attribute for images.

WPP Better Image Sizes

This is a WordPress Plugin that improves the default sizes attribute calculation for images.

Description

WPP Better Image Sizes is a WordPress plugin that provides a better calculation for the default sizes attribute for images. This plugin is designed to enhance the performance and responsiveness of your WordPress site.

Installation

@joemcgill
joemcgill / plugin.php
Last active November 24, 2023 08:53
WP 6.4 Theme Path Fixer
<?php
/*
* Plugin Name: WP 6.4 Theme path fixer
* Plugin URI: https://gist.github.com/joemcgill/dd569c287013ad545f41495f93d7a27e
* Description: Fix problems with theme directory memoization in WP 6.4.
* Version: 1.0
* Requires at least: 6.4
* Author: Joe McGill
* Author URI: https://joemcgill.net
* License: GPL v2 or later
@joemcgill
joemcgill / plugin.php
Created July 20, 2020 19:06
Fix Instagram embeds with Jetpack shortcodes module
<?php
// Disable Jetpack's instagram shortcode since it breaks oEmbed functionality.
add_filter( 'jetpack_shortcodes_to_include', function ( $shortcodes ) {
unset( $shortcodes['instagram'] );
return $shortcodes;
}, 99 );
// Add a simple shortcode wrapper for the embed functionality to support the shortcode format.

Force Gutenberg to Fullscreen Mode

This is an example snippet for forcing the Gutenberg editor into full screen mode in anticipation of the change coming to WordPress 5.4.

@joemcgill
joemcgill / Remove Class Filters Example
Last active March 4, 2020 01:43
Remove filters added from class instances on a specific hook.
class Test_Class {
public function __construct() {
add_filter( 'pre_get_posts', [$this, 'test_callback'] );
}
public function test_callback() {
wp_die( 'Hooked up.' );
}
}
@joemcgill
joemcgill / axe-report.js
Created December 11, 2018 18:12
A11y test example for axe-puppeteer.
const colors = require('colors');
const link = colors.underline.blue;
const error = colors.red.bold;
function selectorToString(selectors, separator) {
separator = separator || ' '
return selectors
.reduce((prev, curr) => prev.concat(curr), [])
.join(separator)
}
@joemcgill
joemcgill / attachment_fields_to_edit_demo.php
Last active November 9, 2018 00:07
Attachment Fields to Edit Demo
<?php
add_filter( 'attachment_fields_to_edit', 'attachment_location_field', 10, 2 );
add_filter( 'attachment_fields_to_save', 'save_location_field', null, 2 );
function attachment_location_field( $form_fields, $post ) {
$field_value = get_post_meta( $post->ID, 'location', true );
$form_fields['location'] = array(
@joemcgill
joemcgill / WP_Image.md
Last active January 29, 2016 19:11
Ideas for a WP_Image Class in WordPress

Goals

  • Mimic the properties of WP_Post, and include additional metadata that's stored for images
    • _wp_attached_file
    • _wp_attachement_metadata
    • _wp_attachment_is_custom_background (maybe?)
  • Include methods for retrieving data associated with an image, possibly replacing the wp_get_attachment_image_ family of functions.
  • Save any reused data that would be used across functions so it's not calculated multiple times (e.g., wp_upload_dir(), see: #34359).
  • Maintain backwards compatability with the media.php image functions.
@joemcgill
joemcgill / 20150108-wustl-load-tests.md
Created January 9, 2016 15:43
WUSTL Server Load Testing 1/8/2015

1st Test – 40 users/1-4 sec/5min

40 concurrent users requesting every 1-4 seconds for 5 minutes avg was 1438 requests in 5 min (28,760/hr or 287.6/min or 4.8/sec)

  • First load is really slow ~7–9s
  • Once cache is warm things are really fast 11ms
  • Cache breaks are happening on every publish.
  • PHP seems to be the bottleneck
Mary:
* Recurrence is kind of wierd/confusing. Some tutorials might be nice.
* We need to double check venues and some other
Migration:
* Everyone is going through stories.
* Slideshows are cumbersome and requires a bunch of extra work.
* Do we need to add promos to old med school stories