Skip to content

Instantly share code, notes, and snippets.

@Lovor01
Last active April 20, 2024 10:35
Show Gist options
  • Save Lovor01/0e6e599411624fac1952fabe96797e4d to your computer and use it in GitHub Desktop.
Save Lovor01/0e6e599411624fac1952fabe96797e4d to your computer and use it in GitHub Desktop.
Block editor secrets

Core secrets

Block scripts and styles enqueueing

registration

wp-includes/blocks.php - register_block_from_metadata

enqueueing

wp-includes/script-loader- wp_enqueue_registered_block_scripts_and_styles

Inspect entities.js

Entites.js hold static and dynamic selectors. Dynamic are created with prefixes and rootEntitiesConfig

useEntityRecord & EntityRecords

useEntityProp

const [ link, setLink ] = useEntityProp( 'postType', postType, 'link', postId );
  1. Entity type
  2. Entity type name
  3. Entity field
  4. post ID (current if omitted)

BlockControls

There is a secret group attribute on BlockControls - default group='default'

Predefined groups: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/block-controls/groups.js

Get post type

select core/editor getCurrentPostType()

// useEntityProp
/**
 * Hook that returns the value and a setter for the
 * specified property of the nearest provided
 * entity of the specified type.
 *
 * @param {string} kind  The entity kind.
 * @param {string} name  The entity name.
 * @param {string} prop  The property name.
 * @param {string} [_id] An entity ID to use instead of the context-provided one.
 *
 * @return {[*, Function, *]} An array where the first item is the
 *                            property value, the second is the
 *                            setter and the third is the full value
 * 							  object from REST API containing more
 * 							  information like `raw`, `rendered` and
 * 							  `protected` props.
 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment