Skip to content

Instantly share code, notes, and snippets.

View rheinardkorf's full-sized avatar

Rheinard Korf rheinardkorf

View GitHub Profile
@rheinardkorf
rheinardkorf / gist:6834dc067c7890b9f2c3
Last active August 29, 2015 14:03
A simple ruby script to add to a TextMate bundle that aligns PHP key/value pairs.
View gist:6834dc067c7890b9f2c3
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -wKU
# Author: Rheinard Korf
# Usage:
# * Create a new bundle (or add to existing bundle).
# * Create a new command (e.g. KeyValue Alignment) and set a shortcut key (e.g. Ctrl+Cmd+Option+] )
# * Paste the code in the command editor and save the bundle (Cmd+S)
#
# Now select a set of key/value pairs (not the whole array) and try out the new command.
@rheinardkorf
rheinardkorf / gist:56078b6907ddb6c041e9
Created June 30, 2014 06:53
A Ruby script for TextMate to cleanup your project's PHP according to WordPress PHP Coding Guidelines.
View gist:56078b6907ddb6c041e9
#!/usr/bin/env ruby
# Author: Rheinard Korf
# Usage:
# Needs to be added to a TextMate bundle as a new 'Command'
# Set command's input to 'None' and output to 'Show in Tool Tip'
# What it does:
# - Adds whitespace inside parentheses.
@rheinardkorf
rheinardkorf / wp-cleanup.rb
Last active August 29, 2015 14:03
A Ruby command line script to cleanup your project's PHP according to WordPress PHP Coding Guidelines.
View wp-cleanup.rb
#!/usr/bin/env ruby
# Author: Rheinard Korf
# Usage:
# Run from command line by passing the path as an argument (add a trailing slash).
# If path is not set it will use the current directory. (Not recommended)
# Examples:
# ruby wp-cleanup.rb /my/project/path/
# (OR set as executable "chmod +x wp-cleanup.rb")
View git-zipit.sh
#!/bin/bash
# A script I use daily to quickly zip up a git repo.
# Note you will need: https://github.com/Kentzo/git-archive-all
#
# Adaptation of: https://gist.github.com/uglyrobot/e872d1a9efc122b6bae2
if [[ $# -eq 0 ]] ; then
echo "Please enter a version number:"
read VERSION
@rheinardkorf
rheinardkorf / vvv_host_update.php
Last active August 29, 2015 14:08
Simple WordPress plugin for VVV to update your vvv-hosts file with your new sites, or remove sites. Running 'vagrant reload' will update local hosts file if you have the vagrant-hostsupdater plugin installed. NOTE: Don't forget to update $site_folder.
View vvv_host_update.php
<?php
/*
Plugin Name: VVV Host Update
Plugin URI: http://rheinardkorf.com
Description: Updates the vvv-hosts file for multisite configs with subdomain enabled.
Author: Rheinard Korf
Author URI: http://rheinardkorf.com
Version: 1.0
Network: True
@rheinardkorf
rheinardkorf / MyPlugin.php
Last active August 29, 2015 14:18
One approach to implement a class autoloader for WordPress plugin development. This file will for the most part be untouched once the structure is in place. The real development starts in the library folder.
View MyPlugin.php
<?php
/**
* @package MyPlugin
*/
//Before playing with this file, see the other file in the gist. Read the comments.
if( ! class_exists( 'MyPlugin' ) ) {
class MyPlugin {
@rheinardkorf
rheinardkorf / php_properties.rb
Last active August 29, 2015 14:20
Searches a PHP Class for declared properties, uses and implicit properties. Not overly elegant, but scratched an annoying itch!
View php_properties.rb
#!/usr/bin/env ruby
declared_properties = []
properties = []
implicit_properties = []
if ARGV[0].to_s.strip.length == 0
puts 'No filename specified.'
exit
end
@rheinardkorf
rheinardkorf / prosites-remove-ads-on-given-pages.php
Last active November 2, 2015 00:39
Remove Pro Sites Ad modules from given pages/posts - This snippet is used to prevent ads from showing up on the front end for given pages or post types on your site.
View prosites-remove-ads-on-given-pages.php
<?php
// ---------------------------------------------
// Remove this line and up if you're adding it to an existing PHP file
// Add this to a theme's functions.php file or a custom plugin.
// This will precent the ads from showing on certain pages on your site
function 20151102_remove_ads_on_page ( $setting, $default ) {
// Option 1 -- Filter by page IDS specified as array
@rheinardkorf
rheinardkorf / developer_login.php
Last active January 11, 2016 01:16
WordPress auto-login
View developer_login.php
<?php
/*
* Auto-login script to save having to manually login when developing a WP site.
*
* Place in wp-content/mu-plugins and remember to add to .gitignore for safety
*
* Add the DEV_GET_PARAMETER to the url to activate the script and login for you
* e.g. http://localhost:8080/?dev
*/
View gist:2a0a64a7a976e36b9656
<?php
class MyPlugin {
/**
* Add this at top of your plugin class constructor or whichever method in your class you use to bootstrap your plugin.
* e.g. public static function bootstrap()
*/
public static function bootstrap() {
if ( version_compare( '5.3', phpversion(), '>' ) ) {