Code Snippets can be used to customize the functionality of your WordPress site without having to modify the core files of the platform. This is important because modifying core files can be risky and lead to compatibility issues with plugins and themes.
Code Snippet for Deleting Transients
Transients are a type of caching mechanism in WordPress that allows temporary data to be stored in the database with an expiration time. Transients are often used for expensive or time-consuming operations, such as database queries or API requests, that must be performed frequently.
Depending on the number of plugins running on the site and how often expired transients are deleted, transients can quickly end up bloating up the site’s options database table.
The cron event in WordPress core is set to delete expired transients every 24 hours. In this code snippet, we modify the cron event in the WordPress core
delete_expired_transients so that it will run every 6 hours.
Bulk Deleting WordPress Plugins
If you are dealing with a client’s new or existing site with the Hello Dolly and Akismet plugins installed, you can utilize a code snippet to disable and remove both plugins. These plugins come as default in a fresh WordPress installation.
Usually, those plugins are not present if you use WP Toolkit by cPanel since you can select which plugins should be installed by default when creating a new WordPress installation.
To execute any action required on WordPress plugins from the MainWP Dashboard, you can utilize this code snippet and modify it accordingly for bulk plugin deletion or any other necessary task.
The Code Snippets is a powerful Extension for MainWP as it allows you to create, edit, delete, and execute custom code snippets on your Child Sites without directly modifying the theme or plugin files, saving you time and effort.
You can also organize your snippets into categories and search through them to quickly find what you need.
This makes it easier to maintain your sites and ensures that your customizations are not lost during updates.
Overall, the Code Snippets Extension is a powerful tool for developers and site owners who want to customize their Child Sites and streamline their workflow.