Skip to content

Instantly share code, notes, and snippets.

View stevenslack's full-sized avatar

Steven Slack stevenslack

View GitHub Profile
@stevenslack
stevenslack / dependency-check.js
Created April 20, 2022 12:07
Check for dependencies concurrently while the page loads.
// Set the window object to be set at a later time then the promise resolve.
setTimeout(() => {
window.DEP = 'I am here!';
}, 31000)
async function dependencyReady() {
// Set a timeout limit of 30 seconds.
const time = Date.now() + 30000;
// Runs an until time is past and window.DEP is ready.
while (!Object.prototype.hasOwnProperty.call(window, 'DEP')) {
@stevenslack
stevenslack / calcAspectRatioHeight.js
Created March 25, 2022 15:26
Calculate the height for a specific width and aspect ratio with JavaScript
/**
* Calculate the height for a specific width and aspect ratio.
*
* @param {Number} width The width used to generate a height for the aspect ratio.
* @param {string} aspectRatio The aspect ratio with the ':' as a delimiter. Example: '16:9'.
* @returns {Number} the height for the aspect ratio.
*/
export default function calcAspectRatioHeight(width = 100, aspectRatio = '16:9') {
let y = String(aspectRatio); // make a copy of the aspect ratio.
@stevenslack
stevenslack / calc_aspect_ratio_height.php
Last active March 25, 2022 15:12
Calculate the height for a specific width and aspect ratio.
<?php
/**
* Calculate the height for a specific width and aspect ratio.
*
* @param int $width The width used to generate a height for the aspect ratio.
* @param string $aspect_ratio The aspect ratio with the ':' as a delimiter. Example: '16:9'.
* @return string The calculated aspect ratio height.
*/
function calc_aspect_ratio_height( int $width = 100, string $aspect_ratio = '16:9' ): string {
// If the aspect ratio is invalid use the default value of 16:9.
@stevenslack
stevenslack / settings.json
Last active December 16, 2021 15:16
Helpful settings for ESLint in VS Code
{
"[javascript]": {
"editor.rulers": [
100
],
},
"[javascriptreact]": {
"editor.rulers": [
100
],
@stevenslack
stevenslack / webpack-update-guide.md
Last active September 30, 2021 14:50
Webpack v4 -> v5 Update Guide

This guide is meant to serve as a reference for updating Webpack to version 5 for projects based off of the WP Starter theme using Webpack version 4. Many of the steps needed to update Webpack are not covered in the Webpack migration guide To v5 from v4 | webpack .

For the majority of the update you can use these two references:

To see what versions you are running and what the latest versions are you can run npm outdated in your terminal to see which packages need to be updated.

The sections below represent the different changes needed across your project:

@stevenslack
stevenslack / get_terms_from_url.php
Created June 20, 2016 19:29
Get terms from a URL
<?php
/**
* Get term object from URL
*
* Assumes the URL structure follows a standard pretty permalink eg: domain/taxonomy/term/
*
* @param string $url The URL to search for a term slug
* @param string $taxonomy_name specify a taxonomy in which the term resides
* @return object The term object
*/
@stevenslack
stevenslack / functions.php
Created April 26, 2016 11:32
If sidebar has a text widget with a particular shortcode
<?php
/**
* Check the sidebar or sidebars for a shortcode
*
* @param mixed array|string|int $index sidebar id, name, or an array of sidebar names
* @param string $shortcode the shortcode to check for
* @return bool true if the sidebar contents contains the shortcode, false otherwise
*/
function if_sidebar_has_shorcode( $index, $shortcode ) {
// get all the sidebars widgets
@stevenslack
stevenslack / wc-membership-object-ids-by-post.php
Last active July 19, 2018 22:10
Get the term IDs associated with the choosen membership levels assigned to a post or page. Only returns taxonomy terms.
<?php
/**
* Get the page/post IDs or taxonomy term IDs for restricted content
* for chosen WooCommerce Memberships levels which have been assigned to a post or page.
*
* @param string $content_type | accepts either 'taxonomy' or 'post_type' object keys
* @param int $post_id The ID of the post or page
* @return array post/pageID's or taxonomy term ID's
*/
function wc_get_membership_term_ids( $content_type, $post_id ) {
@stevenslack
stevenslack / class-drop-walker-nav.php
Last active November 24, 2020 07:53
WordPress Walker Nav extended to add data attributes for Drop support
<?php
/**
* Extends WordPress nav menu by adding data attributes and
* markup for Drop by Chris Ferdinandi
*
* Version 6.1.1
*
* drop source: https://github.com/cferdinandi/drop
*/