Skip to content

Instantly share code, notes, and snippets.

@rohmann
rohmann / github_origin.php
Last active December 21, 2015 15:28
Ensure a web request is coming from github. Useful for setting up web hooks
<?php
function githubOrigin() {
function netMatch($CIDR,$IP) {
list ($net, $mask) = explode ('/', $CIDR);
return ( ip2long ($IP) & ~((1 << (32 - $mask)) - 1) ) == ip2long ($net);
}
return (netMatch("204.232.175.64/27",$_SERVER['REMOTE_ADDR']) || netMatch("192.30.252.0/22",$_SERVER['REMOTE_ADDR']));
}
@rohmann
rohmann / gitarchivemaster.sh
Created August 24, 2013 05:47
Clones repository and creates zip file. (repo-name-master.zip)
#!/bin/bash
# Usage: $ ./gitarchivemaster.sh http://url/to/repo.git dest-folder
url=$1
name=$2
#Clone repo (delete existing)
rm -fR ${name}
git clone ${url} ${name}
@rohmann
rohmann / multisite-default-role.php
Last active December 21, 2015 05:59
Change the default role for users when creating a new site. http://git.io/6_L4Bw
<?php
//This will make the user an editor instead of admin for a new site
add_action('wpmu_new_blog','change_new_blog_role',100,6);
function change_new_blog_role($blog_id, $user_id, $domain, $path, $site_id, $meta) {
remove_user_from_blog($blog_id, $user_id);
add_user_to_blog($blog_id, $user_id, 'editor');
}
@rohmann
rohmann / toolbar-nav.php
Last active December 21, 2015 04:58
This will give you a "theme location" for nav menus that will be placed in the toolbar. Had this in a repo, but moving to a gist.
<?php
/*
Plugin Name: Custom Toolbar
Plugin URI:
Description:
Author: Alexander Rohmann
Version: 1.0
Author URI: http://github.com/rohmann
*/
@rohmann
rohmann / wp-tiny-spam-protect.php
Last active December 21, 2015 04:59
Simple spam protection for Wordpress. Base64 encode with PHP, then decode with Javascript. Was in a repo, but just moving to gist as it's simple enough.
<?php
//Create a shortcode that encrypts the given text and adds a tag around the text that will lated be used to find the text on the client side
add_shortcode( 'nospam', function ( $atts, $content = null ) {
return '<em class="tsp-nospam">'.base64_encode($content).'</em>';
});
add_action('wp_head', function(){ ?>
<script>/* js base64 decode modified/condensed from http://www.webtoolkit.info/javascript-base64.html*/function wptspdecode(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c="",d,e,f,g,h,i,j,k=0,l="",m=c1=c2=0;a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(k<a.length){g=b.indexOf(a.charAt(k++));h=b.indexOf(a.charAt(k++));i=b.indexOf(a.charAt(k++));j=b.indexOf(a.charAt(k++));d=g<<2|h>>4;e=(h&15)<<4|i>>2;f=(i&3)<<6|j;c+=String.fromCharCode(d);i!=64&&(c+=String.fromCharCode(e));j!=64&&(c+=String.fromCharCode(f))}k=0;while(k<c.length){m=c.charCodeAt(k);if(m<128){l+=String.fromCharCode(m);k++}else if(m>191&&m<224){c2=c.charCodeAt(k+1);l+=String.fromCharCode((m&31)<<6|c2&6
@rohmann
rohmann / wp-debug-logging.php
Last active December 20, 2015 23:38
http://git.io/gJANNQ Enables debug logging for Wordpress.This snippet can be placed in wp-config.php to quickly setup debug logging. Adapted from: http://premium.wpmudev.org/forums/topic/the-right-way-to-debug-php-in-wordpress
define('WP_DEBUG', true);
/**
* When debug mode is enabled, you can enable logging to store errors in wp-content/debug.log
* This is useful for finding errors that might not get displayed on screen
*
* The next conditional section will make sure errors are not shown to users when logging is enabled
* This helps with quick troubleshooting on live sites
*/
define('WP_DEBUG_LOG', true);
@rohmann
rohmann / bp-bulk-add-users.php
Last active November 30, 2021 22:16
Quick users page mod to allow for bulk adding to BuddyPress groups.
<?php
add_action('load-users.php',function() {
if(isset($_GET['action']) && isset($_GET['bp_gid']) && isset($_GET['users'])) {
$group_id = $_GET['bp_gid'];
$users = $_GET['users'];
foreach ($users as $user_id) {
groups_join_group( $group_id, $user_id );
}