Skip to content

Instantly share code, notes, and snippets.

View atimmer's full-sized avatar

Anton Timmermans atimmer

View GitHub Profile
CREATE TABLE `wp_yoast_seo_links` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`post_id` bigint(20) unsigned NOT NULL,
`target_post_id` bigint(20) unsigned NOT NULL,
`type` varchar(8) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `link_direction` (`post_id`,`type`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
@atimmer
atimmer / machine.js
Created August 2, 2020 19:30
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions

Gutenberg externals

All packages that the modern WordPress JavaScript uses are available as @wordpress/ packages. This means that a simple npm install @wordpress/data will get you the data module. The same that is used in WordPress. The challenge with this is that this code will be duplicated between WordPress and your plugin. Bundlers like webpack and browserify include all the code in @wordpress/data inside your built JavaScript file. To remedy this you can configure your bundler to use the available package from a global variable instead. For @wordpress/data this global is wp.data.

Your PHP configuration needs to be changed to accomodate this. When you use wp.data you need to make that script a dependency of your script. You can do this by providing it in the dependency array of wp_register_script:

wp_register_script( 'script-handle', 'path-to-script.js', array( 'wp-data' );
<?php
namespace Yoast\YoastCom\Core\WordPress\Integration\WooCommerce;
use Yoast\YoastCom\Core\WordPress\Helper\Shop_Helper;
use Yoast\YoastCom\Core\WordPress\Integration;
use Yoast\YoastCom\Core\WordPress\Integration\Dependencies\Dependency;
use Yoast\YoastCom\Core\WordPress\Integration\Dependencies\WooCommerce_Dependency;
final class Customer_On_All_Sites implements Integration {