Skip to content

Instantly share code, notes, and snippets.

/**
* A shortcode to display the number of testimonials.
*
* For Strong Testimonials plugin.
*
* For all: [my_testimonial_count]
* For a specific category (by slug): [my_testimonial_count category="abc"]
*
* @param $atts
* @param null $content
@cdillon
cdillon / wpmtst_get_the_category_list.php
Created January 19, 2016 12:39
Use in place of `get_the_category_list` in your single-wpm-testimonial.php template file.
/**
* Retrieve category list in either HTML list or custom format.
* This is a copy of the native `get_the_category_list` function.
*
* @global WP_Rewrite $wp_rewrite
*
* @param string $separator Optional, default is empty string. Separator for between the categories.
* @param string $parents Optional. How to display the parents.
* @param int|bool $post_id Optional. Post ID to retrieve categories.
* @return string
@cdillon
cdillon / theme-screenshot-inheritance.php
Last active November 15, 2015 19:17
A minimalist WordPress plugin to allow child themes to inherit their parent's screenshot.
<?php
/**
* Plugin Name: Theme Screenshot Inheritance
* Description: Child themes without screenshots inherit their parent theme's screenshot.
*
* Drop this in the /plugins or /mu-plugins directory.
*/
/**
* Add parent screenshot to child theme.
@cdillon
cdillon / gist:59033a52ba9796930e6e
Created April 22, 2015 23:30
require minimum length for WordPress user login
/**
* Additional registration checks.
*
* This filter is documented in wp-includes/user.php
*/
function my_registration_errors( $errors, $sanitized_user_login, $user_email ) {
if ( strlen( $sanitized_user_login ) < 5 ) {
$errors->add( 'username_too_short', __( '<strong>ERROR</strong>: Username must be at least 5 characters.' ) );
}
return $errors;
// Remove classes that have given prefix
// Example:
// You have an element with classes "apple juiceSmall juiceBig banana"
// You run:
// $elem.removeClassPrefix('juice');
// The resulting classes are "apple banana"
// NOTE: discussion of implementation techniques for this, including why simple RegExp with word boundaries isn't correct:
// http://stackoverflow.com/questions/57812/jquery-remove-all-classes-that-begin-with-a-certain-string#comment14232343_58533
@cdillon
cdillon / gist:31b4ccc4185dbd4b778b
Last active May 10, 2016 12:35
example of a custom form in WordPress using math Captcha plugin by BestWebSoft
// shortcode: [demo-form]
function demo_form_shortcode( $atts ) {
$name = '';
$email = '';
$company = '';
$errors = array();
if ( isset( $_POST['demo_form_submitted'] )
/**
* Return a timestamp with the format "m/d/yy h:MM:ss TT"
* @type {Date}
*/
function timeStamp() {
// Create a date object with the current time
var now = new Date();
// Create an array with the current month, day and time
<?php
/* Register custom post types on the 'init' hook. */
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 0.1.0
* @access public