Skip to content

Instantly share code, notes, and snippets.

@brandonjp
brandonjp / code-snippets-pro-add-filetype-to-export-buttons.code-snippets.php
Last active January 22, 2023 20:52
Code Snippets Pro: Add Filetype to Export Buttons - WP
<? // <- remove this line if you copy/paste into Code Snippets Pro
/**
* Code Snippets Pro: Add Filetype to Export Buttons
*
* In the Code Snippets Pro interface, I always forget which button Downloads the PHP snippet and which Exports the JSON, so this snippet simply appends the filetype onto the button text.
*/
namespace bhT0Vm4;
@brandonjp
brandonjp / auto_set_featured.php
Last active January 18, 2023 22:25
Posts: Auto Set First Image as Featured - WP / Code Snippets Pro
@brandonjp
brandonjp / add_metabox_of_post_attachments.php
Last active January 18, 2023 20:29
WP Post Edit: Add Metabox to List Attachments - WP / Code Snippets Pro
<? // <- remove this line if you copy/paste into Code Snippets Pro
namespace cpZgLjBJ;
function add_metabox_of_post_attachments()
{
add_meta_box('att_thumb_display', 'Attachments', '\cpZgLjBJ\generate_list_of_post_attachments', 'post'); // Change your post type here
}
function generate_list_of_post_attachments($post)
{
@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