Skip to content

Instantly share code, notes, and snippets.

View mattradford's full-sized avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@mattradford
mattradford / restrict_acf_menu.php
Created June 11, 2018 09:30
Restrict ACF menu visibility based on the user's email domain
/**
* 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 June 4, 2018 12:20
Highlight menu item based on Yoast Primary Category
/**
* 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 April 27, 2018 15:49
Pull a WP Engine install via SSH. File and DB.
    #!/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 April 24, 2018 08:56
Programatically flush a WP Engine object cache
#!/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 April 21, 2018 00:21
Set the number of choices selected at which "{n} selected" will display. is_tax conditional left as an example.
/**
* 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 March 15, 2018 09:24
Change FacetWP fSelect number of choices at which text changes to "{n} selected"
add_filter( 'facetwp_render_output', function( $output ) {
$output['settings']['location']['numDisplayed'] = 1;
return $output;
});
@mattradford
mattradford / exodus-list
Created January 2, 2018 21:04 — forked from anonymous/exodus-list
Trackers from https://reports.exodus-privacy.eu.org/trackers/ for use in DNS blocking
# 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 October 31, 2017 14:06 — 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
<?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');
@mattradford
mattradford / facetwp_load_more_and_all.php
Last active February 3, 2022 23:17
FacetWP load more and load all
// Adapted from https://gist.github.com/mgibbs189/f2469009a7039159e229efe5a01dab23
function fwp_load_more() {
?>
<script>
(function($) {
$(function() {
if ('object' != typeof FWP) {
return;
}
@mattradford
mattradford / functions.php
Created December 22, 2016 11:34 — forked from BurlesonBrad/functions.php
Reduce or remove WooCommerce 2.5 minimum password strength requirement for creating a user account. Warning: Use at your own risk.
<?php
/**
*Reduce the strength requirement on the woocommerce password.
*
* Strength Settings
* 3 = Strong (default)
* 2 = Medium
* 1 = Weak
* 0 = Very Weak / Anything
*/