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 / learndash-course-completed-redirect.php
Created June 2, 2017 18:36
This hook let's you redirect to a custom page when a LearnDash course is completed.
<?php
function custom_course_completed_redirect($link, $course_id) {
$link = get_post_field( 'post_name', $course_id );
//You can change the link here
return '/congrats/' . $link;
}
add_filter("learndash_course_completion_url", custom_course_completed_redirect, 5, 2);
@zgordon
zgordon / kill-apache-mac
Created December 4, 2017 04:06
Kills Mac apache server so DesktopServer can run
sudo apachectl -k stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist  
@zgordon
zgordon / keywords-settings-for-gutenberg-block.js
Created December 8, 2017 00:54
Use the "keywords" settings parameter to add additional search keywords for your block.
// Import __ from i18n internationalization library
const { __ } = wp.i18n;
// Import registerBlockType() from block building libary
const { registerBlockType } = wp.blocks;
// Import the element creator function (React abstraction layer)
const el = wp.element.createElement;
/**
@zgordon
zgordon / registerblock-default-icon.js
Last active December 8, 2017 01:00
How to register a new Gutenberg visual editor block in JavaScript
// Import __ from i18n internationalization library
const { __ } = wp.i18n;
// Import registerBlockType() from block building libary
const { registerBlockType } = wp.blocks;
// Import the element creator function (React abstraction layer)
const el = wp.element.createElement;
/**
* Register Block using default icon options.
@zgordon
zgordon / block-architecture-for-plugins
Last active December 12, 2017 02:24
Suggested block architecture for working WordPress plugins.
/plugin-root
/blocks
/block-name
editor.css
index.js
index.php
style.css
/another-block-name
editor.css
index.js
@zgordon
zgordon / functions-block-include-example.php
Last active December 12, 2017 02:33
Example of including specific blocks from a main theme index file
// Require a block
require_once( get_template_directory() . '/blocks/block-name/index.php');
// Require another block
require_once( get_template_directory() . '/blocks/another-block-name/index.php');
@zgordon
zgordon / block-architecture-for-themes
Last active December 18, 2017 10:05
Suggested block architecture for working WordPress themes (without webpack). See my block architecture for themes with webpack.
/theme-root
/blocks
/block-name
editor.css // Option for editor only styles
index.js // Main block JS file
index.php // Enqueues the block JS and CSS
style.css // Frontend and editor styles
/another-block-name
editor.css
index.js
@zgordon
zgordon / block-architecture-for-themes-with-webpack
Created December 18, 2017 10:06
Suggested block architecture for working WordPress themes when using webpack.
/theme-root
/blocks
/block-name
editor.css // Option for editor only styles
index.js // Main block JS file
index.php // Enqueues the block JS and CSS
style.css // Frontend and editor styles
/another-block-name
editor.css
index.js
@zgordon
zgordon / webpack-config-for-gutenberg-blocks.js
Last active December 18, 2017 16:44
A webpack.config.js file for working with Gutenberg [In Development, not yet for production]
const path = require( 'path' );
// const BrowserSyncPlugin = require( 'browser-sync-webpack-plugin' );
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: '../css/blocks.style.css',
} );
@zgordon
zgordon / registerBlockType-global-variable.js
Last active December 28, 2017 09:04
Shortcut to make registerBlockType easily available when creating WordPress blocks.
// Get registerBlockType() from wp.blocks in the global scope
const { registerBlockType } = window.wp.blocks;