Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 . '/*' );
<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 / 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 / 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 ]]