Skip to content

Instantly share code, notes, and snippets.

View codearachnid's full-sized avatar
🎯
Focusing

Timothy Wood codearachnid

🎯
Focusing
View GitHub Profile
<?php
/**
* Plugin Name: Deny Giant Image Uploads
* Description: Prevents Uploads of images greater than 3.2MP
* Author: TJNowell
* Author URI: http://tomjn.com
* Plugin URI: http://tomjn.com/164/clients-who-upload-huge-camera-photos-decompression-bombs/
* Version: 1.1
*/
<?php
function check_user_role($roles,$user_id=NULL) {
// Get user by ID, else get current user
if ($user_id)
$user = get_userdata($user_id);
else
$user = wp_get_current_user();
// No user found, return
@nikic
nikic / password_hashing_api.md
Created September 12, 2012 15:04
The new Secure Password Hashing API in PHP 5.5

The new Secure Password Hashing API in PHP 5.5

The [RFC for a new simple to use password hashing API][rfc] has just been accepted for PHP 5.5. As the RFC itself is rather technical and most of the sample codes are something you should not use, I want to give a very quick overview of the new API:

Why do we need a new API?

Everybody knows that you should be hashing their passwords using bcrypt, but still a surprising number of developers uses insecure md5 or sha1 hashes (just look at the recent password leaks). One of the reasons for this is that the crypt() API is ridiculously hard to use and very prone to programming mistakes.

@rjz
rjz / cs-jq-plugin-template.coffee
Created September 3, 2012 17:01
Coffeescript jQuery Plugin Class Template
# A class-based template for jQuery plugins in Coffeescript
#
# $('.target').myPlugin({ paramA: 'not-foo' });
# $('.target').myPlugin('myMethod', 'Hello, world');
#
# Check out Alan Hogan's original jQuery plugin template:
# https://github.com/alanhogan/Coffeescript-jQuery-Plugin-Template
#
(($, window) ->
@mikeschinkel
mikeschinkel / aeromaxx-parse-request.php
Created August 19, 2012 00:16
WordPress URLs for 1 taxonomy on 2 different custom post types
<?php
/**
* Answering: http://lists.automattic.com/pipermail/wp-hackers/2012-August/044119.html
* By: Mike Schinkel - http://about.me/mikeschinkel
*/
add_action( 'parse_request', 'aeromaxx_parse_request' );
function aeromaxx_parse_request( $wp ) {
if ( preg_match( '#^/(draw-results|ball-statistics)/game/([^/]+)/#', $_SERVER['REQUEST_URI'], $matches ) ) {
$wp->query_vars = array(
'post_type' => $matches[1], // Assumes your post types are registered with same name as your URL slugs
@alexkingorg
alexkingorg / deploy.sh
Created August 16, 2012 13:12 — forked from dancameron/deploy.sh
Script to deploy from Github to WordPress.org Plugin Repository
#! /bin/bash
#
# Script to deploy from Github to WordPress.org Plugin Repository
#prompt for plugin slug
echo -e "Plugin Slug: \c"
read PLUGINSLUG
# main config, set off of plugin slug
CURRENTDIR=`pwd`
// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
// http://gist.github.com/raw/63002/b53853727856bad494dcbb7ffed4fc17f289af92/gistfile1.rb
// $z is the pnormaldist with power = 0.05. I.e., pnormaldist(1-power/2)
function score($pos, $n) {
if ($n == 0) { return 0; }
$z = 1.95996397158435;
$phat = 1.0*$pos/$n;
return ($phat + $z*$z/(2*$n) - $z * sqrt(($phat*(1-$phat)+$z*$z/(4*$n))/$n))/(1+$z*$z/$n);
}
@feedmeastraycat
feedmeastraycat / get_post_id_by_meta_key_and_value.php
Created July 7, 2012 11:32
WordPress: Get post id by meta key and value
<?php
if (!function_exists('get_post_id_by_meta_key_and_value')) {
/**
* Get post id from meta key and value
* @param string $key
* @param mixed $value
* @return int|bool
* @author David M&aring;rtensson <david.martensson@gmail.com>
*/
function get_post_id_by_meta_key_and_value($key, $value) {
@franz-josef-kaiser
franz-josef-kaiser / example_post_status.php
Created June 14, 2012 13:07
Add a custom post status for WP (custom) post types
<?php
// No, Thanks. Direct file access forbidden.
! defined( 'ABSPATH' ) AND exit;
// INIT
add_action( 'after_setup_theme', array( 'unavailable_post_status', 'init' ) );
class unavailable_post_status extends wp_custom_post_status
{
/**
@maxrice
maxrice / us-state-names-abbrevs.php
Created May 23, 2012 18:32
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',