Skip to content

Instantly share code, notes, and snippets.

@ryanshoover
ryanshoover / acf-object-caching.php
Last active December 5, 2023 17:57
Add object caching to ACF
<?php
/**
* ACF object caching
*
* Adds Object caching support to ACF so taht it doesn't have to recalculate all of
* its data on each page load. It can substantially improve performance on sites that
* heavily use ACF.
*
* This is NOT multisite compatible. ACF uses an alternative data structure for multisites.
* Its internal APIs don't support an external tool to cache all of the multisite data.
@ryanshoover
ryanshoover / .ci\deploy\pantheon\dev-multidev
Created October 5, 2023 21:14
Deploying to feature branches & dev
...
echo "Ready to deploy to Pantheon"
if [[ $CI_BRANCH != $DEFAULT_BRANCH ]]
then
echo "Pushing to a multidev environment."
ENV_EXISTS=$(terminus env:list "$TERMINUS_SITE" --field=id | grep "^$TERMINUS_ENV$" || true)
if [[ $ENV_EXISTS ]]
@ryanshoover
ryanshoover / count-files-one-liner.sh
Last active August 18, 2023 02:18
Flag directories with > 30,000 files
find /path/to/starting/directory -mindepth 1 -type d -exec bash -c 'echo -n "{}: "; find "{}" -maxdepth 1 -type f | wc -l' \;
@ryanshoover
ryanshoover / retry-failed.php
Created May 18, 2022 20:06
Action Scheduler retry failed jobs
<?php
// Instance of the batch processing job.
$job = MyBatchJob();
// How many failed attempts do you want to process.
$batch_max_attempts = 3;
add_action( 'action_scheduler_failed_execution', 'maybe_retry_failed_batch' );
add_action( 'action_scheduler_failed_action', 'maybe_retry_failed_batch' );
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
<filter class="solr.LowerCaseFilterFactory"/>
<!-- filter class="solr.EnglishPorterFilterFactory" protected="protwords.txt"/ -->
<filter class="solr.SnowballPorterFilterFactory" protected="protwords.txt" language="English"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
<filter class="solr.GermanNormalizationFilterFactory"/>
</analyzer>
@ryanshoover
ryanshoover / .circleci config.yml
Last active January 24, 2023 16:18
CircleCI 2.1 Continuous Integration with WP Engine
# Continuous Integration to a WP Engine install
# PHP CircleCI 2.1 configuration file
# Requirements:
# 1. In CircleCI settings, add environment variables for your site's installs:
# * WPE_PRODUCTION_INSTALL=thenameofyourproductioninstall
# * WPE_STAGING_INSTALL=thenameofyourstaginginstall
# * WPE_DEVELOPMENT_INSTALL=thenameofyourdevelopmentinstall
# 2. In your repo, have two files
# * `./.gitignores/__default` -- Excludes any compiled files
@ryanshoover
ryanshoover / delete-multisite-content.php
Created December 15, 2022 19:48
Delete a WordPress network's site content when a single site is deleted.
<?php
/**
* Helper function to remove a directory and all its contents.
* PHP requires you to remove each file individually and delete
* a directory only when it's empty.
*
* @param string $path Absolute path to a directory.
*/
function remove_directory( $path ) {
$files = glob( $path . '/*' );
@ryanshoover
ryanshoover / sunrise.php
Created November 21, 2022 17:46
Retrofit WPMS blogs.dir structure
<?php
/**
* Sunrise - load very early.
*/
/**
* If the request is for a file, send it to the legacy ms-files.php for processing.
*
* File requests follow the pattern `multisite.com/sitename/files/2022/06/filename.jpg`
*/
@ryanshoover
ryanshoover / wpengine-stop-htaccess-rewrites.php
Created February 4, 2019 20:02
WP Plugin Stop htaccess rewrites
<?php
/**
* Stop htaccess rewrites
*
* @package wpengine-stop-htaccess-rewrites
* @author wpengine
* @license Proprietary
*
* @wordpress-muplugin
* Plugin Name: Stop htaccess rewrites
@ryanshoover
ryanshoover / demandbase.js
Created June 16, 2020 01:49
Unminified Demandbase
"use strict";
"undefined" == typeof window.console && (window.console = { log: function () {}, debug: function () {} });
"undefined" == typeof JSON && (JSON = { stringify: function () {}, parse: function () {} });
Array.prototype.indexOf ||
(Array.prototype.indexOf = function (e) {
var t = this.length >>> 0,
n = Number(arguments[1]) || 0;
n = 0 > n ? Math.ceil(n) : Math.floor(n);
0 > n && (n += t);
for (; t > n; n++) if (n in this && this[n] === e) return n;