Skip to content

Instantly share code, notes, and snippets.

View chaance's full-sized avatar
🏄‍♂️
Out there

Chance Strickland chaance

🏄‍♂️
Out there
View GitHub Profile
@chaance
chaance / wp-class-autoloader.php
Last active April 17, 2018 21:52
wp-class-autoloader
<?php
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class autoloader
*
* @param string $class Qualified class name.
*/
Array.prototype.shuffle = function() {
var i = this.length, // array length to determine current index in loop
r, // random index value
p; // current index value
// Loop through array indicies
while ( i-- ) {
// always returns less than the index to ensure it always exists
r = Math.floor( Math.random() * i );
@chaance
chaance / get-logo.php
Last active January 24, 2018 15:48
Get URL of the custom logo in WordPress.
<?php
/**
* Get theme logo URL
*/
function xx_get_logo() {
$custom_logo_id = get_theme_mod( 'custom_logo' );
if ( ! $custom_logo_id )
return;
$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
@chaance
chaance / wp-social-share-link.php
Last active March 23, 2018 17:52
Generate JS social sharing links for posts or pages. Uses my get_logo function (https://git.io/vbZOT).
@chaance
chaance / wp-exclude-terms-uncategorized.php
Last active March 23, 2018 17:46
WordPress function to exclude `Uncategorized` category from all terms lists.
<?php
/**
* Exclude `Uncategorized` category from all terms lists.
*
* @param array $terms Array of taxonomy terms.
* @return array List of terms, less 1
*/
function xx_exclude_terms_uncategorized( $terms ) {
$exclude_terms = [ 1 ]; // Exclude `Uncategorized` category
if ( ! empty( $terms ) && is_array( $terms ) ) {
@chaance
chaance / wp-get-field-as-link.php
Last active March 23, 2018 17:44
Validate text input as valid URL for WordPress
@chaance
chaance / twitter-functions.php
Last active February 7, 2018 17:15
Uses twitteroauth PHP library to render latest tweets from a user's feed. https://github.com/abraham/twitteroauth
<?php
/**
* Wrap input inside a link to include in the body of the tweet.
*
* @todo more validation (URL?)
*
* @param string $url URL to use as a link.
* @param string $text Text to wrap.
* @return [type] Formatted HTML link.
*/
@chaance
chaance / sass-utils.scss
Last active January 30, 2019 22:04
Some of my go-to sass mixins/functions. #prettycool.
/// Screen breakpoints for media queries
$breakpoints: (
'medium': 40em,
'large': 64em,
'xlarge': 75em,
'xxlarge': 90em
) !default;
/// Mixin to manage responsive breakpoints
/// @link https://css-tricks.com/snippets/sass/mixin-manage-breakpoints/
@chaance
chaance / localwp
Created February 25, 2018 18:11 — forked from anonymous/localwp
Quickly CD into working WP theme directory
## Add to your bash or zsh profile
## Modify path to match where you keep your local WP installs
## Your install and theme names should match!
function localwp() {
cd ~/Desktop/local/"$@"/app/public/wp-content/themes/"$@"
}
## To use, type `localwp themename` (replace themename obvi)
## Now you’re in your theme directory! Yay!
@chaance
chaance / wp-team-post-save-link-user.php
Last active June 12, 2018 15:01
Function to dynamically sync CPT team posts with WP users. The post type requires custom meta fields for linked_author (user ID) and email.
<?php
/**
* Helper funnction to remove name suffixes.
*
* @param string $name Name.
* @return array Suffix-free name parts.
*/
function xx_get_suffix_free_name_parts( $name ) {
// Format first and last names.
$parts = explode( ' ', (string) $name );