WordPress Codesnippets

Programmatically install plugins


This code adds a function called ‘install_plugins’ to the ‘admin_init’ action hook. This function then requires the ‘plugin-install’ file from the WordPress admin directory, and creates an array of plugins. The code then loops through the array, using the plugins_api function to retrieve information about each plugin. If an error is returned, the script will die. The code then creates a WP_Ajax_Upgrader_Skin and a Plugin_Upgrader, and uses the Plugin_Upgrader to install the plugin using the download_link retrieved from the plugins_api call. The goal of this code is to automate the installation of one or more plugins.

Was this code snippet helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »