Skip to content

Instantly share code, notes, and snippets.

@brandonjp
brandonjp / AddPostAttachmentsMetaBox.php
Created June 16, 2023 21:23
For WordPress, Add a Metabox to List Attachments in the editor. Works on posts, pages & custom post types. - https://snipsnip.pro/s/724
// Add a Metabox to List Attachments in the editor - https://snipsnip.pro/s/724
if (!class_exists('AddPostAttachmentsMetaBox')) {
class AddPostAttachmentsMetaBox {
public function __construct() {
add_action('add_meta_boxes', array($this, 'add_metabox_of_post_attachments'));
}
public function add_metabox_of_post_attachments() {
$post_types = get_post_types(array('public' => true), 'names');
foreach ($post_types as $post_type) {
@brandonjp
brandonjp / SimplePostDuplicator.php
Created June 16, 2023 18:44
For Wordpress, add a Duplicate option to Posts & Pages without using a plugin.
// SimplePostDuplicator - Adds a Duplicate option to Posts & Pages without using a plugin! https://snipsnip.pro/s/701
if (!class_exists('SimplePostDuplicator')) {
class SimplePostDuplicator {
public function __construct() {
add_action('admin_action_simple_post_duplicator_duplicate_post_as_draft', array($this, 'duplicatePostAsDraft'));
add_filter('post_row_actions', array($this, 'addDuplicatePostLink'), 10, 2);
add_filter('page_row_actions', array($this, 'addDuplicatePostLink'), 10, 2);
}
@brandonjp
brandonjp / site-add-env-notice-to-admin-screens.code-snippets.php
Created January 21, 2023 22:13
SITE: Add Env Notice to Admin Screens - WP / Code Snippets Pro
<? // <- remove this line if you copy/paste into Code Snippets Pro
/**
* SITE: Add Env Notice to Admin Screens
*
* For admins only, display an admin notice with the current domain environment, such as: [STAGING] or [LOCAL] or [PRODUCTION]
* /* Requires Env555 */
*/
/* Requires Env555 */
@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(