Skip to content

Instantly share code, notes, and snippets.

View stokesman's full-sized avatar

Mitchell Austin stokesman

View GitHub Profile
@stokesman
stokesman / vite.config.js
Created October 24, 2023 18:56
Rudimentary Vite config that builds with WordPress dependency extraction
import { createHash } from 'crypto'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import {
defaultRequestToExternal,
defaultRequestToHandle
} from '@wordpress/dependency-extraction-webpack-plugin/lib/util.js'
import json2php from 'json2php'
import packageMeta from './package.json';
@stokesman
stokesman / classic-block-resticky.php
Created October 4, 2023 05:02
Plugin to workaround gutenberg issue #53477
<?php
/**
* Plugin Name: Classic Block Resticky
* Description: Ensures the classic block’s formatting toolbar is sticky when custom fields are present.
*/
add_action( 'admin_footer', function() {
// Bails unless on a block editor screen
if ( ! get_current_screen()->is_block_editor() ) return;
@stokesman
stokesman / masonry.patched.js
Created August 24, 2023 15:45
Masonry patched for cross-frame support
/*!
* Masonry PACKAGED v4.2.2-patch1
* Cascading grid layout library
* https://masonry.desandro.com
* MIT License
* by David DeSandro
*/
!function(t,e){"function"==typeof define&&define.amd?define("jquery-bridget/jquery-bridget",["jquery"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("jquery")):t.jQueryBridget=e(t,t.jQuery)}(window,function(t,e){"use strict";function i(i,r,a){function h(t,e,n){var o,r="$()."+i+'("'+e+'")';return t.each(function(t,h){var u=a.data(h,i);if(!u)return void s(i+" not initialized. Cannot call methods, i.e. "+r);var d=u[e];if(!d||"_"==e.charAt(0))return void s(r+" is not a valid method");var l=d.apply(u,n);o=void 0===o?l:o}),void 0!==o?o:t}function u(t,e){t.each(function(t,n){var o=a.data(n,i);o?(o.option(e),o._init()):(o=new r(n,e),a.data(n,i,o))})}a=a||e||t.jQuery,a&&(r.prototype.option||(r.prototype.option=function(t){a.isPlainObject(t)&&(this.options=a.extend(!0,this.options,t))}),a.fn[i]=function(t){if("string"==typeof t){
@stokesman
stokesman / columns-with-faux-grid-alignment.html
Last active August 19, 2023 21:26
WP: tedious way to align nested children
<!-- wp:columns {"verticalAlignment":"center","align":"wide"} -->
<div class="wp-block-columns alignwide are-vertically-aligned-center"><!-- wp:column {"verticalAlignment":"center"} -->
<div class="wp-block-column is-vertically-aligned-center"><!-- wp:cover {"dimRatio":50,"overlayColor":"cyan-bluish-gray","contentPosition":"center center","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="wp-block-cover__background has-cyan-bluish-gray-background-color has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:group {"layout":{"type":"flex","orientation":"vertical","justifyContent":"center"}} -->
<div class="wp-block-group"><!-- wp:heading {"textAlign":"center","style":{"layout":{"selfStretch":"fixed","flexSize":"2.5em"}},"fontSize":"large"} -->
<h2 class="wp-block-heading has-text-align-center has-large-font-size">Simple Question</h2>
<!-- /wp:heading -->
<!-- wp:paragraph {"align":"center","style":{"layout":{"selfStretch":"fixed","flexSize":"6em"}}
@stokesman
stokesman / block-library-disdialoged.php
Last active August 14, 2023 16:39
WP: hack to keep the Block library/Inserter open unless manually closed.
<?php
/**
* Plugin Name: Block Library Disdialoged
* Description: Hack to keep the Block library/Inserter open unless manually closed.
* Version: 0.2.0
* License: GPL-2.0-or-later
*/
add_action( 'admin_footer', function() {
// Bails unless on a block editor screen
@stokesman
stokesman / pasta.php
Last active December 7, 2021 22:33
WP insert new posts from remote WP
<?php
['body' => $payload] = wp_remote_get( '/wp-json/wp/v2/posts/?categories=10&per_page=20' );
$post_list = json_decode( $payload );
foreach ( $post_list as $post_data ) {
$post = [
'post_category' => [ 7 ],
'post_title' => $post_data->title->rendered,
'post_status' => 'publish',
'post_date' => $post_data->date,
@stokesman
stokesman / getScrollContext.js
Last active June 29, 2021 23:57
Find parent scrolling context from DOM element
function getScrollContext( node ) {
let at = node;
let hasOverflow = false;
while ( at.parentNode !== at.ownerDocument ) {
at = at.parentNode;
if ( at.clientHeight < at.scrollHeight ) {
hasOverflow = true;
break;
}
}
@stokesman
stokesman / svg-format-demo.js
Last active November 3, 2023 22:54
Use the Format API to add SVG in RichText
( ( {
blockEditor: { RichTextToolbarButton },
element: { createElement },
richText: { insertObject, registerFormatType, remove },
} ) => {
const formatName = 'svg-format-demo/one';
const format = {
title: 'SVG Format Demo',
tagName: 'u',
contentEditable: false,
@stokesman
stokesman / index.js
Created August 11, 2020 01:16
Repro Woe is xlink:href in gutenberg
//tambien nada
@stokesman
stokesman / .block
Created July 25, 2016 22:11 — forked from mbostock/.block
Gradient Along Stroke
license: gpl-3.0