Skip to content

Instantly share code, notes, and snippets.

View johnstonphilip's full-sized avatar

Phil Johnston johnstonphilip

View GitHub Profile
import ReactDOM from "react-dom";
import {
BlockEditorProvider,
BlockList,
WritingFlow,
ObserveTyping,
BlockEditorKeyboardShortcuts,
storeConfig as blockEditorStoreConfig,
BlockInspector,
<?php
/**
* Modify the rendered output of any block.
*
* @param string $block_content The normal block HTML that would be sent to the screen.
* @param array $block An array of data about the block, and the way the user configured it.
*/
function my_custom_render( $block_content, $block ) {
<?php
define('SHORTINIT', true);
require 'wp-load.php';
global $wpdb;
$post_id_to_get = 2;
$result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id_to_get ) );
echo json_encode( $result );
die();
@johnstonphilip
johnstonphilip / order-posts-in-term-by-term-order
Created October 7, 2023 17:16
This will make posts get queried in order by the term_order defined for the post in the term_relationships table
function my_order_posts_in_term_by_term_order( $orderby, $query ) {
global $wpdb;
return "$wpdb->term_relationships.term_order ASC";
}
add_filter( 'posts_orderby', 'my_order_posts_in_term_by_term_order', 10, 2 );
<?php
define('SHORTINIT', true);
require 'wp-load.php';
// Require the minimum to verify the current user -----------------------------------------------
require_once ABSPATH . WPINC . '/default-constants.php';
require_once ABSPATH . WPINC . '/class-wp-user.php';
require_once ABSPATH . WPINC . '/user.php';
require_once ABSPATH . WPINC . '/pluggable.php';
@johnstonphilip
johnstonphilip / sync-global-dependency-versions-wp-plugin.sh
Last active June 20, 2024 01:26
WordPress Plugin Helper: Sync plugin dependency packages with WP core for external globals like react, react-dom, any @WordPress package, etc
#!/bin/bash
# This file is designed to be run in the root of a plugin directory, and will sync the global packages in the package.json file
# with the versions used in the "Tested up to" WordPress core version, as set in the plugin's readme.txt file.
# Get the "Tested up to" version from the plugin's readme.txt file.
readme_file="$PWD/readme.txt"
tested_up_to=$(grep "Tested up to: " "$readme_file" | sed 's/Tested up to: //')
# If $tested_up_to has a value, then try syncing the versions of the global packages.