Skip to content

Instantly share code, notes, and snippets.

View adamdehaven's full-sized avatar

Adam DeHaven adamdehaven

View GitHub Profile
@adamdehaven
adamdehaven / launch.json
Created September 11, 2018 20:19
VS Code Xdebug configuration for Homestead project
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
@adamdehaven
adamdehaven / class.WP_Breadcrumbs.php
Last active July 6, 2018 14:51
Custom WordPress Breadcrumbs
<?php
class PW_Breadcrumbs {
// Declare variables
private $home_link;
private $home_text;
private $link_before;
private $link_after;
private $link_attr;
@adamdehaven
adamdehaven / phone-regex.md
Last active June 7, 2018 13:23
Phone number RegEx

^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$

@adamdehaven
adamdehaven / wp-category-and-children-count.php
Last active February 8, 2018 14:37
Function to get the post count from a given category or taxonomy term or terms, including their children in WordPress.
<?php
/*
* Function to get the post count from a given category or taxonomy
* term or terms, including their children.
*
* @param (int|array|string) $term Single integer value, or array of integers or "all"
* @param (string) $taxonomy
* @param (array) $args Array of arguments to pass to WP_Query
* @return $q->found_posts
*
@adamdehaven
adamdehaven / tinypng.sh
Created January 26, 2018 14:09
TinyPNG API Bash Script
#!/bin/bash
TINYAPIKEY="YOUR_API_KEY"
# Make sure source dir is supplied
if [ -z "$1" ]
then
echo "Missing argument. Supply the source directory containing the images to be optimized. Usage: ./tiny.sh <source_dir>"
exit 1
fi
@adamdehaven
adamdehaven / isonscreen.js
Created September 25, 2017 17:57
jQuery function to detect if element is within viewport
// If element is in viewport
// EXAMPLE: $('.element').isOnScreen();
$.fn.isOnScreen = function(){
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
@adamdehaven
adamdehaven / custom_gulp_commands.py
Created September 21, 2017 15:22
Adds a "Kill and Delete Cache" command to the sublime-gulp package for Sublime Text 3
import sublime
import sublime_plugin
class GulpDeleteCacheOnKill(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("gulp_kill")
self.window.run_command("gulp_delete_cache")
@adamdehaven
adamdehaven / wp-schedule.md
Last active November 1, 2018 04:13
Schedule events in WordPress

You probably already know that WordPress can schedule events. For example, it can publish posts at preset dates and times. Using hooks and wp-cron, we can easily schedule our own events. In this example, we will get our WordPress blog to send us an email once hourly.

The solution

Paste the following code block in the functions.php file of your theme.

if (!wp_next_scheduled('my_task_hook')) {
  wp_schedule_event( time(), 'hourly', 'my_task_hook' );
}
@adamdehaven
adamdehaven / element-in-viewport.js
Created April 3, 2017 15:02
jQuery: Check if element is in designated area of viewport (horizontal)
function toggleDecadeVisibility() {
var windowWidth = $(window).width();
$('.element').each(function() {
var elementLeft = $(this).offset().left,
visibleOffset = (windowWidth / 2) - ($(this).width() / 2),
hideOffset = visibleOffset - $(this).width();
// If element is in center of viewport, make visible
if (elementLeft <= visibleOffset && elementLeft >= hideOffset) {
<svg class="logo" viewBox="0 0 196 50" width="196px" height="100%" preserveAspectRatio="xMinYMin meet">
<title>Image Title</title>
<switch>
<use xlink:href="#khat-logo"></use>
<foreignObject>
<img class="logo" alt="KHAT logo" src="~/Content/images/logo.png" />
</foreignObject>
</switch>
</svg>