This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Validate a value by running it through one or more callbacks. | |
* | |
* @param mixed $value | |
* @param callable $validation | |
* @return bool | |
*/ | |
function validate( $value, $validation ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 = '' ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 {*} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ( $ ) { | |
/** | |
* A jQuery plugin that will position an element relative to another element, regardles of whether or not they share the | |
* same parent in the DOM. | |
* | |
* Note: This must be called within a $(document).ready() call to work properly. If loading images in the element | |
* that aren't specifically sized via CSS, it may be necessary to call this within a $(window).load() call | |
* depending on the positioning used. | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Creating a class to handle a WordPress shortcode is overkill in most cases. | |
* However, it is extremely handy when your shortcode requires helper functions. | |
*/ | |
class My_Shortcode { | |
protected | |
$atts = array(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_enqueue_scripts', 'enqueue_my_styles' ); | |
/** | |
* Example callback function that demonstrates how to properly enqueue conditional stylesheets in WordPress for IE. | |
* IE10 and up does not support conditional comments in standards mode. | |
* | |
* @uses wp_style_add_data() WordPress function to add the conditional data. | |
* @link https://developer.wordpress.org/reference/functions/wp_style_add_data/ |