Skip to content

Instantly share code, notes, and snippets.

@tangrufus
tangrufus / vip-wp-multisite-plugin-is-activated.sh
Last active August 16, 2022 14:19
Check whether a plugin is avticated on each sites in a network on WP VIP
#!/bin/bash
set -euo pipefail
app='@theApp.theEnv'
plugin='wordpress-seo'
echo "Checking whether plugin ${plugin} is activated on ${app}"
echo 'Fetching URLs'
urls=$(vip "${app}" --yes -- wp site list --fields="url" --format="csv" --quiet --no-color)
@tangrufus
tangrufus / vip-wp-multisite-theme-list-active.sh
Last active August 16, 2022 13:33
List active themes for each sites in a network on WP VIP
#!/bin/bash
set -euo pipefail
echo 'Fetching URLs...'
urls=$(vip -y @theApp.theEnv -- wp site list --fields="url" --format="csv")
for url in $urls
do
if [ "${url}" == "url" ]; then
continue # skip the CSV header
fi
<?php
add_action('save_post', function($id, $post, $update): void {
if (! $update) {
return;
}
$postType = get_post_type($id);
// TODO: Change to the correct post type!
if ('post' !== $postType) {
require "http"
require 'json'
require 'open3'
http = HTTP.auth("token XXXXX")
max_page=12
clone_urls = (1..max_page).map do |page|
body = http.get("https://api.github.com/orgs/itinerisltd/repos?type=sources&sort=created&page=#{page}").body
repos = JSON.parse(body)
@tangrufus
tangrufus / find-corrupted-wordpress-image-attachments.php
Last active August 21, 2019 11:15
Find corrupted wordpress image attachments
<?php
$mineTypes = get_allowed_mime_types();
$imageMineTypes = array_filter($mineTypes, function (string $type): bool {
return '' !== 'image/' && 0 === strpos($type, 'image/');
});
$query = new WP_Query([
'fields' => 'ids',
'post_type' => 'attachment',
@tangrufus
tangrufus / wp offload media + download monitor s3.md
Last active August 8, 2019 10:38
wp offload media + download monitor s3

Keybase proof

I hereby claim:

  • I am tangrufus on github.
  • I am tangrufus (https://keybase.io/tangrufus) on keybase.
  • I have a public key whose fingerprint is CFBE 0B13 3B14 C437 56D0 0D34 5709 0746 B2C4 EAC7

To claim this, I am signing this object:

@tangrufus
tangrufus / github-zip.jpg
Last active October 16, 2018 13:54
Making wp plugin zip out of composer repo
github-zip.jpg
@tangrufus
tangrufus / query-to-redirect.md
Last active September 6, 2018 06:06
Refactoring query-to-redirect

Don't hook into parse_query.

- add_action('parse_query', [$this, 'fixEmptyQueryString']);
- add_action('parse_query', [$this, 'filterBarQueryRedirect']);

+ add_action('wp', [$this, 'fixEmptyQueryString'], 5);
+ add_action('wp', [$this, 'filterBarQueryRedirect'], 5);