Skip to content

Instantly share code, notes, and snippets.

Your First Block

To make things simple, we're going to make a semi-structured way to display a mailing address.

We're going to start with a file tree that looks like this:

address-block
  ├ blocks
  | ├ address.jsx
@brianhogg
brianhogg / gist:b87c216dde537ecaccdc5063858d0c3f
Last active October 30, 2018 21:16 — forked from davekiss/gist:e2b5beb37b3a1a93a3dddcf43ce51ce9
Display notice in EDD if email already exists and not logged in
<?php
/*
Plugin Name: EDD Prompt Login On Checkout
Plugin URI: http://brianhogg.com/
Description: Prompt login if email exists
Author: Dave Kiss
Version: 1.0.0
Author URI: http://brianhogg.com
License: GPL2
*/
@pento
pento / php-block.js
Last active February 29, 2024 01:31
Converting a shortcode to a block: this method is fast to do, but a mediocre UX. You should only use this as a stopgap until you can implement a full block UI.
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
/*
* Here's where we register the block in JavaScript.
@EricBusch
EricBusch / wordpress_table_column_exists.php
Last active November 6, 2022 11:05
A function for WordPress to check if a column exists in a database table or not. Returns true if a database table column exists. Otherwise returns false.
<?php
/**
* Returns true if a database table column exists. Otherwise returns false.
*
* @link http://stackoverflow.com/a/5943905/2489248
* @global wpdb $wpdb
*
* @param string $table_name Name of table we will check for column existence.
* @param string $column_name Name of column we are checking for.
@contemplate
contemplate / functions.php
Last active November 14, 2023 12:59
WooCommerce - Allow guest checkout for certain products when Guest checkout is Disabled globally
/*--------------------------------------
Woocommerce - Allow Guest Checkout on Certain products
----------------------------------------*/
// Display Guest Checkout Field
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
/**
* This Google Sheets script keeps data in the specified column sorted any time
* the data changes.
*
* After much research, there wasn't an easy way to automatically keep a column
* sorted in Google Sheets, and creating a second sheet to act as a "view" to
* my primary one in order to achieve that was not an option. Instead, I
* created a script that watches for when a cell is edited and triggers
* an auto sort.
*
@hofmannsven
hofmannsven / README.md
Last active May 3, 2024 15:30
Git CLI Cheatsheet
@helen
helen / repeatable-fields-metabox.php
Created January 11, 2012 04:42
Repeating Custom Fields in a Metabox
<?
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
*
* From a bespoke system, so currently not modular - will fix soon
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function hhs_get_sample_options() {