Skip to content

Instantly share code, notes, and snippets.

@dlh01
dlh01 / traverse-reshape-example.php
Created February 1, 2023 03:00
traverse/reshape example
<?php
$arr = [
'apples' => [
'red' => [
'gala',
'mcintosh',
],
'green' => [
'granny_smith',
<?php
function flatten_blocks( array $blocks ) {
reset( $blocks );
$out = [];
while ( $block = array_shift( $blocks ) ) {
$out[] = $block;
const useEffectOnceOnDemand = (effect) => {
const [count, setCount] = useState(0);
useEffect(() => {
if (1 === count) {
effect();
}
});
return () => setCount((prev) => Math.min(2, prev + 1));
@dlh01
dlh01 / block-content.html
Last active May 25, 2020 00:33
The blocks in the Gutenberg plugin's demo post (and then some) as raw HTML, a PHP array of parsed blocks, and a JSON object of the PHP array.
<!-- wp:cover {"url":"https://cldup.com/Fz-ASbo2s3.jpg","className":"alignwide"} -->
<div class="wp-block-cover has-background-dim alignwide" style="background-image:url(https://cldup.com/Fz-ASbo2s3.jpg)"><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Of Mountains &amp; Printing Presses</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->
<!-- wp:paragraph -->
<p>The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of <em>pieces of content</em>—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you&#8217;ll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting.</p>
<!-- /wp:paragraph -->
@dlh01
dlh01 / wp-cli.php
Last active November 27, 2023 20:53
wp-cli command docs
<?php
/**
* Print syndication debugging information about a post.
*
* ## OPTIONS
*
* <id>
* : Post ID.
*
@dlh01
dlh01 / header.php
Last active May 8, 2017 21:45
Try to stop Chrome from caching WordPress feeds during development
<?php
add_action( 'send_headers', function ( $wp ) {
if ( ! empty( $wp->query_vars['feed'] ) ) {
header( 'Cache-Control: no-cache, no-store, must-revalidate' );
}
}, 100 );
<?php
/*
Plugin Name: Members
*/
function member_init() {
register_post_type( 'member', array(
'labels' => array(
'name' => __( 'Members', 'foobar' ),
'singular_name' => __( 'Member', 'foobar' ),
@dlh01
dlh01 / distribute_user.sh
Last active June 27, 2023 20:25
WP-CLI: Add a user to all sites in a network
#!/bin/bash
# Usage: ./distribute_user.sh [username] [role]
ARGS="$@"
echo "Adding user $1 as $2 to all sites"
SITES=$(wp site list --field=url --format=csv)
for site in $SITES
do
@dlh01
dlh01 / apigen.sh
Created December 16, 2013 01:42
10.9 + Homebrew PHP + PEAR ApiGen quick fix for error "PHP Warning: require(Texy.php): failed to open stream: No such file or directory in /usr/local/Cellar/php54/5.4.11/bin/apigen on line 48"
sudo ln -s /usr/local/Cellar/php54/5.4.11/lib/php/texy/src/texy.php /usr/local/Cellar/php54/5.4.11/lib/php
@dlh01
dlh01 / bwp_recent_comments_template.php
Created September 27, 2013 02:07
BetterWP Recent Comments: Allows you to define the "Template for comments" from a plugin or theme
add_action( 'wp_head', 'my_bwp_recent_comments_template' );
function my_bwp_recent_comments_template() {
global $bwp_rc;
$bwp_rc->options['template_comment'] = '<p>My template here</p>';
}