The WordPress coreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. development team builds WordPress! Follow this site for general updates, status reports, and the occasional code debate. There’s lots of ways to contribute:
Found a bugbugA bug is an error or unexpected result. Performance improvements, code optimization, and are considered enhancements, not defects. After feature freeze, only bugs are dealt with, with regressions (adverse changes from the previous version) being the highest priority.?Create a ticket in the bug tracker.
WordPress 5.4 introduces a new package called @wordpress/keyboard-shortcuts to centralize the registration/removal and documentation of the available keyboard shortcuts in the blockBlockBlock is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. editor screen.
Registering shortcuts
You should register keyboard shortcuts when you load the screen/pluginPluginA plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party for the first time, by calling the registerShortcut action.
wp.data.dispatch( 'core/keyboard-shortcuts' ).registerShortcut( {
// Shortcut name (identifier)
name: 'plugin/shortcut-name',
// Catergory (global, block or selection)
category: 'block',
// Description
description: 'Short description of your shortcut.',
// The key combination used to trigger the shortcut
// Could be just a single character or a character with
// a modifier.
keyCombination: {
modifier: 'primaryAlt',
character: 't',
},
// Some shortcuts can be triggered using several
// key combination, the aliases array is used to define
// the alternative combinations
aliases: [
{
modifier: 'primary',
character: 'i',
},
],
} );
Registering a shortcut automatically adds it to the keyboard shortcuts help modal, where users can find it.
Implementing the keyboard shortcut behavior
The @wordpress/keyboard-shortcuts package also provides the useShortcutReactReactReact is a JavaScript library that makes it easy to reason about, construct, and maintain stateless and stateful user interfaces. https://reactjs.org/. hook to define the behavior triggered by the keyboard shortcuts.
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import { useCallback } from '@wordpress/element';
const MyComponent = () => {
useShortcut(
// Shortcut name
'plugin/shortcut-name',
// Shortcut callback
useCallback(
( event ) => {
// Do something when the keyboard
// shortcut is triggered
},
[]
)
);
}
Using this React hook instead of a custom implementation comes with a few advantages:
If the shortcut is unregistered by a third-party plugin, the callback is just ignored.
The shortcut key combination can be modified at runtime and the callback will still be called properly.
Removing existing shortcuts
Registered shortcuts can also be unregistered (and potentially replaced) by third-party plugins
You must be logged in to post a comment.