Skip to content

Instantly share code, notes, and snippets.

View tarecord's full-sized avatar
🔨
Hammering Things Into Place

Tanner Record tarecord

🔨
Hammering Things Into Place
View GitHub Profile
@tarecord
tarecord / menu_transients.php
Created July 5, 2017 17:54
A function to display a nav menu saved as a transient
<?php
/**
* Menu Transient, a function that helps with extremely large menus by storing the query in a transient
* for ~24hrs. It can be used in template files to both store the transient and display the menu so there
* is no need for multiple functions and queries.
*
* @param $name string A descriptive name of the menu (ex. "mobile-menu" or "quick-links").
* @param $args array The array of nav menu arguments.
*
* @return string The HTML formatted nav menu
@tarecord
tarecord / docker-compose.yml
Created November 27, 2018 20:22
A docker-compose configuration for spinning up local WordPress sites
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- ./mysql:/var/lib/mysql
ports:
- "3306:3306"
restart: always
@tarecord
tarecord / salesforce_pardot_country_codes.php
Created March 17, 2022 18:57
An array of countries and country codes for Salesforce Pardot
<?php
// List of countries: https://help.salesforce.com/s/articleView?id=000318281&type=1
$countries = [
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
@tarecord
tarecord / .distignore
Created May 29, 2023 20:14
A basic .distignore for a Wordpress plugin using dist-archive WP-CLI package
# A set of files you probably don't want in your WordPress.org distribution
.deploy
.distignore
.DS_Store
.editorconfig
.git
.github
.gitignore
.gitmodules
*.sql
@tarecord
tarecord / disable-email.php
Created February 7, 2023 03:22
A plugin that disables all WordPress emails sent using wp_mail()
<?php
/**
* Plugin Name: Disable Email
* Plugin URI: https://www.tannerrecord.com/micro-plugins/disable-email
* Description: A plugin that disables all email sent using <code>wp_mail()</code>.
* Author: Tanner Record
* Author URI: https://www.tannerrecord.com
* Update URI: false
* Version: 1.0
*/
@tarecord
tarecord / get_vimeo_id.php
Last active October 7, 2023 18:02
A function that takes a vimeo url and returns the video ID
<?php
function get_vimeo_id( $url ) {
/**
* Matches:
* https://player.vimeo.com/video/123456789
* https://vimeo.com/123456789
* https://www.vimeo.com/123456789
*/
preg_match( '/(vimeo\.com\/)(?:video\/)?([\d]+)/', $url, $matches );
$vimeo_id = $matches[2];
@tarecord
tarecord / get_top_ancestor.php
Created June 6, 2017 18:22
Get the top most parent of a WordPress post
/**
* Gets the top most ancestor for a post.
*
* @param object $post The current post
*
* @return integer The post ID of the ancestor
*/
function get_top_ancestor( $post ) {
if ( $post->post_parent ) {
$ancestors = get_post_ancestors( $post->ID );
@tarecord
tarecord / redirect_attachment_page_to_file.php
Last active October 7, 2023 18:04
Redirect any WordPress attachment page to the actual file
<?php
/**
* Redirect all attachment pages to actual file
*/
function redirect_attachment_pages() {
global $post;
// Return if not an attachment
if ( !is_attachment() ) {
@tarecord
tarecord / redirect_after_register.php
Created September 23, 2020 11:35
Sign in With Google - Adjust redirect after successfully authenticating
<?php
/**
* functions.php
**/
add_filter( 'siwg_auth_redirect', 'redirect_users_after_login', 10, 1 );
/**
* Filter the url redirection after user authenticates with Google.
**/
@tarecord
tarecord / get_primary_taxonomy_term.php
Last active October 7, 2023 18:16
Returns the primary term for the chosen taxonomy set by Yoast SEO or the first term selected.
<?php
/**
* Returns the primary term for the chosen taxonomy set by Yoast SEO
* or the first term selected.
*
* @link https://www.tannerrecord.com/how-to-get-yoasts-primary-category/
* @param integer $post The post id.
* @param string $taxonomy The taxonomy to query. Defaults to category.
* @return array The term with keys of 'title', 'slug', and 'url'.
*/