Skip to content

Instantly share code, notes, and snippets.

@robhurring

robhurring/USAGE

Created Nov 12, 2011
Embed
What would you like to do?
Update or export wordpress using Thor from the command line : http://proccli.com/update-wordpress-ruby-thor
1. install thor gem
> gem install thor
2. add wordpress script to your wordpress install root and chmod it
> chmod a+x wordpress
3. update wordpress
> ./wordpress update
4. export wordpress (php must have CLI support)
> ./wordpress export | gzip -c > ~/Desktop/wp_export.xml.gz
#!/usr/bin/env ruby
require 'rubygems'
require 'thor'
require 'open-uri'
class Wordpress < Thor
include Thor::Actions
WORDPRESS_URL = %{http://wordpress.org}
FILENAME = %{latest.tar.gz}
TMP_PATH = %{/tmp}
desc 'update', 'Update wordpress to the latest version'
def update
download_url = URI.join(WORDPRESS_URL, FILENAME)
tmp_path = File.join(TMP_PATH, FILENAME)
install_path = File.expand_path(File.dirname(__FILE__))
say %{Downloading latest version of wordpress from #{download_url}}, :yellow
run %{`which curl` #{download_url} -o #{tmp_path}}
say %{Installing to #{install_path}}, :yellow
if yes?(%{Continue? [yes/no]: }, :green)
say %{Updating...}, :yellow
run %{tar -C #{install_path} -xzf #{tmp_path} --strip 1}
else
say %{Update Aborted}, :red
end
end
# See: http://drincruz.blogspot.com/2009/11/wordpress-cli-export.html
desc 'export', 'Export wordpress to STDOUT (same as using the website)'
def export
code = %{
require_once('wp-config.php');
require_once('wp-admin/includes/export.php');
export_wp();
}.gsub(/\n|\s*/,'')
run %{`which php` -r "#{code}"}, :verbose => false
end
end
Wordpress.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.