Skip to content

Instantly share code, notes, and snippets.

View jimboobrien's full-sized avatar

Jimobrien jimboobrien

View GitHub Profile
@jimboobrien
jimboobrien / shortcode.php
Created September 20, 2017 23:17 — forked from wpscholar/shortcode.php
A class for creating shortcodes in a flexible way.
<?php
/**
* Class My_Shortcode
*/
class My_Shortcode {
/**
* The shortcode attributes
*
@jimboobrien
jimboobrien / wp-get-excerpt-by-id.php
Created September 20, 2017 23:18 — forked from wpscholar/wp-get-excerpt-by-id.php
Get the excerpt for a WP_Post by post ID.
<?php
/**
* Get the excerpt for a WP_Post by post ID.
*
* @param int $post_id
*/
function get_excerpt_by_id( $post_id = 0 ) {
global $post;
$save_post = $post;
@jimboobrien
jimboobrien / sanitize.php
Created September 20, 2017 23:18 — forked from wpscholar/sanitize.php
Sanitize a value by passing it through one or more sanitization callbacks.
<?php
/**
* Sanitize a value by passing it through one or more sanitization callbacks.
*
* @param mixed $value
* @param callable|array $sanitize
* @return mixed
*/
function sanitize( $value, $sanitize ) {
@jimboobrien
jimboobrien / validate.php
Created September 20, 2017 23:19 — forked from wpscholar/validate.php
Validate a value by running it through one or more callbacks.
<?php
/**
* Validate a value by running it through one or more callbacks.
*
* @param mixed $value
* @param callable $validation
* @return bool
*/
function validate( $value, $validation ) {
@jimboobrien
jimboobrien / index-by.php
Created September 20, 2017 23:19 — forked from wpscholar/index-by.php
Index a collection of arrays/objects by a specific key/property.
<?php
/**
* Index a collection of arrays/objects by a specific key/property.
*
* @param string $index
* @param array $data
* @return array
*/
function index_by( $index, array $data ) {
@jimboobrien
jimboobrien / array-find.php
Created September 20, 2017 23:19 — forked from wpscholar/array-find.php
Case insensitive array_search() with partial matches
<?php
/**
* Case insensitive array_search() with partial matches.
*
* @param string $needle
* @param array $haystack
* @return bool|int|string
*/
public static function array_find( $needle, array $haystack ) {
@jimboobrien
jimboobrien / array-order-by-keys.php
Created September 20, 2017 23:19 — forked from wpscholar/array-order-by-keys.php
Order an array based an ordered set of keys. NOTE: Values that don't have a corresponding key in the array of keys will be dropped.
<?php
/**
* Order an array based an ordered set of keys.
* NOTE: Values that don't have a corresponding key in the array of keys will be dropped.
*
* @param array $array
* @param array $keys
* @return array
*/
public static function array_order_by_keys( array $array, array $keys ) {
@jimboobrien
jimboobrien / excerpt.php
Created September 20, 2017 23:19 — forked from wpscholar/excerpt.php
Generate an excerpt from provided content. Strips HTML, removes trailing punctuation and adds a 'more' string when text has been removed.
<?php
/**
* Get an excerpt
*
* @param string $content The content to be transformed
* @param int $length The number of words
* @param string $more The text to be displayed at the end, if shortened
* @return string
*/
@jimboobrien
jimboobrien / local-time.php
Created September 20, 2017 23:26 — forked from wpscholar/local-time.php
Properly fetch the local date / time in WordPress based on a Unix timestamp.
<?php
/**
* Fetch the local date/time in WordPress based on a Unix timestamp.
*
* @param int $timestamp
* @param string $format
* @return string
*/
function get_wp_local_date_time( $timestamp, $format = '' ) {
@jimboobrien
jimboobrien / jquery.toggleElement.js
Created September 20, 2017 23:27 — forked from wpscholar/jquery.toggleElement.js
A jQuery plugin that will toggle the display of an element when another element is clicked. When the toggled element is being displayed, clicking on the initiating element or any other element that is not the toggled element or its children will cause the toggled element to be hidden. Works on touchscreens.
(function( $ ) {
/**
* A jQuery plugin that will toggle the display of an element when another element is clicked.
* When the toggled element is being displayed, clicking on the initiating element or any other element that
* is not the toggled element or its children will cause the toggled element to be hidden.
*
* @param $el
* @returns {*}
*/