Skip to content

Instantly share code, notes, and snippets.

@brandonjp
brandonjp / wp-settings-set-all-themes-plugins-to-auto-update.code-snippets.php
Created January 18, 2023 23:23
WP Settings: Set All Themes & Plugins to Auto-Update - Code Snippets Pro
<? // <- remove this line if you copy/paste into Code Snippets Pro
/**
* WP Settings: Set All Themes & Plugins to Auto-Update
*
* Set all themes and plug-ins to auto update.
* * Run only as needed
*/
namespace tOrGBs5p;
@brandonjp
brandonjp / post-title-remove-html-tags-from-post-title-on-save_post.code-snippets.php
Last active January 18, 2023 21:54
Post Title: Remove HTML Tags from Post Title on save_post - WP / Code Snippets Pro
<? // <- remove this line if you copy/paste into Code Snippets Pro
/**
* Post Title: Remove HTML Tags from Post Title on save_post
*
* On post save, if the title contains any html tags, they will be stripped out and replaced with a space. This also resets the slug.
*/
namespace WK0aky0;
function custom_strip_all_tags_replace_with_space( $string ) {
@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