Skip to content

Instantly share code, notes, and snippets.

@lgladdy
lgladdy / hello-taylor.php
Last active August 29, 2016 18:15
A WordPress plugin to replace Hello Dolly lyrics with the infinitely better Taylor Swift.
<?php
/*
Plugin Name: Hello Taylor
Plugin URI: https://gist.github.com/lgladdy/9e1a7303c6a6bf43b9b1
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in <strike>two</strike> words sung most famously by <strike>Louis Armstrong: Hello, Dolly.</strike>Taylor Swift. When activated you will randomly see a lyric from <strike><cite>Hello, Dolly</cite></strike><cite>Taylor Swift</cite> in the upper right of your admin screen on every page.
Author: Liam Gladdy (based on Hello Dolly by Matt Mullenweg)
Version: 1.1
Author URI: http://www.twitter.com/lgladdy & http://ma.tt/
*/
@lgladdy
lgladdy / adLDAP-group_info.php
Created August 14, 2015 07:37
Rewrite group_info to query a group for more than 1500 people in a group on WS 2012 DCs
public function group_info($group_name,$fields=NULL){
if ($group_name===NULL){ return (false); }
if (!$this->_bind){ return (false); }
if (stristr($group_name, '+')) {
$group_name=stripslashes($group_name);
}
$filter="(&(objectCategory=group)(name=".$this->ldap_slashes($group_name)."))";
//echo ($filter."!!!<br>");
@lgladdy
lgladdy / composer.json
Last active March 12, 2016 20:06
An example laravel 5.2 composer.json that supports the Mondo API inside orison's oauth-5-laravel. Note the repositories key, and the "dev-master as 0.3" for lusitanian/oauth. Update, then follow lusitanian/oauth's docs.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"lusitanian/oauth": "dev-master as 0.3",
function get_responsive_image_tag_for_attachment($attachment_id, $requested_size) {
$data = get_responsive_image_sizes_for_size($requested_size);
$srcset = [];
foreach($data as $image) {
$image_data = wp_get_attachment_image_src($attachment_id, $image);
if ($requested_size == $image) {
$src = $image_data[0];
}
$srcset[] = $image_data[0].' '.$image_data[1].'w';
}
@lgladdy
lgladdy / wrap_jetpack_sharing.php
Created September 28, 2017 13:03
If you're using a build process to manage compilation of multiple javascript files on WordPress and getting errors from jetpack's sharing JS because jQuery isn't ready yet, you can use the following to wrap it in a handler which only inits after the DOM is ready
add_action('wp_footer', 'wrap_jetpack_sharing', 18);
function wrap_jetpack_sharing() {
global $wp_scripts;
$a = $wp_scripts->get_data('sharing-js','after');
$data = 'document.addEventListener( "DOMContentLoaded", function() { ';
$data .= implode("\n", $a);
$data .= ' }, false );';
$script[] = $data;
@lgladdy
lgladdy / assets.php
Last active August 23, 2018 13:52
Add zurb foundation widescreen/responsive-embed code to gutenberg video blocks.
function foundation_gutenberg_wrappers()
{
if (defined('WP_DEBUG') && WP_DEBUG) {
$gutenberg_file = '/js/raw/gutenberg.js?no_cache=' . time();
} else {
$gutenberg_file = '/js/raw/gutenberg.js';
}
wp_enqueue_script('foundation-gutenberg-extensions', get_template_directory_uri() . $gutenberg_file, array('wp-blocks'));
}
add_action('enqueue_block_editor_assets', 'foundation_gutenberg_wrappers');
@lgladdy
lgladdy / tailwind.config.js
Last active April 3, 2024 00:36
A tailwind plugin for generating WordPress block editor (Gutenberg) color css styles from the tailwind palette
const _ = require('lodash')
const plugin = require('tailwindcss/plugin')
plugins: [
plugin(function({ addComponents, theme }) {
const colors = theme('colors', {})
const exclude = ['transparent', 'current']
const paletteColors = []
for (const [key, value] of Object.entries(colors)) {
@lgladdy
lgladdy / acf-use-editor-palette.js
Created July 22, 2021 07:02
Set the color picker palette to match the block editor's
acf.addFilter('color_picker_args', function (args) {
const settings = wp.data.select( "core/editor" ).getEditorSettings();
let colors = settings.colors.map(x => x.color);
args.palettes = colors;
return args;
});
//block.json
{
"name": "simple-test-block",
"title": "Simple Test Block",
"description": "Simple Test Block",
"category": "theme",
"icon": "admin-comments",
"acf": {
"mode": "preview",
"renderTemplate": "render.php"
@lgladdy
lgladdy / acf-shortcode-query-loop-support.php
Last active December 11, 2023 19:54
This code sample enables support for the ACF shortcode inside a query loop by overriding the default shortcode block renderer with one which will inject the correct Post ID into the shortcode parameters
<?php
add_filter( 'render_block_core/shortcode', 'test_acf_shortcode_render', 10, 3);
function test_acf_shortcode_render( $content, $parsed_block, $block ) {
$content = preg_replace_callback( '/\[acf\s.*?\]/', 'acf_inject_query_loop_post_ID', $content );
return $content;
}
function acf_inject_query_loop_post_ID( $match ) {
return str_replace( '[acf', '[acf post_id="' . get_the_ID() . '"', $match[0] );