• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP Bitz

A curated collection of code snippets for WordPress

  • Home
  • About
  • Blog
  • Code Snippets
You are here: Home / Archives for Code Snippets

Delete directory using rmdir() in PHP even if the directory is not empty

December 20, 2025

function delete_directory( $dir ) { // Check if $dir is a directory. if ( ! is_dir( $dir ) ) { return false; // No need to continue …

Continue Reading

Delete orphaned user meta

November 28, 2025

DELETE um FROM wp_usermeta um LEFT JOIN wp_posts u ON wp.ID = um.user_id WHERE u.ID IS NULL …

Continue Reading

Get a list of orphaned user meta

November 28, 2025

SELECT * FROM rg_usermeta um LEFT JOIN rg_users u ON u.ID = um.user_id WHERE u.ID IS NULL …

Continue Reading

Get word count of a post

March 6, 2023

add_filter( 'the_content', function( $content ) { $words = explode( ' ', $content ); $word_count = count( $words ); …

Continue Reading

Restore Bitnami WordPress Filesystem Permissions

December 15, 2022

sudo chown -R bitnami:daemon TARGET sudo find TARGET -type d -exec chmod 775 {} \; sudo find TARGET -type f -exec chmod 664 {} \; sudo …

Continue Reading

Batch file to remove WordPress site in XAMPP

November 8, 2022

:: PHP, WP-CLI, and MYSQL all need to be path environment variables. :: If you get errors that indicate something is not recognized as an …

Continue Reading

Batch file to create WP site in XAMPP

November 8, 2022

:: This is for spinning up installs for dev work, so don't consider this for :: production applications. It creates everything off a …

Continue Reading

Add the Customizer to the Toolbar

October 28, 2022

add_action( 'admin_bar_menu', function( $wp_adminbar ) { global $wp; $current_url = home_url( add_query_arg( array(), $wp->request ) …

Continue Reading

Validate user registration email with Proofy.io API

October 24, 2022

/** * Validates email in native WP registration using Proofy.io API. * * @param array $errors A WP_Error object …

Continue Reading

  • Page 1
  • Page 2
  • Page 3
  • Interim pages omitted …
  • Page 7
  • Go to Next Page »

Primary Sidebar

Join for free!

Get free code snippets, WordPress best practices, and practical Content Marketing advice from seasoned WordPress expert Chad Butler (butlerblog):

Recent Posts

  • Check and delete orphaned user meta in WordPress
  • Add a Database Connection to use WPDB
  • Notice: Function WP_Block_Patterns_Registry::register was called incorrectly
  • Use WP-CLI to back up your site
  • Bitnami WordPress Autoptimize cannot write to the cache directory

Copyright © 2026 · Maker Pro on Genesis Framework · WordPress · Log in