Skip to content

Instantly share code, notes, and snippets.

View kfriend's full-sized avatar

Kevin Friend kfriend

  • 742 Evergreen Terrace
View GitHub Profile
@kfriend
kfriend / gist:4756594
Last active December 12, 2015 10:09
Simple software version comparer. Provides ability to compare an arbitrary number of version segments. Non numberic charters not supported
<?php
function compare_versions(
$version, $compareVersion, $lookup = array('greater' => 1, 'equal' => 0, 'less' => -1)
)
{
$version = explode('.', $version);
$compareVersion = explode('.', $compareVersion);
$count = max(count($version), count($compareVersion));
@kfriend
kfriend / gist:5045040
Created February 27, 2013 04:19
12 hour select field
<?php
function select_12_hour()
{
$return = '';
for ($i = 0; $i < 24; $i++)
{
$period = ($i < 12) ? 'a.m.' : 'p.m.';
@kfriend
kfriend / gist:5048470
Created February 27, 2013 14:54
Simple one-file honeypot
<?php
/*
* Simple Honeypot
*
* Takes request and stores the users IP, user-agent, and request into separate files. Useful
* for logging requests to locations that no one should be poking around.
*
* To do:
* - Add user-agent blocking
@kfriend
kfriend / gist:5048507
Last active December 14, 2015 07:09
Add a WordPress editor "Styles" drop down with top and bottom margin options
<?php
// Enable styles dropdown
add_filter('mce_buttons_2', function ($buttons) {
array_unshift($buttons, 'styleselect');
return $buttons;
});
// Register editor "Styles" drop down classes
add_filter('tiny_mce_before_init', function($styles) {
@kfriend
kfriend / gist:5048533
Created February 27, 2013 15:01
WordPress "editor-styles" to go along "Styles" editor drop down for margin entries
span.margin-class-applied,
#tinymce.wp-editor span.margin-class-applied
{
display: inline-block;
}
.margin-bottom-none,
#tinymce.wp-editor .margin-bottom-none
{
margin-bottom: 0;
@kfriend
kfriend / gist:5048566
Created February 27, 2013 15:06
Remove useless "Capital P Dangit" filter from WordPress
<?php
remove_filter('the_title', 'capital_P_dangit', 11);
remove_filter('the_content', 'capital_P_dangit', 11);
remove_filter('comment_text', 'capital_P_dangit', 31);
@kfriend
kfriend / gist:5048584
Last active December 14, 2015 07:09
WordPress helper for detecting if the current page is the login page
<?php
/**
* Is Login Page
*
* Detects if the current request is from the login page.
*
* Credit: http://stackoverflow.com/questions/5266945/wordpress-how-detect-if-current-page-is-the-login-page#5892694
*/
function isLoginPage()
@kfriend
kfriend / gist:5137776
Created March 11, 2013 21:09
Download a list of files from a location and save locally
<?php
// Where to save
$store = '';
// Files to download
$files = array(
'file',
);
@kfriend
kfriend / gist:5190690
Created March 18, 2013 20:50
Pre-Wordpress bootstrapping file which removes any development or staging domains from finalized output. Relies on an environment constant WP_ENVIRONMENT. Wordpress's index.php should be renamed to wordpress.php.
<?php
// Application bootstrap
// Start buffering output. We'll do some work on it later.
ob_start();
// Bootstrap Wordpress
// PHP 5.2 is still in use, so we cannot use __DIR__
require dirname(__FILE__).'/wordpress.php';
@kfriend
kfriend / gist:5240927
Created March 25, 2013 21:27
Add post-type-derived class to Wordpress's admin <body>
<?php
// functions.php
add_filter('admin_body_class', function($classes) {
global $wpdb, $post;
if (is_admin())
{