Skip to content

Instantly share code, notes, and snippets.

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 Sep 14, 2018
An example Gutenberg package.json file
View package.json
{
"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 Sep 14, 2018
A Gutenberg webpack configuration file
View webpack.config.js
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 Sep 11, 2018
An example of an article excerpt you should be able to create with JavaScript
View article.html
<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 Mar 10, 2020
This function hooks in when Gravity Forms Registers a New User and then Adds them to a LearnDash Group using ld_update_group_access
View gravityforms-learndash-groups.php
<?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 Apr 13, 2018
Example of how to set default blocks for a post in Gutenberg with block templates.
View gutenberg-block-tempalte-example.php
<?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 Apr 4, 2018
Logs out the React library (no React DOM)
View react-book-ch3-react-object.html
<!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 Feb 20, 2018
Example of how to import files using webpack external aliases
View import-using-alias.js
// 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 Sep 17, 2019
An example of a webpack config for Gutenberg block development using externals
View gutenberg-webpack-config-with-externals.js
/**
* 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 Feb 20, 2018
An example package.json for a Gutenberg block plugin
View gutenberg-package.json
{
"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 Dec 9, 2020
An example .babelrc file for working with Gutenberg
View gutenberg-babelrc
{
"presets": [ "@wordpress/default" ],
"plugins": [
"transform-object-rest-spread",
[
"transform-react-jsx",
{
"pragma": "wp.element.createElement"
}
],