Skip to content

Instantly share code, notes, and snippets.

View tobeyadr's full-sized avatar
🎯
Focusing

Adrian Tobey tobeyadr

🎯
Focusing
View GitHub Profile
@tobeyadr
tobeyadr / post-creation-hook.php
Last active November 12, 2020 22:03
Post creation hook
add_action( 'wp_insert_post', 'gh_new_post_hook' );
function gh_new_post_hook(){
if ( ! is_user_logged_in() ){
return;
}
$contact = \Groundhogg\get_current_contact();
@tobeyadr
tobeyadr / require-prev-lesson-complete.php
Created February 3, 2020 21:02
Require the previous lesson in a LifterLMS course to be complete before moving forward. Same as requiring the prerequisite for a lesson to be the previous lesson.
/*
Plugin Name: LifterLMS Mods
Plugin URI: https://academy.groundhogg.io
Description: Modify default LifterLMS behaviour.
Version: 1.0
Author: Groundhogg Inc.
Author URI: http://groundhogg.io
License: A "Slug" license name e.g. GPL2
*/
<?php
// Load after Groundhogg
use function Groundhogg\is_managed_page;
add_filter( 'template_include', 'load_custom_preferences_page', 11 );
/**
* Load the custom template from the them folder
*
<?php
if ( ! defined( 'ABSPATH' ) ) {
/** Set up WordPress environment */
require_once( dirname( __FILE__ ) . '/wp-load.php' );
}
/**
* Here is some pseudo code that will hopefully help you.
* Generate broadcast stats from Apache raw access logs...
@tobeyadr
tobeyadr / force-to-email.php
Last active May 15, 2020 19:30
Force any outgoing emails from Groundhogg to the go to the given address
<?php
// Force any outgoing emails from Groundhogg to the go to the given address
add_filter( 'groundhogg/email/to', function ( $to_address ){
return 'email.to.force.to@example.com';
} );
<?php
/**
* Add CC spouse email address
*/
add_filter( 'groundhogg/email/headers', function ( $headers = [] ){
// The contact ID is not passed, so let's get it from the global
// Check if the event queue is running, if it's not then this is not relevant...
if ( ! \Groundhogg\Queue\Event_Queue::is_processing() ){
<?php
if ( ! function_exists( 'wp_mail' ) ):
function wp_mail( $to='', $subject='', $body='', $headers='', $attachments=[] ){
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', 'Domain based email disabled.' ) );
return false;
<?php
// get the contact record if one exists
$contact = \Groundhogg\get_contactdata( 'email@example.com' );
// Get a list of contact ids
$tags = $contact->get_tags();
// to get a list of ID >> Name
$tag_id_to_name = [];
// Populate the list
foreach ( $tags as $tag_id ) {
<?php
/**
* Demonstrates...
*
* Create a contact record
* Add a tag
* Remove a tag
*
* @param $email
@tobeyadr
tobeyadr / remove-tools-tabs.php
Created June 17, 2020 16:28
Remove tabs from the tools page if the current user is not a super admin.
<?php
/**
* Remove unwanted tabs from the tools page
*
* @param $tabs
*
* @return array[]
*/
function remove_tools_tabs_from_groundhogg( $tabs ){