Skip to content

Instantly share code, notes, and snippets.

View brandonbarringer's full-sized avatar

Brandon Barringer brandonbarringer

View GitHub Profile
@brandonbarringer
brandonbarringer / GlobalAlert.js
Last active October 19, 2022 19:07
Dismissable Alert Custom Web Component
/**
* Attributes:
* close-icon: String
*
* Example:
* <global-alert>
* <h2>This is a title</h2>
* <p>This is a paragraph</p>
* </global-alert>
*/
@brandonbarringer
brandonbarringer / relatedPages.php
Last active October 18, 2022 16:25
Get Related Pages Based on Menu Hierarchy in WordPress
<?php
function getRelatedPages($pageID, $limit = 10) {
// if this page has a parent, query for sybling pages
// else if this page is a parent, query for child pages
// else query for other top level pages
$parentID = wp_get_post_parent_id(get_the_ID());
$pages = [];
if ($parentID) {
$pages = Helpers::getPagesHierarchy([
'sort_column' => 'menu_order',
@brandonbarringer
brandonbarringer / elementor.json.code-snippets
Last active October 12, 2022 12:19
Elementor Snippets for VScode
{
"PHP Elementor": {
"scope": "php,html",
"prefix": "elementor",
"body": [
"<?php",
"namespace Theme\\Elementor;",
"",
"use Elementor\\Controls_Manager;",
"use Elementor\\Controls_Stack;",
@brandonbarringer
brandonbarringer / diffTime.js
Last active June 16, 2022 13:30
Gets the difference between two times and returns an object with days, hours, minutes
export const diffTIme = (time1, time2) => {
const date1 = new Date(time1);
const date2 = new Date(time2);
const diff = date2.getTime() - date1.getTime();
let minutes = Math.floor(diff / (1000 * 60)) % 60;
let hours = 0;
let days = 0;
if (minutes > 59) {
hours = Math.floor(minutes / 60);
minutes %= 60;
const objectDiff = (obj1, obj2) => {
// Make sure an object to compare is provided
if (!obj2 || Object.prototype.toString.call(obj2) !== '[object Object]') {
return obj1;
}
let diffs = {};
let key;
@brandonbarringer
brandonbarringer / getMenu.php
Last active January 19, 2021 17:12
Sane Custom WP Menu
<?php
public function get_menu($menu_name) {
$locations = get_nav_menu_locations();
$menu_object = wp_get_nav_menu_object( $locations[ $menu_name ] );
$array_menu = wp_get_nav_menu_items($menu_object->term_id);
$menu = array();
foreach ($array_menu as $m) {
if (empty($m->menu_item_parent)) {
$menu[$m->ID] = array();
@mixin color-modifiers($attribute: 'color', $selector: '.') {
@each $name, $color in $colors {
&#{$selector}#{$name} {
@each $tone, $hex in $color {
& #{$selector}#{$tone} {
#{$attribute}: $hex;
}
}
}
}
@brandonbarringer
brandonbarringer / deck.js
Last active August 6, 2019 19:44
Nitish's deck problem
var Deck = (function() {
var cards = [];
var settings = {
deckSize: 52,
cardSets: 4,
uniqueSets: function() { return this.deckSize / this.cardSets }
};
@brandonbarringer
brandonbarringer / industries.txt
Created December 30, 2016 20:31
List of Industries
Accounting
Airlines/Aviation
Alternative Dispute Resolution
Alternative Medicine
Animation
Apparel & Fashion
Architecture & Planning
Arts & Crafts
Automotive
Aviation & Aerospace
@brandonbarringer
brandonbarringer / page-import.php
Last active August 6, 2019 19:45
Recategorizes Posts from data in CSV
<?php
// @Description
// Creates and assigns categories to a list of post URLs via a CSV file
// If we have a file to parse
if ( ($handle = fopen( get_stylesheet_directory() . "/categories.csv", "r" ) ) !== FALSE ) {
// While we are parsing the CSV
// Every iteration is 1 row
// @example fgetcsv($handle, $max_length, $delimiter)