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
Last active November 4, 2024 15:33
YT embed
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { TextControl } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { useBlockProps } from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';
@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 / 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 / block.json
Created May 20, 2022 17:32
Defining default values for Background color, text color, link color, padding and margin for custom blocks
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "create-block/block-supports-test",
"version": "0.1.0",
"title": "Block Supports Test",
"category": "widgets",
"icon": "smiley",
"description": "Example block written with ESNext standard and JSX support – build step required.",
"attributes":{
@ryanwelcher
ryanwelcher / webfonts-tt2-example.json
Created April 29, 2022 14:14
WordPress 6.0 Example: Webfonts API Registering a font from theme.json
"fontFamilies": [
{
"fontFamily": "-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif",
"name": "System Font",
"slug": "system-font"
},
{
"fontFamily": "\"Source Serif Pero\", serif",
"name": "Source Serif Pero",
"slug": "source-serif-pero",
@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
@ryanwelcher
ryanwelcher / wp-6-0-suggested-block-pattern.php
Created April 28, 2022 14:44
WordPress 6.0 Example: Allowing a block patter to be show as a suggestion on new Pages.
<?php
/**
* Example showing how to allow a block pattern to be shown as a suggested pattern for new Pages.
*/
add_action(
'init',
function() {
register_block_pattern(
'block-pattern-suggestion-example',
array(
@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 / 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,