4. Cleanup Module in Beyond Multisite

The Cleanup module will help you bulk delete unwanted comments, revisions, sites, leftover database tables, and users without a role from your WordPress multisite network. It creates a network admin page with four forms – one for each type of cleanup. In these forms you can choose the criteria for the cleanup task you want to perform.

Keep in mind, that this module can delete permanently data from your WordPress network. You have to be very careful when choosing the cleanup criteria in the forms before you execute the deletion. Also you have to understand well how the module works and what each form element means.

To avoid unwanted data loss I recommend that you do a backup before you begin and to always use the preview feature before you execute the deletion. We are not responsible for any unwanted data loss, even if it is caused by a bug in the plugin.

Navigating to the Network Cleanup Page

From the Network Admin Screen click on Dashboard and then Network Cleanup.

Delete Comments

How to bulk delete comments?

  1. From the Network Cleanup page, first choose from the options for the Comment status drop-down menu.
    1. Any – Comments with any status will be deleted.
    2. Pending – Only comments pending moderation will be deleted.
    3. Approved – Only approved comments will be deleted.
    4. Spammed – Only spam comments will be deleted.
    5. Trashed – Only comments that are in the trash will be deleted.
    6. Post trashed – Only comments made on trashed posts and pages will be deleted. These comments are not visible in the comments admin page.
  2. In the next drop-down menu choose from the Comment URLs options. This menu can help you find spam comments, since they usually have links in them.
    1. Any – Comments with any amount of URL addresses will be deleted.
    2. Filled URL field – Only comments with something in the URL field will be deleted.
    3. Has a URL in the text – Only comments with at least one URL address in the comment text will be deleted.
    4. Filled URL field or a URL in the text – Only comments with something in the URL field or with at least one URL address in the comment text will be deleted.
    5. Filled URL field and a URL in the text – Only comments with something in the URL field and with at least one URL address in the comment text will be deleted.
  3. In the next drop-down menu choose from the Comment date/time options.
    1. Any – Comments made at any point of time will be deleted.
    2. Older than X days – Only comments made before more than X days will be deleted.
    3. In the last X days – Only comments made in the last X days will be deleted.
  4. The next two drop-down menus for the first Affect sites with group work together to form the selected setting. They allow you to target the deletion only to sites with a certain amount of comments with a selected status.
    1. From the first of them you can select from:
      1. Any amount of – All sites will be affected.
      2. At least X – Only sites with at least X comments of selected status (in the next option) will be affected. This option can help you identify sites with a lot of spam comments.
    2. From the second one you can select from:
      1. Comments in total – Works in combination with the At least X option to count all comments.
      2. Pending comments – Works in combination with the At least X option to count only pending comments.
      3. Approved comments – Works in combination with the At least X option to count only approved comments.
      4. Spammed comments – Works in combination with the At least X option to count only spammed comments.
      5. Trashed comments – Works in combination with the At least X option to count only trashed comments.
  5. Next is the second Affect sites with group.
    1. Any site ID – The comment deletion will affect all sites in the network.
    2. Only these site IDs: – The comment deletion will affect only sites with an ID that is in the comma-separated list provided in the text box to the right of the drop-down menu.
    3. All except these site IDs: – The comment deletion will affect only sites with an ID that is not in the the comma-separated list provided in the text box to the right of the drop-down menu.
  6. If you have selected option 2 or 3 from the previous drop-down menu, you need to enter a comma-separated list of site IDs in the text box.
  7. Now click the Preview Comment Deletion button to see which sites will be affected and how.
  8. If you are sure that these are the deletion criteria you want to use, click Execute Comment Deletion! and then OK to confirm the permanent deletion of comments.
  9. You will see a loading screen and when it is done you will see a table with the results. There you can see how many comments were deleted for each site (nested comments are not counted, read more about that below).

