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
@tangrufus
tangrufus / class-cloudflare-api-helper.php
Created July 17, 2014 18:33
Make CloudFlare Client API calls via wp_remote_post. A fork from CloudFlare-API by VEXXHOST, Inc.
<?php
/**
* Make CloudFlare Client API calls via wp_remote_post
* A fork from CloudFlare-API by VEXXHOST, Inc.
*
* @package CloudFlare_API_Helper
* @link https://github.com/vexxhost/CloudFlare-API
* @link https://www.cloudflare.com/docs/client-api.html
*/
@tangrufus
tangrufus / settings-api-tabs-demo.php
Created July 26, 2014 07:58
Adding Tabs with Settings API
<?php
/*
* Plugin Name: Settings API Tabs Demo
* Plugin URI: http://theme.fm/?p=
* Description: This is a demo showing off usage of tabs with the WordPress Settings API
* Version: 1.0
* Author: kovshenin
* Author URI: http://theme.fm
* License: GPL2
*/
<div id="sunny_demo_url_purger" class="wrap">
<form id="sunny_demo_url_purger_form" method="POST">
<?php wp_nonce_field( 'sunny_demo_url_purger', 'sunny_demo_url_purger_nonce'); ?>
<?php do_settings_sections( 'sunny_demo_url_purger_section' ); ?>
<?php submit_button( __('Purge', $plugin_slug ), 'primary', 'sunny_demo_url_purger_button' ); ?>
</form>
<br class="clear">
<div id="sunny_demo_url_purger_result" style="display: none">
<h3 id="sunny_demo_url_purger_result_heading">URL Purger Result</h3>
<img id="sunny_demo_url_purger_form_spinner" style="display: none" src="<?php echo admin_url(); ?>images/spinner-2x.gif">
<?php
// inside private function register_settings()
// below add_settings_section()
// Next, we will introduce the fields for CloudFlare Account info.
add_settings_field(
// ID used to identify the field throughout the theme
'sunny_demo_cloudflare_email',
// The label to the left of the option interface element
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)
<?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) {
@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