/custom-post-type-cleanup

A WordPress plugin to detect and delete posts from custom post types that are no longer in use

Primary LanguagePHPGNU General Public License v2.0GPL-2.0

Custom Post Type Cleanup Tests

Version: 1.3.2
Requires at least: 5.9
Tested up to: 6.5

This is the development repository for the WordPress plugin Custom Post Type Cleanup


Custom post type posts are left in the database if a post type is no longer registered (in use).

Plugins and themes can (without you knowing) use custom post types as a way to store data. These posts stay in the database forever if they're not cleaned up by the plugin/theme itself upon deletion.

There are a lot of plugins that clean your database (by removing revisions, drafts etc.), but I haven't found one that does a cleanup of unused post type posts.

This plugin provides an easy way to detect and remove posts from post types that are no longer in use. The settings page for this plugin is at wp-admin > Tools > Custom Post Type Cleanup.

Note: The proper WordPress delete function wp_delete_post() is used instead of running a direct MySQL query to delete the posts. This way all associated post data (comments, post meta etc.) are also deleted from the database. The only exception being term relationships from taxonomies that are also not in use anymore. Delete the terms from those taxonomies as well with this sister plugin

Since version 1.2.0 you can re-register unused custom post types for a limited period of time. This allows you to inspect and delete the posts like you would normally (in the wp-admin).

It's recommended you make a database backup before deleting posts.

Screenshots

No posts found

The settings page if there are no posts from unused post types in the database. De-activate or delete the plugin and use it again later.

screenshot-4

Settings Page

The settings page if posts where found (after deleting a batch of 100 posts). screenshot-1

Re-registering unused custom post types

The settings page when unused custom post types are re-registered. screenshot-2

Done

The settings page if all posts were deleted. De-activate or delete the plugin and use it again later. screenshot-3

Contributing

Anyone is welcome to contribute to the Custom Post Type Cleanup plugin. If you find an issue, let us know here or open up a forum topic in the WordPress forums

Help Tranlate this plugin

If you want to contribute translations so other people can use them as well, you can do so by visiting the translate.wordpress.org page for this plugin. You can read about how translating works in the WordPress Translator's Handbook.

Let me know in the WordPress forums if you want to become a Translation Editor for this plugin.

Development

The master branch is where you'll find the most recent, stable release. The develop branch is the current working branch for development. Both branches are required to pass all unit tests. Any pull requests are first merged with the develop branch before being merged into the master branch. See Pull Requests

Pull Requests

When starting work on a new feature, branch off from the develop branch.

# clone the repository
git clone https://github.com/keesiemeijer/custom-post-type-cleanup.git

# cd into the custom-post-type-cleanup directory
cd custom-post-type-cleanup

# switch to the develop branch
git checkout develop

# create new branch newfeature and switch to it
git checkout -b newfeature develop

Creating a new build

To compile the plugin without all the development files use the following commands:

# Go to the master branch
git checkout master

# Install Grunt tasks
npm install

# Build the production plugin
grunt build

The plugin will be compiled in the build directory.