Skip to content

Instantly share code, notes, and snippets.

Matt Radford mattradford

Block or report user

Report or block mattradford

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mattradford
mattradford / yoast_social_accounts.php
Last active Jun 20, 2019
Output Yoast Social links
View yoast_social_accounts.php
/**
* Return a nav element populated with Yoast social accounts
*/
function yoast_social_accounts()
{
if ($social_accounts = get_option('wpseo_social')) {
$fb_url = $social_accounts['facebook_site'];
$twitter_account = $social_accounts['twitter_site'];
$youtube_url = $social_accounts['youtube_url'];
@mattradford
mattradford / wp-install.sh
Last active Oct 23, 2018 — forked from hanigamal/wp-install.sh
WordPress Commandline Local Install
View wp-install.sh
#!/bin/bash
#
# WP Commandline Local Install, by Brian Richards (@rzen)
#
# Creates a new directory, downloads WordPress, creates a database, sets up wp-config,
# optionally empties wp-content, and deletes other misc files. This compliments my local
# dev setup, outlined here: http://rzen.net/development/local-develoment-in-osx/
#
# Credit:
# Based on WPBuildr (https://github.com/AaronHolbrook/wpbuildr/). Props to Aaron Holbrook
@mattradford
mattradford / restrict_acf_menu.php
Created Jun 11, 2018
Restrict ACF menu visibility based on the user's email domain
View restrict_acf_menu.php
/**
* Restrict ACF Custom Fields menu to example.com domains only
*/
function td_acf_hide_admin() {
$current_user = wp_get_current_user();
$domain = substr(
strrchr(
$current_user->user_email,
@mattradford
mattradford / yoast-primary-category-menu-item.php
Created Jun 4, 2018
Highlight menu item based on Yoast Primary Category
View yoast-primary-category-menu-item.php
/**
* Highlight menu item based on Yoast Primary Category
*/
function td_yoast_primary_category_nav_class( $classes, $item ) {
if ( is_single() ) {
global $post;
if ( $primary_category = get_post_meta($post->ID,'_yoast_wpseo_primary_category',true) ) {
$primary_category_term = get_term_by( 'id', $primary_category, 'category' );
$menu_locations = get_nav_menu_locations();
if ( has_term($menu_locations['primary_navigation'], 'nav_menu', $item) ) {
@mattradford
mattradford / pull-wpe.sh
Created Apr 27, 2018
Pull a WP Engine install via SSH. File and DB.
View pull-wpe.sh
    #!/bin/bash
    # Pull an install's files and DB from WP Engine
    # Variables
    lpath='app/public/'
    rpath='~/sites/'$install
    #User input
    read -p 'Repo to clone (blank if none): ' repo
    read -p 'Install to pull: ' install
    read -r -p 'Include uploads? (y/N) ' response
    read -p 'Local MySQL port: ' port
@mattradford
mattradford / wpe_flush_cache.sh
Last active Apr 24, 2018
Programatically flush a WP Engine object cache
View wpe_flush_cache.sh
#!/bin/bash
# Programatically flush a WPE cache
# Requires https://github.com/a7/wpe-cache-flush/
# Set private key in $private_key
# @params install
# @params private_key
# @returns HTTP status code
# Variables
$private_key=YOUR_PRIVATE_KEY
@mattradford
mattradford / FacetWP set n selected
Last active Apr 21, 2018
Set the number of choices selected at which "{n} selected" will display. is_tax conditional left as an example.
View FacetWP set n selected
/**
* Set {n} selected text to show after 1 selection, on all facets
*/
function td_facetwp_selected() {
if ( is_tax() ) {
?>
<script>
(function($) {
$(function() {
if ('undefined' !== typeof FWP) {
@mattradford
mattradford / fSelect-numDisplayed
Created Mar 15, 2018
Change FacetWP fSelect number of choices at which text changes to "{n} selected"
View fSelect-numDisplayed
add_filter( 'facetwp_render_output', function( $output ) {
$output['settings']['location']['numDisplayed'] = 1;
return $output;
});
View exodus-list
# List of trackers for DNS blocking
# Taken from https://reports.exodus-privacy.eu.org/trackers/ and https://discourse.pi-hole.net/t/trackers/5656
0.0.0.0 a4.tl2
0.0.0.0 accengage.com
0.0.0.0 aatkit.com
0.0.0.0 adswizz.com
0.0.0.0 appboy.com
0.0.0.0 adnxs.com
0.0.0.0 appsflyer.com
@mattradford
mattradford / ajax-handler-wp.php
Last active Oct 31, 2017 — forked from pixeline/ajax-handler-wp.php
Custom ajax handler for Wordpress. Using admin-ajax.php does not allow the use of plugin shortcodes. Using a custom ajax handler like this bypasses that. http://wordpress.stackexchange.com/questions/170808/the-content-shows-shortcode-instead-of-parsing-it
View ajax-handler-wp.php
<?php
/*
WORDPRESS SPECIFIC AJAX HANDLER (because admin-ajax.php does not render plugin shortcodes).
credits: Raz Ohad https://coderwall.com/p/of7y2q/faster-ajax-for-wordpress
*/
//mimic the actual admin-ajax
define('DOING_AJAX', true);
if (!isset( $_REQUEST['action']))
die('-1');
You can’t perform that action at this time.