Easy WordPress automation


WordPress resolved issues

WordPress resolved issues

WordPress comes with a number of great features that could easily be automated. In the article today we will discuss a WordPress automation and develop a little script that could be set as a cronjob and its task would be to check the plugins and themes for available updates and patch them if necessary. For many WordPress enthusiasts, manual plugins and themes upgrades are irritating and time-consuming tasks so optimizing them is a must.

WordPress automations are not only helpful when dealing with large websites and many extensions, but also small ones.

To ease the things we will use WordPress command-line interface. Our WordPress automation script will process 3 major components separately:

  • We will check the version of our application and upgrade it if its version is outdated
  • During the second stage, we will check and upgrade the plugins
  • Finally, we will check and upgrade the installed themes

Automated WordPress core files checks

WordPress version check could be easily done by typing the following command wp core version. The expected output should be similar to the following one:

# wp core version

4.9.1

The check the newer versions we use wp core check-update. To update the application to the latest available version we use wp core update. Right after its execution, we can again verify the version. In my case the result is:

# wp core version

5.2.2

WordPress plugin updates automation

A list of WordPress plugins could be generated using wp plugin list. From this moment on, we could either execute wp plugin update –all or select only the plugins that have available updates and apply patches only to them. The second option would use less server resources, especially when working with a large number of plugins. To achieve the task we will use for loop which looks like:

for i in $(wp plugin list | grep available | awk '{print $1}'); do wp plugin update $i; done

The above line reads – apply a patch for each plugin that has avialable update

WordPress theme updates automation

Similarly to the above technique, we use wp theme list to get information regarding the installed themes and updates. To refine the result we use grep and awk commands in a way to get only the themes names:

# wp theme list | grep available | awk '{print $1}'

twentynineteen

twentyseventeen

twentysixteen

After that, we loop through the result and apply patches. Here is how the command would look like:

for i in $(wp theme list | grep available | awk '{print $1}'); do wp theme update $i; done

Now let’s piece the details together and compile the script:

#!/bin/bash

# Core update

wp core update

# Plugins update

for i in $(wp plugin list | grep available | awk '{print $1}'); do wp plugin update $i; done

# Themes update

for i in $(wp theme list | grep available | awk '{print $1}'); do wp theme update $i; done

In addition, the above easy WordPress automation could be set as a cronjob to run once a week. This way you could be sure that your application gets updated frequently.

Note that the script is not intended to generate backups before applying updates. Developing a more complex script is a subject of another article.


Do you want to share your opinion?

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


*

Рязане и пробиване на бетон Сканиране на бетон Безвзривно разрушаване на бетон
We are not industry specific. We are WordPress specific. We work with everyone to help them find solutions with their troubles.
If you show us the problem you are experiencing, we will show you how to fix it. It is that simple.


Reported WordPress issues

  1. Wordpress: How to create a website that customer can make their own profile in there and observable via their pages
  2. How do I make my SVG larger within a HTML table?
  3. Replace result of a wordpress function in a hook
  4. i receive this email from my data center :“ We have detected abuse…”
  5. Is it wordpress plugin [on hold]
  6. After AWS Cloudfront Setup Browser Info is Incorrect
  7. wp mail smtp settings takes in custom created plugin
  8. Exclude page from restriction
  9. WP All-in-One Migration shows “wp-config already exists”
  10. contact form 7 wordpress dropdown

WordPress problems we are working on

  1. Wordpress multisite redirects subpages to homepage
  2. Programmatically add value to custom field based on custom field
  3. Failed to load resource: the server responded with a status of 503 ()
  4. How to find relavant element from an array based on index using number in the loop?
  5. Wordpress custom Gutenberg Block not reloading correctly
  6. Suddenly starts receiving alert when trying to login to wordpress admin panel
  7. Issue with polish character in FPDF
  8. How to fix theme thumbnails without uploading images to media library?
  9. Highlighting Current Page in Nav_Menu (WordPress) /w SASS
  10. API integration in WordPress to pass login details to app

Resolved issues

  1. How To Allow Special Characters & Capital Letters In Wp Permalink?
  2. Create Submenu with Redux Framework _WordPress
  3. Wordpress Boostrap NavMenu on mobile hides after displaying
  4. Can give access to only one Plugin?
  5. Youtube within a Paywall site
  6. How To Add Custom Fields in Dokan Vendor Dashboard
  7. How to extract Product attributes from Product Variations
  8. Stripe Payment Button Not Responsive
  9. Output ACF Flexible Content fields in a table (with the table header not to be repeated through loop)
  10. How do I create a sliding team section with variable positioning and z-indexes?
wppotion - powered by persistence and passion