Skip to content

Instantly share code, notes, and snippets.

View dgwyer's full-sized avatar
🏠
Working from home

David Gwyer dgwyer

🏠
Working from home
View GitHub Profile
@dgwyer
dgwyer / action-types.js
Created September 28, 2023 15:00 — forked from helgatheviking/action-types.js
Product Data Store Example
const TYPES = {
FETCH_FROM_API : "FETCH_FROM_API",
HYDRATE_PRODUCT: "HYDRATE_PRODUCT",
};
export default TYPES;
/**
* WordPress dependencies
*/
import { createReduxStore, register, controls } from '@wordpress/data';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
export const STORE_NAME = 'search-filter/settings';
const getUniqueKey = ( args ) => {
@dgwyer
dgwyer / index.js
Last active August 30, 2023 15:42
import { registerPlugin } from "@wordpress/plugins";
import { useState, useEffect, createPortal } from "@wordpress/element";
const SomeEditorPlugin = () => {
const [portalContainer, setPortalContainer] = useState(null);
useEffect(() => {
// Wait for the DOM element to be available
const container = document.querySelector("#some-element");
setPortalContainer(container);
@dgwyer
dgwyer / error-log.txt
Last active August 17, 2023 12:53
Test script run via a GitHb action to create InstaWP sites
Attempting to create site 1 of 10...
Site name: 1234-test-3B9gNalUoA
Sites created: Promise { <pending> }
New site created: {
status: true,
message: 'Site installation work in progress, Wait for installation.',
data: {
message: 'Site installation work in progress, Wait for installation.',
task_id: 'b037e201ddc9',
status: 1,
#!/bin/bash
# Number of posts to create
posts=100
# Paragraphs
p=2
# Create new posts and pages with random Lorem ipsum content inside paragraph blocks
curl -N http://loripsum.net/api/$p | sed '/^$/d' | sed 's/^/<\!-- wp:paragraph -->/' | sed 's/$/<\!-- \/wp:paragraph -->/' | wp post generate --count=$posts --post_content
#!/bin/bash
# Delete all posts for specified posts types
wp post delete $(wp post list --post_type='post,page,product,attachment' --format=ids) --force
#!/bin/bash
# Start the timer
start_time=$(date +%s)
# Vars
import_images=12
# 1. IMPORT MEDIA
import fs from 'fs';
import needle from 'needle';
import cryptojs from 'crypto-js';
import config from '../../../../caller/deploy.config.js';
export function deployZip() {
// Base 64 URL encode.
const base64_url_encode = function (str) {
str = Buffer.from(str).toString('base64');
str = str.replace(/=/g, '');
@dgwyer
dgwyer / what-forces-layout.md
Created October 19, 2022 14:00 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
<?php
/**
* Plugin Name: Post Meta Registration Test
* Version: 0.1.0
* Text Domain: post-meta-registration-test
*/
function register_post_meta_1() {
register_post_meta( 'post', 'test_post_data1', array(
'show_in_rest' => true,