Skip to content

Instantly share code, notes, and snippets.

View tott's full-sized avatar

Thorsten Ott tott

  • Germany, Cologne area
View GitHub Profile
#!/bin/bash
# ./curl-urls.sh numprocessses http://urltograp urlpattern
# ./curl-urls.sh 3 http://www.domain.com domain.com
numprocessses=$1
baseurl=$2
urlpattern=$3
function forky() {
local num_par_procs
if [[ -z $1 ]] ; then
@tott
tott / alter-robots-txt.php
Created November 14, 2013 14:15
alter robots.txt
add_filter( 'robots_txt', 'sav_add_sitemap_to_robots' );
function sav_add_sitemap_to_robots( $robots ) {
$robots .= 'Sitemap: ' . site_url( 'sitemap_index.xml' );
return $robots;
}
@tott
tott / gist:8639621
Created January 26, 2014 21:17
Speed up wp-admin when there are a lot of terms
add_action( 'admin_init', 'deregister_autosuggest' );
function deregister_autosuggest() {
if ( is_admin() ) {
wp_deregister_script( 'suggest' );
}
}
@tott
tott / gist:8517558
Created January 20, 2014 09:49
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…
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
tott / gist:7908001
Created December 11, 2013 10:11
Get a space separated list of all hosts in an apache config so you can add them to your hosts file
#!/bin/bash
grep -E "Server(Name|Alias)" httpd.conf | sort | uniq | cut -d " " -f 6 | tr "\n" " "
@tott
tott / compare-urls.sh
Created December 10, 2013 11:18
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.
#!/bin/bash
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
tott / functions.php
Created November 15, 2013 08:49
validate if a path is a subfolder of WP_CONTENT_DIR
/**
* Validate that a given path is a child of the WP_CONTENT_DIR
* @param string $path path to check
* @return boolean true/false
*/
function sav_path_is_valid( $path ) {
if ( !defined( WP_CONTENT_DIR ) )
return false;
$start = 0;
@tott
tott / frontend-force-mapped-domain.php
Created November 14, 2013 14:14
Enforce domain mapping mapped domain for all front-end urls ran through esc_url()
add_filter( 'clean_url', 'sav_force_mapped_url' );
function sav_force_mapped_url( $url ) {
if ( ! is_admin() ) {
if ( function_exists( 'get_original_url' ) && strpos( '/wp-admin', $url ) === false ) {
$original = preg_replace( '#^https?://#', '', get_original_url('') );
$new = preg_replace( '#^https?://#', '', site_url() );
$url = str_ireplace( $original, $new, $url );
}
}
return $url;
@tott
tott / force-referer-for-import.php
Created November 13, 2013 19:35
Force http referer for imports to bypass some bad servers who would not want to serve the static assets otherwise
add_filter( 'http_request_args', 'force_referer_for_import' );
function force_referer_for_import( $r ) {
if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
$r['headers']['Referer'] = 'http://<referer>/';
}
return $r;
}
@tott
tott / gist:7384971
Created November 9, 2013 12:33
Enable exporting of Nav menus via WP Exporter
<?php
function tott_enable_menu_export() {
global $wp_post_types;
$wp_post_types['nav_menu_item']->_builtin = false;
}
add_action( 'load-export.php', 'tott_enable_menu_export' );