Skip to content

Instantly share code, notes, and snippets.

View ethanclevenger91's full-sized avatar

Ethan Clevenger ethanclevenger91

View GitHub Profile
@ethanclevenger91
ethanclevenger91 / index.php
Created December 5, 2022 23:16
Determine if a product is a FooEvent
<?php
// However you get a product reference
global $post;
$product = wc_get_product($post);
if($product && $product->get_meta('WooCommerceEventsEvent')) {
// it's a FooEvents product
}
@ethanclevenger91
ethanclevenger91 / imagemagick-heic-forge-php-80-recipe.txt
Last active January 10, 2024 22:19
ImageMagick w/ HEIC support on Laravel Forge - Recipe (PHP 8.0)
# Minor tweaks from https://eplt.medium.com/5-minutes-to-install-imagemagick-with-heic-support-on-ubuntu-18-04-digitalocean-fe2d09dcef1
sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
apt-get update
apt-get -y install build-essential autoconf libtool git-core
apt-get -y build-dep imagemagick libmagickcore-dev libde265 libheif
cd /usr/src/
git clone https://github.com/strukturag/libde265.git
git clone https://github.com/strukturag/libheif.git
cd libde265/
./autogen.sh
<?php
/**
* Registers the `dog` post type.
*/
function dog_init() {
register_post_type( 'dog', array(
'labels' => array(
'name' => __( 'Dogs', 'YOUR-TEXTDOMAIN' ),
'singular_name' => __( 'Dog', 'YOUR-TEXTDOMAIN' ),
@ethanclevenger91
ethanclevenger91 / cloudflare-account.conf
Created August 27, 2021 22:16
fail2ban action for a Cloudflare account (rather than user)
#
# Author: Mike Rushton
#
# IMPORTANT
#
# Please set jail.local's permission to 640 because it contains your CF API key.
#
# This action depends on curl (and optionally jq).
# Referenced from http://www.normyee.net/blog/2012/02/02/adding-cloudflare-support-to-fail2ban by NORM YEE
#
@ethanclevenger91
ethanclevenger91 / functions.php
Created March 3, 2021 21:09 — forked from cliffordp/functions.php
The Events Calendar Get Events for 1 Year from Today in iCal Export File -- http://example.com/events/?ical=1&year-feed
<?php
// From https://gist.github.com/cliffordp/ab1f7c4d95723ee6f892/, a fork of https://gist.github.com/jesseeproductions/2b1af6527b7029eaea6e
// References:
// https://theeventscalendar.com/support/forums/topic/ical-only-pushing-1-month-at-a-time/
// https://theeventscalendar.com/support/forums/topic/how-users-can-subscribe-to-my-events-calendar-in-their-personal-calendars/#post-1022932
// https://tribe.uservoice.com/forums/195723-feature-ideas/suggestions/3777092-subscribe-to-calendar-via-ical
/*
* The Events Calendar Get Events for 1 Year from Today in iCal Export File
* add coding to child theme's functions.php
* Tested works with The Events Calendar v3.12 and v4.0
@ethanclevenger91
ethanclevenger91 / programmatically-add-tribe-event-ticket.php
Last active November 24, 2023 14:46 — forked from barryhughes/programmatically-add-woocommerce-etp-ticket.php
Programmatically add a Tribe Events Calendar event with tickets and attendee meta
<?php
$event_id = tribe_create_event( [
'post_title' => 'My Event',
// see https://docs.theeventscalendar.com/reference/functions/tribe_create_event/ for full arguments
] );
$provider = \Tribe__Tickets__Tickets::get_event_ticket_provider();
$ticket_id = $provider::get_instance()->ticket_add( $event_id, [
@ethanclevenger91
ethanclevenger91 / index.php
Last active June 16, 2020 16:41
Custom Fonts otf/ttf mime rewrite
class Foo {
public function __construct() {
// ...
add_filter( 'wp_check_filetype_and_ext', array( $this, 'update_mime_types' ), 10, 3 );
add_filter( 'upload_mimes', array( $this, 'add_fonts_to_allowed_mimes' ) );
}
// ...
@ethanclevenger91
ethanclevenger91 / Hooks.php
Last active August 13, 2019 18:48
An abstract class for wrapping related WP hooks together. For code organization.
<?php
/**
* Usage:
*
* class RelatedHooks extends Hooks {
*
* private $actions = [];
* private $filters = [];
*
@ethanclevenger91
ethanclevenger91 / functions.php
Last active September 27, 2020 08:32
Add FacetWP facets with code-based ones, with preference for code-based definitions over db ones with same name
<?php
/**
* Glob all our JSON facets and register them
* with FacetWP
*/
function my_register_facets( $facets ) {
$new_facets_raw = glob(dirname(__FILE__) . '/facets/*.json'); // Or however you want to get your facet definitions
$new_facets = [];
foreach($new_facets_raw as $facet) {
$facet = json_decode(file_get_contents($facet), true);
@ethanclevenger91
ethanclevenger91 / after.sh
Last active March 26, 2024 22:24
Install PHP SQLSRV database extension on Laravel Homestead (probably works as a Laravel Forge recipe, too). Thanks @richvida
#!/bin/sh
PHP_MSSQL_DRIVERS=Ubuntu18-7.3
PHP_MSSQL_RELEASE=5.6.1
# Download and extract phpmysql drivers
sudo wget "https://github.com/Microsoft/msphpsql/releases/download/v${PHP_MSSQL_RELEASE}/${PHP_MSSQL_DRIVERS}.tar" -O - | tar -x
# Change Directory
cd $PHP_MSSQL_DRIVERS