Should a WordPress plugin polyfill the global JS environment?

Does WordPress ship any polyfills of its own for the global environment? No, as far as I remember WP core doesn’t ship with any polyfills. What are best practices around handling/shipping polyfills in WordPress plugins? The typical practice for JS in public WP extensions is to either: stick with core–provided scripts/environment; isolate your code and … Read more

@wordpress/components Button variants not styled

The WordPress components docs are pulled from the development branch of the repository, meaning they may describe features and functionality that have yet to be released. With the current version of the library used in WordPress, you declare the variant with the isPrimary, isSecondary, or isTertiary property: <Button isSecondary onClick={open}> Select image… </Button>

Only loads on the contact template page

First a bit of advise (since the solution is based on it) – always “enqueue” your scripts, don’t just add them in the footer. Read this, for example . Now the solution for loading scripts on specific template, since this is what you asked for: function enqueue_themescrits() { if ( is_page_template(‘contact.php’) ) { //the file … Read more

How do I access site and block editor state data and use `useSelect()` or `withSelect()` to bind it to my components?

✨ Intro to the Gutenberg Data Module ✨ Gutenberg’s core data model shares a lot of the API and ideology of the state-management library Redux, with a number of differences. Reading up on Redux can provide a lot of insight into how Gutenberg’s data management functions. This lecture will be on the final exam. Application … Read more

How to get value of selected page template in Gutenberg editor?

I slightly modified SkyShab’s code, because it fired template change event on page load and it didn’t fire when template was changed to default (since getEditedPostAttribute( ‘template’ ) is then ”, which equals to null when testing for template change) const { select, subscribe } = wp.data; class PageTemplateSwitcher { constructor() { this.template = null; … Read more