Skip to content

Instantly share code, notes, and snippets.

View zgordon's full-sized avatar
🎓
Prepping a Course on Gatsby, GraphQL & WordPress

Zac Gordon zgordon

🎓
Prepping a Course on Gatsby, GraphQL & WordPress
View GitHub Profile
@zgordon
zgordon / package.json
Created September 14, 2018 16:17
An example Gutenberg package.json file
{
"name": "cta-block-example",
"version": "1.0.0",
"license": "MIT",
"main": "blocks/index.js",
"scripts": {
"dev": "cross-env BABEL_ENV=default webpack --watch",
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack -p"
},
"devDependencies": {
@zgordon
zgordon / webpack.config.js
Created September 14, 2018 16:16
A Gutenberg webpack configuration file
const path = require( 'path' );
const webpack = require( 'webpack' );
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
// Set different CSS extraction for editor only and common block styles
const blocksCSSPlugin = new ExtractTextPlugin( {
filename: './assets/css/blocks.style.css',
} );
const editBlocksCSSPlugin = new ExtractTextPlugin( {
filename: './assets/css/blocks.editor.css',
@zgordon
zgordon / article.html
Created September 11, 2018 13:30
An example of an article excerpt you should be able to create with JavaScript
<article class="post">
<h2 class="entry-title"><a href="#">Title</a></h2>
<div class="entry-excerpt">
<p>Excerpt here...</p>
</div>
</article>
@zgordon
zgordon / gravityforms-learndash-groups.php
Last active March 10, 2020 17:17
This function hooks in when Gravity Forms Registers a New User and then Adds them to a LearnDash Group using ld_update_group_access
<?php
add_action( 'gform_activate_user', 'apply_learndash_group', 10, 3 );
function apply_learndash_group( $user_id, $user_data ) {
// Change to be group ID for your group
$group_id = XXXX;
@zgordon
zgordon / gutenberg-block-tempalte-example.php
Created April 13, 2018 18:04
Example of how to set default blocks for a post in Gutenberg with block templates.
<?php
function wpvipblocks_templates( $args, $post_type ) {
if ( $post_type == 'post' ) {
$args['template_lock'] = true;
$args['template'] = [
[
'core/heading', [
'placeholder' => 'Add heading here.',
@zgordon
zgordon / react-book-ch3-react-object.html
Created April 4, 2018 13:52
Logs out the React library (no React DOM)
<!DOCTYPE html>
<html>
<head>
<title>Core React Library</title>
</head>
<body>
</body>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script type="text/javascript">
@zgordon
zgordon / import-using-alias.js
Created February 20, 2018 19:49
Example of how to import files using webpack external aliases
// Example of how to deconstruct registerBlockType without externals
const { registerBlockType } = wp.blocks;
// Example of how to import wp.blocks using webpack externals
import { registerBlockType } from "@wordpress/blocks";
@zgordon
zgordon / gutenberg-webpack-config-with-externals.js
Last active November 19, 2021 12:25
An example of a webpack config for Gutenberg block development using externals
/**
* External dependencies
*/
// Load webpack for use of certain webpack tools and methods
const webpack = require( 'webpack' );
// For extracting CSS (and SASS) into separate files
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
// Main CSS loader for everything but blocks..
@zgordon
zgordon / gutenberg-package.json
Last active February 20, 2018 18:06
An example package.json for a Gutenberg block plugin
{
"name": "ex6-events",
"version": "1.0.0",
"scripts": {
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
"dev": "cross-env BABEL_ENV=default webpack --watch"
},
"browserslist": [
"extends @wordpress/browserslist-config"
],
@zgordon
zgordon / gutenberg-babelrc
Last active July 22, 2021 08:34
An example .babelrc file for working with Gutenberg
{
"presets": [ "@wordpress/default" ],
"plugins": [
"transform-object-rest-spread",
[
"transform-react-jsx",
{
"pragma": "wp.element.createElement"
}
],