Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Howells-Mead markhowellsmead

View GitHub Profile
@markhowellsmead
markhowellsmead / updatelive.sh
Created Apr 21, 2022
Bash script with coloured messaged
View updatelive.sh
#!/bin/bash
function cecho(){
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
NC="\033[0m" # No Color
printf "${!1}\n${2} ${NC}"
}
@markhowellsmead
markhowellsmead / PostFeaturedImage.php
Created Mar 11, 2022
WordPress Gutenberg: add preset size selector to core Post Featured Image block
View PostFeaturedImage.php
<?php
namespace SayHello\Theme\Block;
use WP_Block;
/**
* Core Post Featured Image block
* From plugin
*
@markhowellsmead
markhowellsmead / PostMoreSameCategory.php
Last active Mar 9, 2022
Gutenberg: server side render with editable title
View PostMoreSameCategory.php
<?php
namespace SayHello\Theme\Block;
use WP_Term;
/**
* More posts from same category as current post
*
* @author Say Hello GmbH <hello@sayhello.ch>
@markhowellsmead
markhowellsmead / extend_admin_search.php
Created Mar 3, 2022
Extend WordPress admin media search to include custom meta fields
View extend_admin_search.php
<?php
add_action( 'pre_get_posts', 'extend_admin_search' );
function extend_admin_search( $query ) {
$post_type = 'post';
$custom_fields = array("source",);
if( ! is_admin() )
return;
if ( $query->query['post_type'] != $post_type )
return;
@markhowellsmead
markhowellsmead / block.php
Created Feb 25, 2022
Use alignment in server-side rendered blocks for WordPress Gutenberg
View block.php
<?php
register_block_type('shb/demo', [
'attributes' => [
'align' => [
'type' => 'string',
'enum' => ['wide', 'full'],
]
],
@markhowellsmead
markhowellsmead / post_with_tag.js
Created Feb 25, 2022
Create a single tag, then create a post linked to that tag. Uses async/await.
View post_with_tag.js
const remote_domain = 'DOMAIN', // without trailing slash
application_password = 'APPLICATION PASSWORD',
username = 'USERNAME';
const headers = new Headers({
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa(username + ':' + application_password)
});
const makePost = async function() {
@markhowellsmead
markhowellsmead / remote_create_post.js
Last active Feb 25, 2022
Creates a post on a remote WordPress site, using the REST API and an application password
View remote_create_post.js
const remote_domain = 'https://example.org', // without trailing slash
application_password = 'Application password',
username = 'remote_user_name';
const body = JSON.stringify({
title: 'Post using REST API',
content: 'Post content using REST API',
status: 'publish'
});
@markhowellsmead
markhowellsmead / ThreeColumns.php
Last active Feb 18, 2022
Register a block pattern using PHP. Fits into the Theme structure of https://github.com/SayHelloGmbH/hello-roots/
View ThreeColumns.php
<?php
namespace SayHello\Theme\Pattern;
/**
* Manage single block pattern
*
* @author Say Hello GmbH <hello@sayhello.ch>
*/
class ThreeColumns
@markhowellsmead
markhowellsmead / GroupWithMediaText.php
Last active Feb 18, 2022
Register a block pattern using PHP. Fits into the Theme structure of https://github.com/SayHelloGmbH/hello-roots/
View GroupWithMediaText.php
<?php
namespace SayHello\Theme\Pattern;
/**
* Manage single block pattern
*
* @author Say Hello GmbH <hello@sayhello.ch>
*/
class GroupWithMediaText
@markhowellsmead
markhowellsmead / alignment-options.js
Created Feb 17, 2022 — forked from wpmark/alignment-options.js
Add alignment options for WordPress core blocks.
View alignment-options.js
// set alignment options for cover, video, and paragraph blocks.
wp.hooks.addFilter(
'blocks.registerBlockType',
'hd-theme/hd-theme',
function( settings, name ) {
if ( name === 'core/cover' || name === 'core/video' || name === 'core/paragraph' || name === 'core/list' ) {
return lodash.assign( {}, settings, {
supports: lodash.assign( {}, settings.supports, {
// allow support for full and wide alignment.
align: ['full', 'wide'],