Skip to content

Instantly share code, notes, and snippets.

@stephenharris
stephenharris / wp-user-registration-query.php
Last active October 6, 2021 12:55
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
*/
;( function( $, obj ) {
var uno = function( e ) {
e.preventDefault();
var $this = $( this );
$.ajax( {
type: "POST",
url: obj.ajaxurl
+ "?action=" + obj.action
@stephenharris
stephenharris / is-descendent-of.php
Created May 29, 2013 23:26
Check if current page is a descendant of the specified one.
<?php
/**
* Is the current page a descendent of page identified by the path (not slug).
* A page is not a descendent of itself!
* @link http://wordpress.stackexchange.com/questions/101213/does-is-child-exist-in-wp-3-5-1
* @param string $page_path The path of the page, e.g. mypage/mysubpage
* @return boolean True if current page is a descednent of specified $page_path. False otherwise.
*/
function is_descendent_of( $page_path ){
@stephenharris
stephenharris / get_the_parent_terms.php
Created June 13, 2013 10:32
Get taxonomy terms of a post who have a child term also associated with a post.
<?php
/**
* Returns a term IDs of terms that are associated with a post, and who have
* child terms also associated with the post.
*
* Please note, 'parent' is a slight misnomer. If you have category structure:
* Cat A > Sub-Cat B > Sub-Sub-Cat C
* and a post belongs to A and B, but not C. 'B' is not considered a parent term
* for this post.
*
<?php
/**
* An implementation of the AES cipher (CBC mode).
* For reference http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
*
* @author Stephen Harris ([email protected])
* @license GPL
*
* Example usage:
@stephenharris
stephenharris / kill-the-bot.php
Last active December 19, 2015 15:58
A really simple method of dealing with brute-force attacks. This is not about securing yourself from these attacks - it's stopping them wasting your server resources when they patently won't work.
<?php
/**
* A really simple method of dealing with brute-force attacks.
* This is not about securing yourself from these attacks - it's stopping them wasting your
* server resources when they patently won't work.
*
* Put this at the very top of your wp-config.php. Add other banned usernames as desired.
* You may wish to prevent users from registering them.
*/
@stephenharris
stephenharris / bbpress-kses.php
Last active February 3, 2020 08:44
By default bbpress can be quite strict on the HTML it allows in posts (tags are whitelisted). The following loosens those restrictions and is taken from this post: http://buddypress.org/support/topic/tutorial-allow-more-html-tags-in-bp-forum-topics/
<?php
function myprefix_kses_allowed_tags($input){
return array_merge( $input, array(
// paragraphs
'p' => array(
'style' => array()
),
'span' => array(
'style' => array()
),
@stephenharris
stephenharris / pre-tags-in-comments.php
Created August 12, 2013 15:07
Allow pre tags in comments
<?php
/**
* Allow 'pre' tags in comments.
* This is not by default allowed for users who cannot publish 'unfiltered_html'.
* Maybe this should go in WP-MarkDown?
*
*/
add_filter( 'wp_kses_allowed_html', 'myprefix_allow_pre_tags_in_comments', 10, 2 );
function myprefix_allow_pre_tags_in_comments( $tags, $context ){
if( 'pre_comment_content' == $context ){
@stephenharris
stephenharris / eo-theme-direct.php
Created September 11, 2013 19:01
Register a template location with Event Organiser for your theme
<?php
/**
* Registers the directory "[child-theme-dir]/event-organiser" as a template location for
* Event Organiser. EO will look there when looking for the plug-in template files (e.g. single-event.php, archive-event.php, etc )
*
*/
function mytheme_register_eventorganiser_stack( $stacks ){
//$stacks is an array of (absolute) directory paths. EO will look in the order
//in which they appear in the array
@stephenharris
stephenharris / style.css
Created September 20, 2013 12:41
Demonstration of how to customise the event list widget. Provides an example template with CSS styling, as used in the Omega theme (http://wp-event-organiser.com/demo/).
/**
* This should be added to your theme's style.css
*/
.eo-events-widget{ font-size: 14px }
.eo-events-widget li{ overflow:hidden;}
.eo-events .eo-date-container{ color:white;float:left;;text-align: center;width: 35px;line-height: 1.3; margin:0px 5px; }
.eo-events .eo-date-month{ margin: 0px;display: block;font-size: 14px;font-variant: small-caps;color: white;letter-spacing: 3.2px;text-align: center;}
.eo-events .eo-date-day{ display: block;margin: 0px;border: none;font-size: 20px; }
.eo-events .eo-date-container{ background: #1e8cbe}
.eo-events .eo-date-day{ background: #78c8e6}