How does the comment deletion work?

  • The comment deletion process will go through all selected sites in the network twice. The first time it will apply the primary comment deletion, which deletes the comments that match the selected criteria. On the second run the secondary comment deletion will be applied, which does the following:
    • deletes all nested comments with parent comments that does not exist (deleted nested comments are not counted in the results of the deletion)
    • deletes all comment meta data for any type of comments that do not exist
    • updates the comment counts for each affected post/page
  • The comments are deleted directly from the database with MySQL queries (not with WordPress functions). This is done for much better speed when deleting large amounts of comments. This means that WordPress hooks related to comment deletion will not run. So if some plugin wants to performs an action after a comment is deleted, this action will not run.
  • Only comments with the type “comment” or an empty type in the database will be deleted (an exception is the comment meta data deletion of non-existent comments, which affects all types). For example pings will not be deleted.

Delete Revisions

Revisions are old versions of posts or pages. They can easily build up to big numbers with time and are rarely used, so this is why we offer the option to delete all or some of them.

How to bulk delete revisions?

  1. From the Network Cleanup page, first choose from the options for the Revision date/time drop-down menu.
    1. Any – All revisions will be deleted.
    2. Older than X day(s) – Only revisions made before more than X day(s) will be deleted.
  2. Then choose from the options of the Exclude from deletion drop-down menu.
    1. None – All revisions will be deleted.
    2. The X most recent for each post – All revisions except for the X most recent for each post and page will be deleted.
  3. Next is the Affect sites with drop-down menu.
    1. Any site ID – The revision deletion will affect all sites in the network.
    2. Only these site IDs: – The revision deletion will affect only sites with an ID that is in the comma-separated list provided in the text box to the right of the drop-down menu.
    3. All except these site IDs: – The revision deletion will affect only sites with an ID that is not in the the comma-separated list provided in the text box to the right of the drop-down menu.
  4. If you have selected option 2 or 3 from the previous drop-down menu, you need to enter a comma-separated list of site IDs in the text box.
  5. Now click the Preview Revision Deletion button to see which sites will be affected and how.
  6. If you are sure that these are the deletion criteria you want to use, click Execute Revision Deletion! and then OK to confirm the permanent deletion of revisions.
  7. You will see a loading screen and when it is done you will see a table with the results. There you can see how many revisions were deleted for each site.

Delete Sites

