Skip to content

Instantly share code, notes, and snippets.

View brettkelly's full-sized avatar

Brett Kelly brettkelly

View GitHub Profile
@brettkelly
brettkelly / functions.php
Created February 15, 2023 19:44
Hide an HTML element by class based on WP user role
<?php
// Hide the Inventory nav item for everybody except admins and buyers
function rw_hide_inventory_link_for_role() {
$allowed_roles = ['administrator', 'rw-buyer']; // these user roles can see the item
$hide = true; // default to hiding it
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = (array)$user->roles;
foreach($roles as $role) {
@brettkelly
brettkelly / functions.php
Created January 5, 2023 04:27
An example of a WordPress shortcode that takes parameters
<?php
/*
Collect and display a sorted, unordered list element containing all children of the current post
Supported attributes:
`remove` = this string will be removed in the resulting links
`exclude` = posts whose title contains one of these comma-separated strings will be omitted
TODO: fix both params to be pipe-delimited because flexibility
*/
@brettkelly
brettkelly / us_state_abbreviations.py
Last active July 13, 2022 21:58 — forked from JeffPaine/us_state_abbreviations.py
A python list of all US state abbreviations.
states = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
'AZ': 'Arizona',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DC': 'District of Columbia',
'DE': 'Delaware',
elements = [".some-class", "#some-id"]; // selectors for each element to suppress events
events = ["mouseover", "click"]; // events to suppress
document.addEventListener("fullscreenchange", (event) => {
// fullscreen event fired
elements.forEach((element) => {
events.forEach((event) => {
if (document.fullscreenElement) {
// some element has fullscreen now
document.querySelectorAll(element).forEach((el) => {
el.addEventListener(event, (e) => {
import React, {useState, useEffect} from "react"
import {useRouter} from 'next/router'
const Event = ({embed}) => {
const router = useRouter()
const [embedSRC, setEmbedSRC] = useState(embed);
// useEffect(() => {
// const handleRouteChange = () => {
// setEmbedSRC(embed)
// }
@brettkelly
brettkelly / epro-cpt-archive-override.php
Created January 28, 2022 21:11
Override the archive title for a CPT in Elementor Pro
<?php
// ganked this from a FB group thread that linked to a dead E doc page.
// Storing here for reference/posterity.
function archive_callback( $title ) {
// make this a switch if you want to handle a bunch of different CPTs in one go
if ( is_post_type_archive('my_cpt_slug') ) {
return 'My custom archive title, baybay';
}
@brettkelly
brettkelly / embed.html
Created October 28, 2021 15:50
AC Page Embed
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body,
html {
@brettkelly
brettkelly / vimeoPlayback.js
Last active August 26, 2021 18:13
Ad-hoc store/load playback position for embedded Vimeo players
/*
To Do:
1. Deal with multiple iframes. Don't just match the element type and assume it's a player.
2. Deal with multiple embedded players?
3. Handle a page close/reload event during playback
*/
var iframe = document.querySelector("iframe");
if (!iframe) {
console.log("No Vimeo player found");
} else {
@brettkelly
brettkelly / testimonial.css
Created June 4, 2021 14:24
Add quotation mark image to testimonial
selector::before {
content:"";
background-image:url('foo.svg');
position:absolute;
top:0;
left:2;
opacity:0.3;
}
selector::after {

Using Git to Manage a Live Web Site

Overview

As a freelancer, I build a lot of web sites. That's a lot of code changes to track. Thankfully, a Git-enabled workflow with proper branching makes short work of project tracking. I can easily see development features in branches as well as a snapshot of the sites' production code. A nice addition to that workflow is that ability to use Git to push updates to any of the various sites I work on while committing changes.

Contents