Sunday, August 19, 2018
Plugins

Cleaning the scrap codes of uninstalled plugins

Uninstalling a plugin is easy. ¿But how do you know if plugin is completely uninstalled and it doesn't leave any trace?

Cleaning the scrap codes of uninstalled plugins

Installing a plugin is easy. But sometimes they resist to being completely uninstalled without leaving some scrap codes in your WordPress website.

This is not a big problem unless you install and uninstall lots of plugins. If so you may have tons of scrap codes that may harm your WordPress speed or even worst, it could trigger an error.

Uninstalling a plugin is easy, you just click on “delete” button in your plugins dashboard page and that’s it.

But. ¿How do you know if plugin is completely uninstalled and it doesn’t leave any trace?

Here you will learn how to discover that, and how clean up any junk code left in your WordPress installation.

Were the plugins can leave traces

A plugin can write code in any file of WordPress, and not always they are deleted after uninstall.

They can leave some trash codes in:

  • Wp-config.php file
  • .htaccess file
  • Database created tables
  • Additional folders or files in root, wp-content, uploads or plugins folder

First step to identify junk code that plugins may left, is knowing which files and directories comes with a standard wordpress installation.

¿What’s in a standard WordPress installation?

Database tables

Tables in database in a fresh WordPress installation are these:

  • wp_commentmeta
  • wp_comments
  • wp_links
  • wp_options
  • wp_postmeta
  • wp_posts
  • wp_termmeta
  • wp_terms
  • wp_term_relationships
  • wp_term_taxonomy
  • wp_usermeta
  • wp_users

And in multisites there are six more additional tables:

  • wp_blogs
  • wp_blog_versions
  • wp_registration_log
  • wp_signups
  • wp_site
  • wp_sitemeta

Known this, you can be sure that if there are any other table in database it’s there because some plugin or theme has created it.

WordPress files and directories in a fresh installation are:

  • wp-admin
  • wp-includes
  • wp-content
  • plugins
  • themes

But WordPress will add some files when your website grows:

  • wp-admin
  • wp-includes
  • wp-content
  • languages
  • mu-plugins
  • plugins
  • themes
  • upgrade
  • uploads

All these folders have some sub folders in it, except uploads.

As you can see, if any plugin saves a file or folder in any subdirectories, things can get really complicated.

Fortunately, most of plugins that do this add their files only in wp-content and/or in uploads.

¿Where can you find the junk code leaved by an uninstalled plugin?

Having in mind what we’ve just said, suspicious places were you can find scrap code will be the following:

  • Folders and files in wp-content and uploads
  • Additional tables in the database
  • Additional lines in the wp-options table of WordPress (almost all plugins do this)

¿How to completely uninstall a plugin?

There are many things to check, and if we think that each developer and plugin is completely different from each other, and that there is no standard specification or requirement of how a plugin must be uninstalled; we have no other option that check manually every time we uninstall a plugin.

Let’s see some examples of what happens when you uninstall some of the most popular plugins.

WooCommerce:

If you ever wanted to test WooCommerce just to know what it’s about, and then you uninstalled it, you must know that it leaves a lot of trash after uninstall.

In fact, in WC official webpage they warn about this and recommend to add a line of code to wp-config.php file to prevent it.

This way, when you uninstall it, WC will delete these 16 additional tables in database:

  • wp_wc_download_log
  • wp_wc_webhooks
  • wp_woocommerce_api_keys
  • wp_woocommerce_attribute_taxonomies
  • wp_woocommerce_downloadable_product_permissions
  • wp_woocommerce_log
  • wp_woocommerce_order_itemmeta
  • wp_woocommerce_order_items
  • wp_woocommerce_payment_tokenmeta
  • wp_woocommerce_payment_tokens
  • wp_woocommerce_sessions
  • wp_woocommerce_shipping_zones
  • wp_woocommerce_shipping_zone_locations
  • wp_woocommerce_shipping_zone_methods
  • wp_woocommerce_tax_rates
  • wp_woocommerce_tax_rate_locations

After uninstalling it, you have to remove the code you added before.

If you didn’t know this and already have uninstalled WC, you will have to delete all the tables in DB manually using PHPMyAdmin.

This procedure is similar when you want to eliminate any trace that a plugin leaves in there.

Important: Before you delete any table, be sure to grab a backup, just in case…

Yoast SEO

Another popular plugin that leaves considerable amount of scrap after uninstalling it.

When installing Yoast SEO, it will create two additional tables in DB:

  • wp_yoast_seo_links
  • wp_yoast_seo_meta

But it also stores data in:

  • wp_usermeta – meta_key values like wpseo_title.
  • wp_postmeta – meta_key values for several ID’s such as:
    • yoast_wpseo_linkdex
    • _yoast_wpseo_title
    • _yoast_wpseo_metadesc
    • _yoast_wpseo_focuskw
    • _yoast_wpseo_focuskw_text_input
    • _yoast_wpseo_primary_category
    • _yoast_wpseo_content_score

Askimet

This plugin saves tons of data in wp_commentmeta table, that will remain there after uninstalling it.

And we are talking about thousands of lines.

Cache plugins:

Cache plugins uninstall deserves a full post. Absolutely all of them leaves some trash somewhere. And we are talking of lots of scrap in some of them.

Now that you know it, I’m sure you are going to think it twice before change your cache plugin.

And don’t forget shortcodes

Many plugins uses shortcodes that can be inserted into posts, widgets or pages. After uninstalling the plugin, shortcodes will remain there.

You will have to edit all of the posts or anywhere they are placed.

It can be a hazardous work to do if you have lots of posts. Fortunately, you can use search in posts page to find them. Just write the shortcode in search box and all posts containing the shortcode will be shown.

Conclusion

So, ¿what shall you do to clean up your website of scrap code?
First of all, think wisely if you really need that plugin you are about to install. Don’t install them just for seeing how it works.

If you don’t remember how many plugins you’ve uninstalled, it’s sure that your WP installation is full of scrappy code.

This is what you have to do in order to make a clean-up.
  1. Make backup of database, WP files and directories.
  2. After uninstalling a plugin, delete any additional folder and/or file created by plugin
  3. Delete any database table created by plugin through PHPMyAdmin
  4. If the plugin was using shortcodes, search for them and edit content
  5. Check the wp-options table and clean it if you find something

It’s not easy work to do, but it’s important to maintain your WP clean and healthy.
And cleaning all this garbage is one thing you can do for that.

¿Did you find many junk left by plugins? Please tell us your experience leaving a comment
.

Seba Rossi
the authorSeba Rossi
Experienced Web Editor with more than 1500 published articles. Passionate about Web development and with advanced knowledge of SEO, amateur guitarist and lover of tasty beer with the company of good and old friends.

Leave a Reply