Skip to content

Instantly share code, notes, and snippets.

@brandonjp
brandonjp / wp_add_custom_taxonomy_to_permalink_structure.php
Created January 3, 2023 06:08
Wordpress URLs: Add custom taxonomy to permalink structure - Allows you to use the /%name%/ of a custom taxonomy in permalink structures. Be sure to set $taxName and $default variables. Adapted from: https://www.shibashake.com/wp/add-custom-taxonomy-tags-to-your-wordpress-permalinks - Code Snippets Pro
@brandonjp
brandonjp / users-create-&-delete-n-new-users.php
Last active January 3, 2023 02:21
Wordpress Users: Create & Delete n New Users - Code Snippets Pro
<?php
namespace FyjaHmx9;
require_once(ABSPATH.'wp-admin/includes/user.php' );
\FyjaHmx9\create_and_delete_n_new_users();
function create_new_user() {
$username = \uniqid();
$userdata = array(
@brandonjp
brandonjp / wp-edit_published_posts-fix.php
Last active May 1, 2023 22:37
Allow non-Author to edit & save a published wordpress post. This works around issues with `_wp_translate_postdata` & `user_has_cap` - Fixes "Sorry, you are not allowed to edit posts as this user."
<?php
/*
*
* ALLOW USER TO EDIT POST IF THEY ARE SELECTED AS THE PM
* Preferred way would be to use `user_has_cap` - see:
* - https://wordpress.stackexchange.com/a/360990/5380
* - https://developer.wordpress.org/reference/hooks/user_has_cap/
* However, WordPress has a nasty long standing issue with this line:
* - https://bit.ly/3I72jOn
* Where it forces a check to make sure the author is current user, which prevents any efforts to customize capabilities by using a `user_has_cap` filter. The bug is documented here:
@brandonjp
brandonjp / block-editor-open-advanced-on-mouseenter-code-snippets.json
Last active August 8, 2023 16:29
Wordpress Gutenberg Block Editor: Keep Advanced Section Always Open
{
"generator":"Code Snippets v3.3.0",
"date_created":"2023-04-08 21:52",
"snippets":[
{
"name":"Block Editor: Open Advanced Panel on Hover [SnipSnip.pro]",
"desc":"When using Gutenberg Block Editor, anytime your mouse enters the sidebar panel, if the \u201cAdvanced\u201d section is not open, then expand it. (Causes a minor annoyance where it scrolls to Advanced after expanding it.) (Includes a delay to ensure the sidebar is rendered... you might need to adjust the setTimeout delay if your site\/browser is slow to load the Block Editor.)\n\nCode revisions at: <a href=\"https:\/\/gist.github.com\/brandonjp\/bcfd56838359f12ef5c3ed2ecb6132dc\">https:\/\/gist.github.com\/brandonjp\/bcfd56838359f12ef5c3ed2ecb6132dc<\/a>\n\n<a href=\"https:\/\/snipsnip.pro\/s\/177\">https:\/\/snipsnip.pro\/s\/177<\/a>",
"tags":[
"admin",
"gutenberg",
@brandonjp
brandonjp / moment-formats.md
Last active May 1, 2025 13:23
List of common date time formats for Moment.js

Big List of Common Moment.JS Date and Time Formats for Easy Copying

Example Format
2021 YYYY
🦏 🦏
202108 YYYYMM
2021-08 YYYY-MM
🦏 🦏
8/5 M/D
08/05 MM/DD
@brandonjp
brandonjp / dMCFileNameChrReplace.md
Last active February 15, 2023 12:53
dBpoweramp Music Converter - XRegistry for Restricted Filename Character Replacements on macOS

Accent Marks in dBpoweramp Music Converter

I've had a huge problem with a variety of diacritics / accent marks in filenames. I lost a few files because I didn't notice that Dropbox had failed to sync umlauts and a few more rare characters between operating systems. So pulling from this list: http://pinyin.info/unicode/diacritics.html - I created a set of filename character replacements for dMC settings. This will replace any diacriticals with the closest unaccented latin character. It's been a game changer for me, posting it here in case it helps anyone else (and probably so I can find it again in a couple years). This is how I've changed it on macOS, I'm not sure about Windows.

Replacement Settings for MacOS

  • First, completely quit any dBpoweramp programs that are running.
  • Then find the registry file at: ~/Library/dBpoweramp/XRegistry and open it in a text editor.
  • Look for the key "dMCFileNameChrReplace" (If you have current replacements set, you might want to copy them to a blank text
@brandonjp
brandonjp / wp-mb-tax-admin.php
Last active July 18, 2022 19:49
PHP - Wordpress Metabox.io ajax fetch custom taxonomy metadata
/**
// -------------------------
// Fetch Taxonomy Term & Meta
// -------------------------
// GOAL: When a user selects a taxonomy term (from a MetaBox.io field) this helps fetch
// the term & it's metadata and returns JSON so the JS can load it into a Custom HTML block
// -------------------------
// FORUM - https://metabox.io/support/topic/show-data-from-related-post-term-after-selection/
// PHP - https://gist.github.com/21fed6266453de7ba76b3d2bc0e5a06f
// JS - https://gist.github.com/3b636d0c7e55ce6dc58ceba3de9a974e
@brandonjp
brandonjp / wp-mb-tax-admin.js
Last active October 14, 2019 20:05
JS - Wordpress Metabox.io ajax fetch custom taxonomy metadata
// -------------------------
// Fetch Taxonomy Term & Meta
// -------------------------
// GOAL: When a user selects a taxonomy term (from a MetaBox.io field) this fetches the
// term & it's metadata and loads it into a Custom HTML block
// -------------------------
// FORUM - https://metabox.io/support/topic/show-data-from-related-post-term-after-selection/
// PHP - https://gist.github.com/21fed6266453de7ba76b3d2bc0e5a06f
// JS - https://gist.github.com/3b636d0c7e55ce6dc58ceba3de9a974e
// -------------------------
@brandonjp
brandonjp / findOverflowParents.js
Last active July 11, 2025 22:29
find overflow:hidden ancestors
// when you're trying to use `position:sticky` on an element
// you'll have trouble if any parent/ancestor element has
// overflow set to anything other than "visible" (such as: auto,hidden,overlay,scroll)
// & turns out if a parent is `display:flex` it might need some love
// (to remedy this you can set the `align-self` of your sticky element)
// see here for how the display & align-self properties affect: http://bit.ly/2ZaRu4o
// so, to find those troublesome parents...
// copy & paste this into Chrome Inspector/Dev Tools console
// (and be sure to change the #stickyElement below, if needed)
@brandonjp
brandonjp / insert_snippet.sh
Last active March 10, 2021 19:00
bash script for Alfred workflow to create a new snippet
#!/bin/bash
# set qry to the query (argument one)
qry="$1"
# fix SNIP_DB location in case it contains tilde (won't expand in quotes)
SNIP_DB=$( echo $SNIP_DB | sed "s:^~:$HOME:" )
# set the internal delimeter (idlm) to some char(s) that will never be used
idlm=''