Skip to content

Instantly share code, notes, and snippets.

Thorsten Ott tott

Block or report user

Report or block tott

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
tott / gist:a7638cb9b602425b3c87
Last active Aug 29, 2015
workaround disabling xmlrpc from within wordpress mu-plugins file
View gist:a7638cb9b602425b3c87
* Disable xmlrpc
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
include_once(ABSPATH . WPINC . '/class-IXR.php');
class blocking_xmlrpc_server {
function serve_request() {
$response = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) );
die( $response->getXml() );
tott / gist:0cc78e7dcad18024d1c8
Created Jul 1, 2014
Create a full list of sites with domain mapping with wp-cli
View gist:0cc78e7dcad18024d1c8
for i in `wp site list | cut -f 2 | grep -v url`; do wp --url=$i eval 'global $wpdb, $blog_id; $blogname=get_option("blogname"); $blogurl=home_url(); $domains=$wpdb->get_results( "SELECT * FROM {$wpdb->dmtable} WHERE blog_id = $blog_id;" ); foreach( $domains as $data ) { echo $blog_id.",".$blogname.",".$blogurl.",".$data->domain.",".$data->active."\n"; }'; done
tott / maybe-flush-rewrite-rules.php
Created Mar 14, 2014
Flush rewrite rules when it's necessary. This could be put in an init hook or the like and ensures that the rewrite rules option is only rewritten when the generated rules don't match up with the option.
View maybe-flush-rewrite-rules.php
function maybe_flush_rules() {
global $wp_rewrite;
$rewrite_rules = get_option( 'rewrite_rules' );
foreach( $rewrite_rules as $rule => $rewrite ) {
$rewrite_rules_array[$rule]['rewrite'] = $rewrite;
$maybe_missing = $wp_rewrite->rewrite_rules();
$missing_rules = false;
$rewrite_rules_array = array_reverse( $rewrite_rules_array, true );
foreach( $maybe_missing as $rule => $rewrite ) {
tott / harvest-bugger.php
Created Feb 3, 2014
For all those people who forget to run their harvest timer. Here's a little script that will bug you when you do. Runs on OSX.
View harvest-bugger.php
* Helper script that can be run in cron to bug you when you forgot to run a harvest timer.
* install terminal-notifier via:
* sudo gem install terminal-notifier
* Make sure to adjust your credentials.
* Schedule via crontab -e to run weekdays 9-5
* <star>/10 09-17 * * 1-5 php <path-to-script>
* replace <star> with *
tott / gist:8639621
Created Jan 26, 2014
Speed up wp-admin when there are a lot of terms
View gist:8639621
add_action( 'admin_init', 'deregister_autosuggest' );
function deregister_autosuggest() {
if ( is_admin() ) {
wp_deregister_script( 'suggest' );
tott / gist:8517558
Created Jan 20, 2014
indexOf was added to the ECMA-262 standard in the 5th edition; as such it may not be present in all browsers. You can work around this by utilizing the following code at the beginning of your scripts. This will allow you to use indexOf when there is still no native support. This algorithm matches the one specified in ECMA-262, 5th edition, assum…
View gist:8517558
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
fromIndex = +fromIndex || 0;
tott / gist:7908001
Created Dec 11, 2013
Get a space separated list of all hosts in an apache config so you can add them to your hosts file
View gist:7908001
grep -E "Server(Name|Alias)" httpd.conf | sort | uniq | cut -d " " -f 6 | tr "\n" " "
tott /
Created Dec 10, 2013
Compare html served by different servers. This script will first get the page from the source ip and extract a list of links on this output. then it will compare the output of each link for both servers.
ip1='FILL-SOURCE-IP'; ip2='FILL-DEST-IP'; host='FILL-HOSTNAME'; curl http://$host | grep -o '<a.*href=.*>' | grep "http://$host" | sed -e 's/<a .*href=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d' > links.txt; for link in `cat links.txt`; do path=`echo -n $link | cut -d "/" -f 4-`; curl --header "Host: $host" "http://$ip1/$path" > ip1.html; curl --header "Host: $host" "http://$ip2/$path" > ip2.html; echo; echo "Diff http://$ip1/$path"; echo; diff ip1.html ip2.html; done
tott / gist:7767218
Created Dec 3, 2013
.htaccess rule to force www and preserving the protocol http/https
View gist:7767218
# Force www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
tott / ip_in_range.php
Created Nov 27, 2013
php check if IP is in given network range
View ip_in_range.php
* Check if a given ip is in a network
* @param string $ip IP to check in IPV4 format eg.
* @param string $range IP/CIDR netmask eg., also is accepted and /32 assumed
* @return boolean true if the ip is in this range / false if not.
function ip_in_range( $ip, $range ) {
if ( strpos( $range, '/' ) == false ) {
$range .= '/32';
You can’t perform that action at this time.