How to bulk delete sites?

  1. From the Network Cleanup page, first choose from the options for the Attributes drop-down menu.
    1. Any – All sites will be deleted.
    2. Public – Only public sites (that encourage search engines to index them) will be deleted.
    3. Deleted – Only sites marked as deleted will be permanently deleted.
    4. Spam – Only sites marked as spam will be deleted.
    5. Archived – Only sites marked as archived will be deleted.
    6. Mature – Only sites marked as mature will be deleted.
    7. Not public – Only sites that discourage search engines to index them will be deleted.
    8. Not deleted – Only sites that are not marked as deleted will be deleted.
    9. Not spam – Only sites that are not marked as spam will be deleted.
    10. Not archived – Only sites that are not marked as archived will be deleted.
    11. Not mature – Only sites that are not marked as mature will be deleted.
  2. Next is the Registered drop-down menu.
    1. Any – All sites will be deleted.
    2. Older than X days – Only sites registered before more than X days will be deleted.
    3. In the last X days – Only sites registered in the last X days will be deleted.
  3. Next is the Last updated drop-down menu. A site update is publishing or deleting a post/page, or updating a published post/page.
    1. Any – All sites will be deleted.
    2. Less than X min/hours/day(s) after registration – Only sites that have been last updated less than X min/hours/day(s) after they have been registered. The idea here is to catch sites that have been abandoned shortly after creation and therefor most likely are empty and unwanted. To catch such sites this option must be used in combination with the Registered drop-down menu to target only old sites.
      Keep in mind that due to a bug in WordPress, all sites created before WordPress 5.1 and at the same time while the time zone of the main network site was different from UTC, are using different time zones for the registered time and last updated time. This causes incorrect site selection when using the Less than X min/hours/day(s) after registration options.
    3. Older than X days – Only sites that have been last updated before more than X days will be deleted.
    4. In the last X days – Only sites that have been last updated in the last X days will be deleted.
  4. Next is the Published post count drop-down menu. Keep in mind that newly created sites have one published post by default.
    1. Any – All sites will be deleted.
    2. 0 (ignore first post) – Newly created sites have a “Hello world!” post by default. If you choose the option “0 (ignore first post)”, that post will be ignored, and only sites with no other published posts will be affected. But if that post was modified, or deleted and another one added in its place, then it will not be ignored. The first post is detected based on ID and the modification is detected based on time of creation and time of last modification (they need to be the same).
    3. 0 – Only sites with zero published posts will be deleted.
    4. 1 – Only sites with one published post will be deleted.
    5. 0 or 1 – Only sites with either zero or one published posts will be deleted.
    6. Less than X – Only sites with less than X published posts will be deleted.
  5. The next two drop-down menus are Published pages count and Approved comments count, which both have the same options like the previous one. The main idea of these options is to find empty sites. The option “0 (ignore first page)” works the same as “0 (ignore first post)” but for the “Sample Page”. And the option “0 (ignore first comment)” is different in a way, since it does not check for modification, just always ignores the comment with ID 1 (but if deleted and another one added, it will have another ID).
  6. Next is the Affect sites with drop-down menu.
    1. Any site ID – The site deletion will affect all sites in the network.
    2. Only these site IDs: – The site deletion will affect only sites with an ID that is in the comma-separated list provided in the text box to the right of the drop-down menu.
    3. All except these site IDs: – The site deletion will affect only sites with an ID that is not in the the comma-separated list provided in the text box to the right of the drop-down menu.
  7. If you have selected option 2 or 3 from the previous drop-down menu, you need to enter a comma-separated list of site IDs in the text box.
  8. Next is the Skip previously cancelled drop-down menu.
    1. Yes – Excludes from deletion all sites that have been previously individually cancelled (not earlier than version 1.1.0).
    2. No – All sites will be deleted.
  9. Next is the Deletion type drop-down menu.
    1. Permanent deletion – The selected sites will be completely deleted along with their database tables and uploaded media files.
    2. Mark as deleted (change last updated time) – The selected sites will be marked as deleted in their attributes. Also their last updated time will be changed to the current time. This way if you plan to do a permanent deletion in the future, you can use the last updated field to affect sites that were marked as deleted for more than a certain amount of days.
    3. Mark as deleted (keep last updated time) – The selected sites will be marked as deleted in their attributes. Their last updated time will remain the same.
    4. Mark as archived (change last updated time) – The selected sites will be marked as archived in their attributes. Also their last updated time will be changed to the current time. This way if you plan to do a permanent deletion in the future, you can use the last updated field to affect sites that were marked as archived for more than a certain amount of days.
    5. Mark as archived (keep last updated time) – The selected sites will be marked as archived in their attributes. Their last updated time will remain the same.
  10. Next is the Deletion time and cancellation by site admins drop-down menu.
    1. Schedule, notify, and wait X days – Site administrators will be notified via email about the deletion of their site and will be given X days time to cancel it (if they decide they need the site). They will receive instructions on how to cancel the deletion (they need to login to the admin dashboard of the site scheduled for deletion and click a button located in a big red deletion message, that is visible on every admin page). All site deletions that have not been cancelled after the X days have passed will be deleted automatically via the WordPress cron feature. Sites that are marked as archived, spam or deleted will be excluded from scheduled deletions upon task creation. If they were not marked as such when the task was created, but are marked later while the task is running, they will then be deleted, but the administrators will not be notified.
    2. No cancellation. Execute now! – The selected sites will be deleted now and site administrators will not be notified.
  11. If you have chosen to schedule site deletion, remember to first check if you want to change the Cleanup module settings regarding the site deletion email notifications (read more below).
  12. Now click the Preview Site Deletion button to see which sites will be affected.
  13. If you are sure that these are the deletion criteria you want to use, click Execute Site Deletion! and then OK to confirm the action.
  14. You will see a loading screen and when it is done, if you have selected to only mark sites as deleted, you will see a table with the affected sites.
  15. If you have scheduled site deletions, after you close the results box, the page will reload and you will see information about the site deletion task that is running. You will not be able to start new site deletion tasks until this task is removed or cancelled.

Site Deletion Task Statistics

Once a site deletion task is created you will not have access to the site deletion form until you cancel or remove the task. Instead you will see the task statistics. There is also a link that will lead you to a page that reloads every 15 seconds. Since every page load is an opportunity for the cron job to run, this will enforce the maximum email sending speed that you have chosen in the module settings (see below) regardless of the amount of visitors you get on your multisite.

Delete Leftover Database Tables

