Skip to content

Instantly share code, notes, and snippets.

@florianbrinkmann
florianbrinkmann / index.js
Last active October 24, 2024 11:59
Gutenberg FormTokenField block with posts as source
/**
* External dependencies
*/
const { isUndefined, pickBy } = lodash;
/**
* WordPress dependencies
*/
const {
registerBlockType,
@MogulChris
MogulChris / gist:8fa67eedf01ef759e92e33a8e784aaa0
Created October 15, 2019 20:25
WooCommerce programmatically create variations from all attributes
<?php
/*
WooCommerce has a handy feature in the admin UI to "Create variations from all attributes".
To do this programmatically (as of WooCommerce v3.7.0) use a modified version of link_all_variations() found in woocommerce/includes/class-wc-ajax.php
*/
function myplugin_create_variations($product_id){
wc_maybe_define_constant( 'WC_MAX_LINKED_VARIATIONS', 50 );
wc_set_time_limit( 0 );
@jherax
jherax / arrayFilterFactory.1.ts
Last active July 18, 2024 15:02
Filters an array of objects with multiple match-criteria.
type FilterOperator = 'AND' | 'OR';
type FiltersBy<T> = {
[K in keyof T]?: (value: T[K]) => boolean;
};
/**
* Factory function that creates a specialized function to filter
* arrays, by validating all filters (AND operator),
* or validating just one of the filters (OR operator).
* @param operator Method to validate all filters: AND, OR