Skip to content

Instantly share code, notes, and snippets.

View ryanwelcher's full-sized avatar
:octocat:
Working from home

Ryan Welcher ryanwelcher

:octocat:
Working from home
View GitHub Profile
@ryanwelcher
ryanwelcher / edit.js
Created October 12, 2023 18:24
Using the useBlockEditingMode hook
/**
* WordPress Dependencies
*/
import {
useBlockProps,
useBlockEditingMode,
RichText,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
@ryanwelcher
ryanwelcher / edit.js
Created January 20, 2023 15:58
Term selector
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { PanelBody, ComboboxControl } from '@wordpress/components';
import { useEntityRecords } from '@wordpress/core-data';
export default function Edit( {
attributes: { blockTaxonomyTerm },
@ryanwelcher
ryanwelcher / theme.json
Created February 8, 2022 17:30
When adding theme.json to an existing Classic Theme, these settings will stop the default color and typography controls from being enabled.
{
"$schema": "http://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"layout": {
"contentSize": "750px"
},
"color": {
"background": false,
"custom": false,
@ryanwelcher
ryanwelcher / block.json
Last active September 15, 2022 17:05 — forked from MonteLogic/block.json
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "create-block/mol-custom-blocks",
"version": "0.1.0",
"title": "Monte Logic's Custom Blocks",
"category": "text",
"icon": "flag",
"description": "A Gutenberg block to show your pride! This block enables you to type text and style it with the color font Gilbert from Type with Pride.",
"attributes": {
@ryanwelcher
ryanwelcher / templates.php
Last active July 19, 2022 09:50
Dynamically Assign Templates In Gutenberg
<?php
/**
* Defines the block templates.
*
* @todo add references to the custom blocks
*
* @return array
*/
function get_block_templates() {
return [
const { useState } = wp.element;
const { ServerSideRender } = wp.components;
const { BlockControls, InnerBlocks } = wp.blockEditor;
import LivePreviewButton from '../../components/live-preview-button';
const EditComponent = ( props ) => {
const [ preview, setPreview ] = useState( false );
const { attributes, clientId, name } = props;
return (
@ryanwelcher
ryanwelcher / query-loop-locked.html
Created February 8, 2022 16:43
A Block Theme Template Part that provides a Query Loop block with locked Post Title and Feature Image blocks.
<!-- wp:query {"queryId":1,"query":{"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","sticky":""}} -->
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true,"lock":{"remove":true}} /-->
<!-- wp:post-featured-image {"isLink":true,"align":"wide","lock":{"remove":true}} /-->
<!-- wp:post-date /-->
<!-- wp:post-excerpt /-->
<!-- wp:separator -->
<hr class="wp-block-separator"/>
<!-- /wp:separator -->
<!-- /wp:post-template -->
@ryanwelcher
ryanwelcher / wordpress-6-0-block-locking.php
Last active July 19, 2022 09:35
WordPress 6.0: Examples on how to restrict block locking in the UI
<?php
/**
* Examples on restricting when blocks can be locked using the UI.
* Based on the example provided by @mamaduka in https://github.com/WordPress/gutenberg/pull/39566
*
* @see https://developer.wordpress.org/reference/hooks/block_editor_settings_all/
*/
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
@ryanwelcher
ryanwelcher / example-pattern.php
Last active July 19, 2022 09:32
WordPress 6.0 Example: Example pattern PHP file to register a block pattern in the /patterns directory
<?php
/**
* Title: Example Block Pattern ( required field )
* Slug: block-pattern-example (required field)
* Description: This is an example of how to use the new /patterns directory to register a block pattern.
* Categories: featured, text
* Viewport Width: 800
* Keywords: example, block-theme, block-pattern
* Block Types: core/template-part/footer, core/post-content
* Inserter: yes