Skip to content

Instantly share code, notes, and snippets.

@stephenh1988
stephenh1988 / aes-cbc.php
Created August 20, 2012 18:09
PHP Implementation of AES-CBC
<?php
/**
* An implementation of the AES cipher (CBC mode).
* For reference http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
*
* @author Stephen Harris (contact@stephenharris.info)
* @license GPL
*
* Example usage:
@stephenh1988
stephenh1988 / lang_change_button.php
Created July 7, 2012 11:51 — forked from franz-josef-kaiser/lang_change_button.md
Change the language by the click of a button (link in the admin bar).
<?php
! defined( 'ABSPATH' ) AND exit;
/*
Plugin Name: User Language Switcher
Plugin URI: http://example.com
Description: Change the language per user, by the click of a button
Author: Stephen Harris
Author URI: http://example.com
Contributors: Franz Josef Kaiser
Version: 0.2
@stephenh1988
stephenh1988 / sh_get_plugins_by_author.php
Created July 2, 2012 16:55
Function to retrieve an array of (WordPress hosted) plug-ins by a particular author, given by their WordPress repository username
<?php
/**
* Function to retrieve an array of (WordPress hosted) plug-ins by a particular author, given by their WordPress repository username.
*
* For information on using the WordPress API see the wptuts tutorial: (link to follow)
*
*
* @param author - WordPress username
* @param fields - which fields (plug-in details) to return. See tutorial for details.
*/
@stephenh1988
stephenh1988 / SH-Which-Template-Is-This.php
Created June 22, 2012 12:38
Prints in the footer the template being used for that page
<?php
/**
* Plugin Name: SH Which Template Is This
* Description: Prints in the footer the template being used for that page.
* Author: Stephen Harris contact@stephenharris.info
* Author URI: http://stephenharris.info
* License: GPL
* License URI: http://www.gnu.org/copyleft/gpl.html
*/
class SH_Which_Template_Is_This{
@stephenh1988
stephenh1988 / toolbar-hooks.php
Created June 19, 2012 17:13 — forked from thefuxia/toolbar-hooks.php
T5 Toolbar hooks: Adds a toolbar item with the current page hooks.
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Toolbar hooks
* Description: Adds a toolbar item with the current page hooks.
* Version: 2012.06.19
* Author: Thomas Scholz <info@toscho.de>
* Author URI: http://toscho.de
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
@stephenh1988
stephenh1988 / frontend-publish.php
Created June 13, 2012 13:53
Provides a function to add a 'publish' link to posts for use on the front end
<?php
/*
* Provides a function to add a 'publish' link to posts.
* Use sh_frontend_publish() to display the link
*
*/
function sh_frontend_publish(){
$post_id = get_the_ID();
if( 'draft' == get_post_status($post_id) && current_user_can('edit_post',$post_id) && current_user_can('publish_posts') ){
@stephenh1988
stephenh1988 / sh-wp-dropdown-taxonomies.php
Created June 9, 2012 20:40
A walker class to use that extends wp_dropdown_categories and allows it to use the term's slug as a value rather than ID
<?php
/*
* A walker class to use that extends wp_dropdown_categories and allows it to use the term's slug as a value rather than ID.
*
* See http://core.trac.wordpress.org/ticket/13258
*
* Usage, as normal:
* wp_dropdown_categories($args);
*
@stephenh1988
stephenh1988 / previous-next-sibling.php
Created June 7, 2012 10:19
Get's the next/previous page (or hierarchical cpt) with the same parent as the current post.
<?php
/*
* Gets IDs of the previous and next siblings (pages with the same parent as current post).
* Then uses wpse5422_display_prev_next to display links to them
* Must be used inside the loop.
*
* This is my solution to: http://wordpress.stackexchange.com/a/54463/9364
*/
function wpse5422_the_page_siblings(){
$post_id = get_the_ID();
@stephenh1988
stephenh1988 / wp-blog-timezone.php
Created May 18, 2012 10:23
Returns the blog timezone as a DateTimeZone object
<?php
/*
* Returns the blog's timezone as a DateTimeZone object
*
*/
function sh_get_blog_timezone(){
$timezone = wp_cache_get( 'sh_blog_timezone' );
if ( false === $timezone || ! ($timezone instanceof DateTimeZone) ) {
@stephenh1988
stephenh1988 / wp-user-registration-query.php
Created May 8, 2012 10:01
Get all users registered between two dates
<?php
/*
* Get all users registered after $start and before $end (dates in yyyy-mm-dd format)
*
* Based on my answer to this question: http://wordpress.stackexchange.com/questions/51485/how-can-i-query-all-users-who-registered-today/51492#51492
*
* @param (string) $start - start date in yyyy-mm-dd format
* @param (string) $end - end date in yyyy-mm-dd format
*/