Script to Upgrade Plugins on WordPress to the latest version fully automatically
UPDATE: Please check out latest version from my git repo: http://git.vpetkov.net/projects – project name: “wordpress”
I already created a script to upgrade wordpress installations automatically. You can find it here: http://blog.vpetkov.net/2011/06/01/script-to-upgrade-wordpress-to-the-latest-version-fully-automatically Recently, the same general problem came about when it came to plugins. The biggest problem I had is that I had to log-into wordpress, see a number of plugins that were outdated, and then go hunt each one down by generally just copying the name and pasting it into google . Even thought most of the time, the plugin was the first hit, I then had to download the latest version, extract it, and clean it up. Imagine doing this for 10+ plugins for 5+ blogs — constantly. It was just time consuming and frustrating.
Here is my solution in the form of a perl script:
#!/usr/bin/perl # Usage: # ./update-wp-plugins.pl # or # ./update-wp-plugins.pl registered-name-of-plugin # (and this works to update an exiting plugin or download+install a new one) chdir("/var/www/domain/blog/wp-content/plugins"); use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->agent_alias( 'Mac Safari' ); my $wp_base_url = "http://wordpress.org/extend/plugins"; ################################################ # Add New Plugins Here: # Format: # 'registered-name-of-plugin', # my @plugins = ( 'google-sitemap-generator', 'wptouch', ); ################################################ if(defined($ARGV[0])) { my $name = $ARGV[0]; &update_plugin($name); } else { for my $name (@plugins) { &update_plugin($name); } } sub update_plugin { my $name = shift; my $url = "$wp_base_url/$name"; $mech->get( $url ); my $page = $mech->content; my ($url,$version,$file) = ""; if($page =~ /.*<p class="button"><a href='(.*)'>Download Version (.*)<\/a><\/p>.*/) { $url = $1; $version = $2; if($url =~ /http:\/\/downloads\.wordpress\.org\/plugin\/(.*)/) { $file = $1; } } print "\nPLUGIN: $name | Version $version\n"; `/bin/rm -f $file`; print "Downloading: \t$url\n"; `/usr/bin/wget -q $url`; print "Unzipping: \t$file\n"; `/usr/bin/unzip -o $file`; print "Installed: \t$name\n"; `/bin/rm -f $file`; }
This script can be used in one of two ways:
1.) You can simply run it, and it will update everything that you have listed in the @plugins array.
2.) You can give it a parameter of a registered plugin name. This does 2 jobs — upgrades an existing plugin, AND installs new ones.
You can definitely add an extension to this. For #1, you can go a step further by making it scan your plugin directory and populating the list from there. If you want to be even fancier, you can relatively easily keep version tracks of what you have installed and what’s currently available, so that you don’t just blindly download new plugins. For me this is sufficient. If anyone is interested in getting help implementing any of these extra additions, feel free to ask and I’ll help as much as I can.
Recent Comments