Skip to content

Instantly share code, notes, and snippets.

View mcaskill's full-sized avatar
🥃

Chauncey McAskill mcaskill

🥃
View GitHub Profile
@mcaskill
mcaskill / wp-intart-sort.php
Created May 2, 2015 05:35
WordPress : Sort post titles in alphabetical order, disregarding initial definite and indefinite articles
<?php
/**
* File: Sort posts in alphabetical order, ignoring initial articles.
*
* This condition is achieved using the `post_fields` and `posts_orderby`
* filters. The implementer must provide their own list of definite and
* indefinite articles for the hooks to ignore.
*
* To enable natural language sorting, pass the following Query parameter:
@mcaskill
mcaskill / charcoal-collection-loader-model-caching.php
Created July 3, 2019 14:30
Charcoal : How to cache object data from a `CollectionLoader` into a `ModelLoader` cache namespace.
<?php
use Pimple\Container;
use Charcoal\Model\ModelInterface;
use Charcoal\Model\CollectionInterface;
use App\Post;
$container = new Container();
$container['cache'] = function (Container $container) {
@mcaskill
mcaskill / Function.Blade-Props.php
Created April 28, 2019 19:54
Blade : Keep partials reusable with two presenter-style functions.
<?php
/**
* Convert array to an object recursively, a new instances of the stdClass.
*
* @param array $props The array to convert into an object.
* @return object
*/
function props(array $props) : object
{
@mcaskill
mcaskill / wp-without-hooks.php
Last active January 18, 2019 17:09 — forked from westonruter/01-common-example.php
WordPress \ Hooks : Temporarily disable hooks while executing a given callback.
<?php
/**
* Call the callback with one or all handlers disabled for the given action or filter.
*
* Temporarily disables the specified hook, or all hooks, from a specified filter or action
* before calling $callback.
*
* @link https://gist.github.com/westonruter/6647252
*
@mcaskill
mcaskill / wp-add-hooks.php
Created January 18, 2019 17:05
WordPress \ Hooks : Hook a function or method to an array of actions or filters.
<?php
/**
* Hook a function or method to an array of actions.
*
* @param string[] $tags Array of names of filters to hook the $function callback to.
* @param callable $function_to_add The callback to be run when the filter is applied.
* @param int $priority Optional. Used to specify the order in which the functions
* associated with a particular action are executed. Default 10.
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
@mcaskill
mcaskill / Function.Is-Blank.php
Last active September 10, 2018 01:58
PHP : Determine whether a variable has a non-empty value.
<?php
if (!function_exists('is_blank')) {
/**
* Determine whether a variable has a non-empty value.
*
* Alternative to {@see empty()} that accepts non-empty values:
* - _0_ (0 as an integer)
* - _0.0_ (0 as a float)
* - _"0"_ (0 as a string)
@mcaskill
mcaskill / Function.OneOf.php
Last active September 10, 2018 01:49
PHP : Returns the first argument that is set and non-empty.
<?php
if (!function_exists('oneof')) {
/**
* Returns the first argument that is set and non-empty.
*
* It will guess where to stop based on the types of the arguments, e.g.
* "" has priority over array() but not 1.
*
* @link https://github.com/vito/chyrp/ Origin of function.
@mcaskill
mcaskill / Function.Fallback.php
Last active September 10, 2018 01:38
PHP : Sets a given variable if it is not set with the last parameter or the first non-empty value.
<?php
if (!function_exists('fallback')) {
/**
* Sets a given variable if it is not set.
*
* The last of the arguments or the first non-empty value will be used.
*
* @link https://github.com/vito/chyrp/ Origin of function.
* @param mixed $var The variable to return or set.
@mcaskill
mcaskill / README.md
Last active January 5, 2018 15:03
Subtree split of the Sage Theme Wrapper classes (see 'roots/sage')

💀 Sage Theme Wrapper for WordPress

This gist has been deprecated and moved to a repository and published on Packagist:
mcaskill/sage-theme-wrapper

Usage

Add the following filter to your theme's functions.php:

@mcaskill
mcaskill / README.md
Last active January 5, 2018 15:01
Subtree split of the Bedrock Autoloader class (see 'roots/bedrock')

💀 Bedrock Autoloader for WordPress

This gist has been deprecated and moved to a repository and published on Packagist:
mcaskill/bedrock-autoloader

Standalone version of the Bedrock Autoloader for must-use plugins.

Usage

Add the following snippet to the mu-plugins directory (or add bedrock-autoloader.php).