Skip to content

Instantly share code, notes, and snippets.

@alexkingorg
alexkingorg / spam-comment-script.txt
Created December 22, 2013 16:04
A spam comment script with replacement clauses intact - accidentally submitted in it's entirety to my site.
{
{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-textarea-form-submit-cmd-enter.js
Last active June 9, 2023 11:40
Submit a form on Command+Enter when in a textarea field.
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 / sort-colors.php
Created March 22, 2012 13:44
Sort colors from dark to light
<?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 July 6, 2012 14:25
Conditional loading of a plugin within a WordPress theme.
<?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-disable-button-after-submit.js
Last active October 10, 2017 13:16
After form submit, disable submit button.
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 September 3, 2011 23:42
Change the brightness of the passed in hex color in 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 January 3, 2012 04:28
WordPress per-year blog stats
<?php
header('Content-type: text/plain');
global $wpdb;
?>
<table class="numbers">
<thead>
<tr>
<th>&nbsp;</th>
@alexkingorg
alexkingorg / wp-plugin-path.php
Created December 15, 2011 19:04
Defining symlink compatible paths for WordPress plugins
<?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 February 6, 2014 21:01
Some starter WordPress code for saving pages/posts as favorite.
<?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 January 16, 2012 18:43
Character counter for WordPress editor
<?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);