Skip to content

Instantly share code, notes, and snippets.

@Coopeh
Coopeh / get_domain_mapped_url.php
Created December 18, 2012 19:25
Get Domain Mapped URL From BlogID
<?php
// Function to get a blog/site's domain mapped url.
//
// You need to call it with a blog ID
//
// Example:
// $custom_blog_id = '14';
// echo get_domain_mapped_url( $custom_blog_id );
//
@Coopeh
Coopeh / nginx.conf
Last active December 10, 2015 13:18
# The final "error" text at the end of the next line is crucial
# You can also use any of the following in it's place:
# "debug | info | notice | warn | error | crit | alert | emerg"
error_log /dir/to/your/nginx/site.log error;
@Coopeh
Coopeh / user-select-mixin.less
Created January 3, 2013 16:11
User-Select LESS Mixin
.user-select(@user-select) {
-webkit-touch-callout: @user-select;
-webkit-user-select: @user-select;
-khtml-user-select: @user-select;
-moz-user-select: @user-select;
-ms-user-select: @user-select;
user-select: @user-select;
}
@Coopeh
Coopeh / nginx-multiple-if.conf
Created January 25, 2013 19:42
How to use multiple if statements in Nginx
set $posting 0; # Make sure to declare it first to stop any warnings
if ($request_method = POST) { # Check if request method is POST
set $posting N; # Initially set the $posting variable as N
}
if ($geoip_country_code ~ (BR|CN|KR|RU|UA) ) { # Here we're using the Nginx GeoIP module to block some spammy countries
set $posting "${posting}O"; # Set the $posting variable to itself plus the letter O
}
@Coopeh
Coopeh / header-esi.php
Created February 28, 2013 02:16
ESI included php file for loading the header images via jQuery
<?php require_once('/var/www/wordpress/wp-load.php'); ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('header.top-head').css('background-image', 'url(<?php header_image(); ?>)');
});
</script>
@Coopeh
Coopeh / default.vcl
Created February 28, 2013 02:20
Varnish ESI vcl_fetch
sub vcl_fetch {
set beresp.do_esi = true;
if (req.url ~ "header-esi.php"){
std.log("ESI found, don't cache, pass to nginx");
set client.identity = clusternginx;
return(hit_for_pass);
}
@Coopeh
Coopeh / header.php
Created February 28, 2013 02:26
WordPress custom header ESI include
<head>
<esi:include src="/wp-content/themes/random/header-esi.php"/>
</head>
@Coopeh
Coopeh / wordpress-auth.conf
Last active December 17, 2015 15:59
Fail2Ban filter for blocking administrator, adminadmin and admin usernames on authentication failure
# Fail2Ban configuration file
#
# Author: Charles Lecklider
#
[INCLUDES]
# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf
@Coopeh
Coopeh / jail.conf.sample
Created May 23, 2013 13:03
Fail2Ban jail.conf example for blocking bad auth in WordPress
[wordpress-admin]
enabled = true
filter = wordpress-admin
action = iptables-allports[name=PrimaryBlogger-admin, protocol=all]
logpath = /var/log/nginx/pblogger-error.log
findtime = 10800
bantime = 86400
maxretry = 2
@Coopeh
Coopeh / login-fail.php
Created May 23, 2013 13:05
Error log out bad auth on wp-login failure
add_action('wp_login_failed', 'log_wp_login_fail');
function log_wp_login_fail($username) {
$ip = ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') ? $_SERVER['REMOTE_ADDR'] : $_SERVER['X_FORWARDED_FOR'];
error_log("Authentication failure for $username from {$ip}");
}