Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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' \;
<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 / 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 / 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' );
@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;
@ryanshoover
ryanshoover / Before In Location
Created August 5, 2019 19:53
Server-side A/B testing with NGINX & Varnish (WP Engine)
add_header Set-Cookie "my_test_group=$test_group;Domain=.mydomain.com;Path=/;Max-Age=604800";
@ryanshoover
ryanshoover / tiles.html
Created June 21, 2019 02:32
Tile testing html
<div class="tiles tiles--two-per-row">
<div class="tile">
<div class="tile__photo">
<img src="https://picsum.photos/id/344/1440/900" class="tile__photo__image">
</div>
<h3 class="tile__title tile_title--small">Beef enim hamburger, doner</h3>
<p class="tile__description">
salami cupidatat ipsum deserunt. Corned beef prosciutto esse eiusmod short loin sausage ut jowl ipsum
cupidatat. Flank meatball pariatur fugiat meatloaf beef. Pork chop turkey jerky, in nostrud in non
consectetur turducken shoulder pig esse cow eu.