Some plugins add their own database tables, but do not delete them when you permanently delete the site that used them. WordPress also does not delete these tables, even though they are unusable after the site is gone. With this feature you can find and delete all such tables.

So this will find all tables which name starts with a prefix that belongs to a site that does not exist. For example if the site with ID 3 is permanently deleted (not just marked as deleted), all database tables which name starts with wp_3_ (assuming that wp_ is your main prefix) will be deleted.

How to delete all leftover database tables?

  1. From the Network Cleanup page click Preview Leftover Tables Deletion to see which tables will be affected
  2. If everything looks good, click Execute Leftover Tables Deletion! to delete the tables

Delete Users

Delete Users Without a Role

When a site is permanently deleted, users that only had a role in that site will now have no roles anywhere. These users are still working, people can login, edit their profile, comment on sites (if allowed), and even create sites if this is allowed in your network (if they create a site, they will have a role in it). You could choose to leave them, but if you want with this feature you can delete all users without a role in any site. Super Administrators will not be affected. The deletion is global and permanent. The users will not be notified. If they are the author of any content on any sites, the content will not be deleted and it will not be assigned to another user.

Delete Users by Role

All users that have only the selected role in any site, will be deleted. If they have any other role anywhere, they will be skipped. Super Administrators will not be affected. The deletion is global and permanent. The users will not be notified. If they are the author of any content on any sites, the content will not be deleted and it will not be assigned to another user.

Delete Users by a List of Roles

You enter a comma-separated list of role slugs. Users with at least one of the provided roles (in any site), who also do not have any role that is not in the list in any site, will be deleted. You can include custom roles too. Make sure you are writing the role slugs, not the role names! The role slugs are lower case and have no spaces, but they can also be different from the role name in other ways, so do not assume they are always a lower case version of the name. To see the slug you can go to edit the site that has the role you want and click on the Users tab. We have put a list of the roles with the slugs there. Super Administrators will not be affected. The deletion is global and permanent. The users will not be notified. If they are the author of any content on any sites, the content will not be deleted and it will not be assigned to another user.

Delete Scheduled Actions

Bulk delete piled up actions in the action scheduler plugin, which is used by WooCommerce and other plugins. They can take up a lot of space sometimes. If you have a lot of pending actions, you may have a problem with cron jobs on your site.

The actions are deleted from the wp_actionscheduler_actions database table of each site, and the logs from the wp_actionscheduler_logs database table. The wp_ prefix is different for each site and it includes the site ID, for example wp_2_actionscheduler_actions for site ID 2.

Module Settings

The settings for the Cleanup module affect only the email notification that is sent to site administrators when their site is scheduled for deletion. To see the settings go to the Beyond Multisite page in the Network Admin Screen and click on Show Settings in the Cleanup box.

  • Maximum email sending speed – This is the maximum number of site deletion emails that the plugin will send per hour. They are sent in chunks of up to 15 and in an interval of at least 15 seconds. The minimum speed depends on how often any page from your WordPress network is loaded, since this is how WordPress cron works. So if you have enough page loads in your network and you set this to 240 per hour, the plugin will send 1 email every 15 seconds. If you set it to 1200 per hour, it will send 5 emails every 15 seconds. If you do not have enough page loads, maybe you have 1 page load every 1 minute, and you set it to 240 per hour, it will send 1 email every 1 minute. The maximum setting available is 3600 per hour. Keep in mind that your hosting may be limited to a certain amount of emails per hour. Ask your hosting provider about that.
  • From email – Site administrators will receive the email notification from this email address. This is the sender (you).
  • From name – This is the name of the sender of the email. Your name or your site name.
  • Subject – The subject of the email notification.
  • Message – This is the body of the email. There is a WordPress text editor for this field, so you can easily apply any formatting. This field supports these shortcodes (they will be replaced with a certain value):
    • [user_sites] – A list of URLs of sites that are scheduled for deletion for this user.
    • [deletion_after_days] – The number of days of waiting time before the deletion.
    • [network_site_url] – The URL of the main network site.
  • Send test email to – If you want to test how the email notification will look like in your inbox, enter the email address where you want to receive such a notification and click the Send Test Email button (before that update the settings if you have changed them).
Get Beyond Multisite - Premium WordPress Plugin