開発したアプリなど一覧

WordPress をコマンドラインから操作する wp-cli

アフィリエイトリンクを含む場合があります

WordPress を操作するコマンドがある事を知ったので早速使ってみる。

Command line interface for WordPress | WP-CLI

インストール

$ curl -kL https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wp-cli.phar $ php wp-cli.phar --info PHP binary: PHP version: 5.3.10-1ubuntu3.6 php.ini used: /etc/php5/cli/php.ini WP-CLI root dir: phar://wp-cli.phar WP-CLI global config: WP-CLI project config: WP-CLI version: 0.15.1 $ chmod +x wp-cli.phar $ sudo mv wp-cli.phar /usr/local/bin/wp

見ての通り Ubuntu で試してます。
これで wp コマンドが使えるようになりました。

使ってみる

ざっと使えるコマンドやできる事を確認してみる。

新規インストール

まず本体をダウンロード。

$ cd /path/to/wordpress $ wp core download Downloading WordPress 3.9.1 (en_US)... Success: WordPress downloaded.

次に設定ファイルを作成。

$ wp core config --dbname=wordpress --dbuser=username --dbpass=password Success: Generated wp-config.php file.

wp-config.php が生成できたらインストール。

$ wp core install --url=http://test.loumo.jp --title=test --admin_user=username --admin_password=password --admin_email=hoge@example.com Success: WordPress installed successfully.

できた。

アップデート

最近は管理画面でもできるけど、もちろんコマンドでも。

$ wp core update Downloading update from https://downloads.wordpress.org/release/wordpress-3.9.1-no-content.zip... Unpacking the update... Success: WordPress updated successfully.

プラグインとテーマ

wp plugin status とやると現在の状態が表示される。

$ wp plugin status 9 installed plugins: UI akismet 2.5.9 UA all-in-one-seo-pack 2.1.1 UA google-analytics-for-wordpress 4.3.3 UA google-sitemap-generator 3.4 I hello 1.6 A loumo-filter 0.0.1 A pubsubhubbub 1.6.5 UA syntaxhighlighter 3.1.7 A syntaxhighlighter-user 0.1

Legend: I = Inactive, A = Active, U = Update Available

I:無効, A:有効, U:アップデート有り, という事らしい。

wp plugin update PLUGIN NAME とやると指定したプラグインのアップデートができる。指定するのが面倒であれば --all をつけると全部アップデートしてくれる。

$ wp plugin update akismet Downloading update from https://downloads.wordpress.org/plugin/akismet.3.0.0.zip... Unpacking the update... Installing the latest version... Removing the old version of the plugin... Plugin updated successfully. Success: Updated 1/1 plugins.

$ wp plugin update --all ... Success: Updated 4/4 plugins.

有効化/無効化ももちろん可

$ wp plugin activate akismet Success: Plugin 'akismet' activated.

$ wp plugin deactivate akismet Success: Plugin 'akismet' deactivated.

テーマも同じような感じ

$ wp theme status 3 installed themes: UA twentyfourteen 1.0 UI twentythirteen 1.1 UI twentytwelve 1.3

Legend: A = Active, I = Inactive, U = Update Available $ wp theme update twentytwelve Downloading update from https://wordpress.org/themes/download/twentytwelve.1.4.zip... Unpacking the update... Installing the latest version... Removing the old version of the theme... Theme updated successfully. Success: Updated 1/1 themes.

$ wp theme update --all ... Success: Updated 2/2 themes.

コマンドの使い方を調べる

コマンドの使い方は --help を引数につけると表示される。

$ wp --help (wp コマンドのヘルプ画面が表示される)

$ wp plugin --help (wp plugin コマンドのヘルプ画面を表示)

wp の導入や管理をスクリプトで自動化するとかに使えるかな?

Sponsored Link

コメント

タイトルとURLをコピーしました