Skip to content

Instantly share code, notes, and snippets.

Alex King alexkingorg

Block or report user

Report or block alexkingorg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alexkingorg
alexkingorg / sort-colors.php
Created Mar 22, 2012
Sort colors from dark to light
View sort-colors.php
<?php
function cf_sort_hex_colors($colors) {
$map = array(
'0' => 0,
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 5,
@alexkingorg
alexkingorg / maybe-include-plugin.php
Created Jul 6, 2012
Conditional loading of a plugin within a WordPress theme.
View maybe-include-plugin.php
<?php
// Run this code on 'after_theme_setup', when plugins have already been loaded.
add_action('after_setup_theme', 'my_load_plugin');
// This function loads the plugin.
function my_load_plugin() {
// Check to see if your plugin has already been loaded. This can be done in several
// ways - here are a few examples:
@alexkingorg
alexkingorg / jquery-textarea-form-submit-cmd-enter.js
Last active Jun 23, 2018
Submit a form on Command+Enter when in a textarea field.
View jquery-textarea-form-submit-cmd-enter.js
jQuery(function($) {
// add a handler for form submit (makes an AJAX call)
$(document).on('submit', 'form.my-class', myFormSubmitHandler);
// submit form on command + enter if in a textarea
$(document).on('keydown', 'body', function(e) {
if (!(e.keyCode == 13 && e.metaKey)) return;
var $target = $(e.target);
if ($target.is('textarea')) {
@alexkingorg
alexkingorg / spam-comment-script.txt
Created Dec 22, 2013
A spam comment script with replacement clauses intact - accidentally submitted in it's entirety to my site.
View spam-comment-script.txt
{
{I have|I've} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It's|It is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good content as you did, the {internet|net|web} will be {much more|a lot more} useful than ever before.|
I {couldn't|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I'll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch} your {rss|rss feed} as I {can not|can't} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you've} any? {Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may just|may|could} subscribe. Thanks.|
{It is|It's} {appropriate|perfect|the best} time to make some plans for the future and {it is|i
@alexkingorg
alexkingorg / jquery-disable-button-after-submit.js
Last active Oct 10, 2017
After form submit, disable submit button.
View jquery-disable-button-after-submit.js
jQuery(function($) {
// set data-after-submit-value on input:submit to disable button after submit
$(document).on('submit', 'form', function() {
var $form = $(this),
$button,
label;
$form.find(':submit').each(function() {
$button = $(this);
label = $button.data('after-submit-value');
if (typeof label != 'undefined') {
@alexkingorg
alexkingorg / hex_color_mod.php
Created Sep 3, 2011
Change the brightness of the passed in hex color in PHP
View hex_color_mod.php
<?php
/**
* Change the brightness of the passed in color
*
* $diff should be negative to go darker, positive to go lighter and
* is subtracted from the decimal (0-255) value of the color
*
* @param string $hex color to be modified
* @param string $diff amount to change the color
@alexkingorg
alexkingorg / wp-stats.php
Created Jan 3, 2012
WordPress per-year blog stats
View wp-stats.php
<?php
header('Content-type: text/plain');
global $wpdb;
?>
<table class="numbers">
<thead>
<tr>
<th>&nbsp;</th>
@alexkingorg
alexkingorg / wp-plugin-path.php
Created Dec 15, 2011
Defining symlink compatible paths for WordPress plugins
View wp-plugin-path.php
<?php
// include this near the top of your plugin file
$my_plugin_file = __FILE__;
if (isset($plugin)) {
$my_plugin_file = $plugin;
}
else if (isset($mu_plugin)) {
@alexkingorg
alexkingorg / cf-favorites.php
Created Feb 6, 2014
Some starter WordPress code for saving pages/posts as favorite.
View cf-favorites.php
<?php
/*
Plugin Name: Favorites
Plugin URI:
Description: Let users save posts/pages as favorites - then access them through a quick menu.
Version: 1.0
Author: Crowd Favorite
Author URI: http://crowdfavorite.com
*/
@alexkingorg
alexkingorg / wp-editor-char-count.php
Created Jan 16, 2012
Character counter for WordPress editor
View wp-editor-char-count.php
<?php
// handy if you write status posts and send them to Twitter
function akv3_editor_char_count() {
?>
<script type="text/javascript">
(function($) {
wpCharCount = function(txt) {
$('.char-count').html("" + txt.length);
You can’t perform that action at this time.