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 / gist-oembed-wordpress
Created June 15, 2015 04:45
oEmbed Gist into WordPress
wp_embed_register_handler(
'github-gist',
'/https:\/\/gist\.github\.com\/([^\/]+)\/([^\/]+)/',
function($matches, $attr, $url, $rawattr) {
$embed = "<script src=\"{$url}.js\"></script>";
return apply_filters(
'embed_github_gist',
$embed,
$matches,
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
@zgordon
zgordon / learndash-groups-woocommerce.php
Last active August 21, 2019 00:06
Assign users to a LearnDash Group when they purchase a specific WooCommerce product
<?php
// Add user to LearnDash Group if purchases specific WooCommerce product
function jsforwp_add_user_to_group( $order_id ) {
// Add group ID from LearnDash here
$ld_group_id = XXXX;
// Add product ID from WooCommerce here
$wc_product_id = XXXX;
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
@zgordon
zgordon / learndash-topic-parent-lesson.php
Last active February 3, 2021 11:42
This snippets lets you get the lesson for a topic in your topic.php file
<?php
$parent_lesson_id = learndash_get_setting( $post, 'lesson' );
$parent_lesson = get_post( $parent_lesson_id );
?>
@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 / update-woo-order-billing-when-user-saves-address.php
Last active May 12, 2021 18:46
Update WooCommerce Order Address Dynamically When Customer Updates Their Address
<?php
add_action( 'woocommerce_customer_save_address', 'jsforwp_update_address_for_orders', 10, 2 );
function jsforwp_update_address_for_orders( $user_id ) {
$customer_meta = get_user_meta( $user_id );
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
@zgordon
zgordon / wp-nav-menu-parameters.php
Last active January 7, 2024 05:15
Demo of the possible menu parameters for wp_nav_menu
<?php
$args = [
// Location pickable in Customizer
'theme_location' => 'main-menu',
// Assigns a default menu to location
'menu' => 'Main Menu',
// Main wrapper around the ul of posts
'container' => 'div',
'container_class' => 'container-class',
'container_id' => 'container-id',
@zgordon
zgordon / register_sidebar-parameters.php
Last active January 7, 2024 05:16
Example of parameters for register_sidebar() function in WordPress
<?php
register_sidebar( [
'name' => esc_html__( 'Sidebar', 'themename' ),
'id' => 'main-sidebar',
'description' => esc_html__( 'Add widgets here.', 'themename' ),
'before_widget' => '<section class="widget">',
'class' => 'custom-widget-area',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
@zgordon
zgordon / node-wpapi-w-async.js
Created June 27, 2017 08:09
Attempting to use async and await with Node WP API Client
// What I'm calling in my router
await Page.render( slug );
Gallery.render();
// The Page.render() code
export default class Page {
/**
* render - Display pages on the Page
@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