标签 ‘WordPress’ 归档文章

命令行自动升级 WordPress 插件

作为个人网站,自动升级插件的风险应该是可控的。 因此用命令行自动升级,可以免除手工下载安装的麻烦。

1. 安装 WP-CLI:

$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

$ php wp-cli.phar –info

$ chmod +x wp-cli.phar

$ sudo mv wp-cli.phar /usr/local/bin/wp

更新所有模块:

# wp –allow-root plugin  update –all

另外:

升级 WordPress 核心:

# wp –allow-root core update
Updating to version 4.6.1 (en_US)…
Downloading update from https://downloads.wordpress.org/release/wordpress-4.6.1-new-bundled.zip…
Unpacking the update…

安装新的插件:

# wp –allow-root plugin install https://downloads.wordpress.org/plugin/google-captcha.1.27.zip
Downloading install package from https://downloads.wordpress.org/plugin/google-captcha.1.27.zip…
Unpacking the package…
Installing the plugin…
Plugin installed successfully.

升级主题:

# wp –allow-root theme update –all

[bws_google_captcha]

Convert back WP MU to WordPress

Godaddy’s WordPress only support single user, not the MU version, have to convert back original WPMU version to single user version.

Since I have to install multiple version of WordPress, each of them has its own DB. I put a .sid for each of mysql DBs as original .my.cnf file.

Contents like this:

# freelamp.com
[client]
host = frexxxxxxx.db.7114699.hostedresource.com
user = frexxxxx
port=3306

[mysql]
database = frexxxxxxxx

Then create alias in .bash_profile for each mysql instance:

alias mysql.albertxu=’mysql  –defaults-file=~/.albertxu -p ‘
alias mysql.freelamp=’mysql  –defaults-file=~/.freelamp -p ‘

So that I can just use mysql.freelamp to log into DB.

The first step is to import the original exported wpmu DB, it includes all the other users tables(blogs), we’ll remove them later.

I write a rename.sh, to rename the required tables:

-bash-3.2$ cat rename.sh
#!/bin/bash
id=$1
[ -z “$id” ] && echo “Syntax: $0 blog_id” && exit 0
FILE=$id.sql
echo > $FILE

# we ignore this two tables: cas_count cas_image
for t in  posts commentmeta comments links options postmeta terms term_relationships term_taxonomy
do
echo “DROP TABLE IF EXISTS wp_$t ;” >> $FILE
echo ALTER TABLE wp_”$id”_$t RENAME TO wp_$t “;” >> $FILE
done

echo UPDATE wp_options set option_name=\”wp_user_roles\” WHERE option_name=\”wp_”$id”_user_roles\” “;” >> $FILE
echo UPDATE wp_usermeta set meta_key=\”wp_capabilities\” WHERE meta_key=\”wp_”$id”_capabilities\” “;” >> $FILE
echo UPDATE wp_usermeta set meta_key=\”wp_user_level\” WHERE meta_key=\”wp_”$id”_user_level\” “;” >> $FILE

cat $FILE

Check the output of the above script, then run mysql.freelamp < 2.sql ( in the example, $id = 2 ), you should see all the blog contents in original WPMU site now migrated. The remain thing is log in the control panel to change “Media” folder path and PermsLinks Settings.

And remove non-used users also.

At last, you should remove all these not in using other user’s tables.

SQL command: show tables like “wp\__\_%”  can list all the others tables not needed, just filter them to a script and make it like

DROP TABLE IF EXISTS $tablename.

All set.   LOL.

Upgrade WordPress 到 2.8.4

Category:Wikipedians who use WordPress
Image via Wikipedia

没有想到, Bug 这么快就被发现,马上有新版本紧急需要更新了。根据前次的升级2.8.1 的思路,写一个脚本来自动升级:

#!/bin/sh
unzip $1
VER=$2
NEWDIR=wordpress-$VER
mv wordpress $NEWDIR
cp blog/.htaccess blog/wp-config.php $NEWDIR
cp -r blog/wp-content/themes/* $NEWDIR/wp-content/themes
rm blog
ln -s $NEWDIR blog

Reblog this post [with Zemanta]

升级 WordPress 到 2.8.1

Category:Wikipedians who use WordPress
Image via Wikipedia

升级的步骤非常简单:

  1. 从官方下载 latest.zip ,解压缩到 Web 服务器的根目录的上一层,我喜欢用软连接,因为这样随时可以 rollback。原来的 wordpress2.7.1 目录软连接到 blog 目录,新的解压后的目录修改为 wordpress2.8.1 , 然后重新软连接到 blog
  2. 拷贝2.7.1 目录下 wp-config.php 和 .htaccess 到新的目录下
  3. 拷贝原来的模板文件: cp -r ../wordpress-2.7.1/wp-content/themes/* wp-content/themes/
  4. 在浏览器上运行 /wp-admin/upgrade.php 升级数据库
  5. 删除或者重命名 wp-admin 目录下的 install.php 和 upgrade.php

Ctr-F5 刷新自己的网站即可看到系统已经升级成功。

Reblog this post [with Zemanta]
Google+