テーマレビュー用の真新しい環境を1分で作成する。WP-CLI Advent Calendar 2014 19日目

wp-cli アドベントカレンダー、先週は僕ではなくて自称の私に書いてもらうという失態をしてしまってすみません。。。ひゃっほーーー!!!というキャラだったのかしらアラヤダ。

さて、昨日の自作プラグインに追加した wp-cli コマンドの出力結果を整形しよう ( WP-CLI Advent Calendar 2014 18日目 ) | dogmap.jpに引き続きまして、本日19日目は、wp-cli を利用してテーマレビュー用の環境を作ろうというテーマで、パワフルなwpのコマンドの紹介をしつつ、1個のファイルにまとめて置いておけば、便利でいいさね、といったところをご紹介したいと思います。

目次

テーマレビュー用の環境?一度作ればそれでよくない??

そういう疑問も出てくるとは思うのですが、

  • 毎回まっさらな状態を用意しないといけない
  • けど、テーマユニットテストデータのインポートも必要
  • サイトの名前やタグラインを長くしたりいろいろしないといけない
  • プラグインもいろいろ入ってるとありがたい
  • もろもろ最新版にしておきたい

というまっさらだけど、いろいろ準備しないといけないというのが大変なわけです。そんな方々のために、宮内さんのVCCWなるVagrant環境もあります。こちらも超簡単で、

$ wp_theme=http://example.com/path/to/zipped/theme/file.zip vagrant up

というコマンドのみでいろいろしてくれます。

 今回のやること

今回自動的にパパっとやってしまいことは、上から順番に以下のようになります。

  1. データベースのテーブルを全部消しちゃう
  2. WordPressのインストールプロセスを実施(サイト名、ユーザ名/パスワード/メールを指定)
  3. WordPressのコアを最新版にする
  4. テーマチェック、debogger、非推奨をロギングしてくれるの、モンスターウィジェット、WordPressインポーターのプラグインをインストールして、有効化する
  5. デバッグバー、WordPressベータテスタープラグインをインストールだけする。
  6. プラグインを全部最新版に更新する(2回目以降は、ステップ4と5では古いバージョンはアップデートされないので)
  7. ブログディスクリプションをめっちゃ長くしておく
  8. posts_per_page を 5 にするなど細かいオプションの設定
  9. テーマユニットテストデータのダウンロード、インポート、削除
  10. 指定したテーマのインストール
  11. 画像の再生成(サイズを合わせる)

となります。
実際のコマンドは以下のようになりますので、WordPressのルートに、newreview というファイル名で保存します。

これで、このレビュー用のディレクトリに移動して、以下のコマンドを入力すると、

$ ./newreview https://downloads.wordpress.org/theme/twentyfifteen.1.0.zip

上記のすべてが実行されて、テーマ(この場合はtwentyfifteen)もインストールされて有効化されます。インターネットの環境にもよりますが、1~2分で完了します。

Success: Database reset.
Success: WordPress installed successfully.
Updating to version 4.1 (en_US)...
Success: WordPress is at the latest version.
Warning: theme-check: Plugin already installed.
Activating 'theme-check'...
Success: Plugin 'theme-check' activated.
Warning: debogger: Plugin already installed.
Activating 'debogger'...
Success: Plugin 'debogger' activated.
Warning: log-deprecated-notices: Plugin already installed.
Activating 'log-deprecated-notices'...
Success: Plugin 'log-deprecated-notices' activated.
Warning: monster-widget: Plugin already installed.
Activating 'monster-widget'...
Success: Plugin 'monster-widget' activated.
Warning: wordpress-importer: Plugin already installed.
Activating 'wordpress-importer'...
Success: Plugin 'wordpress-importer' activated.
Warning: debug-bar: Plugin already installed.
Warning: wordpress-beta-tester: Plugin already installed.
Success: Updated 0/0 plugins.
Success: Updated 'blogdescription' option.
Success: Updated 'posts_per_page' option.
Success: Updated 'thread_comments' option.
Success: Updated 'thread_comments_depth' option.
Success: Updated 'page_comments' option.
Success: Updated 'comments_per_page' option.
Success: Updated 'large_size_w' option.
Success: Updated 'large_size_h' option.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  391k  100  391k    0     0  90863      0  0:00:04  0:00:04 --:--:-- 92218
Starting the import process...
Processing post #2 ("About The Tests") (post_type: page)
-- 1 of 148
-- Fri, 19 Dec 2014 07:35:39 +0000
-- Imported post as post_id #3
-- Added post_meta _wp_page_template

(〜中略・テーマユニットテストにあるデータがインポートされる〜)

Processing post #1446 ("Template: Excerpt (Generated)") (post_type: post)
-- 148 of 148
-- Fri, 19 Dec 2014 07:22:26 +0000
-- Imported post as post_id #1446
-- Added terms (79,91,160) for taxonomy "post_tag"
-- Added terms (49,1) for taxonomy "category"
-- Added post_meta _publicize_pending
All done. Have fun!

Remember to update the passwords and roles of imported users.

Success: Finished importing from ./theme-unit-test-data.xml file. 
Downloading install package from https://wordpress.org/themes/download/natura.1.1.zip?nostats=1... 
Unpacking the package... 
Installing the theme... 
Theme installed successfully. 
Activating 'natura'... 
Success: Switched to 'Natura' theme. 
Found 37 images to regenerate. 
Regenerated thumbnails for "spectacles" (ID 1692). 
Regenerated thumbnails for "dsc20050315_145007_132" (ID 1691). 

(〜中略・全部の画像の再生成をしている〜)

Regenerated thumbnails for "dsc20050727_091048_222" (ID 616). 
Regenerated thumbnails for "canola2" (ID 611). 
Success: Finished regenerating all images.

あとひとつ、やりたいけどできていないのが、定義されているウィジェットエリアを全部取得 → すべてのエリアからすべてのウィジェットを削除 → すべてのエリアにモンスターウィジェットを設置、というのなのですが、できていないのでどなたかおしえてくださいませ。wp widgetというコマンドがあるのですが、ウィジェットエリアのIDが取得できないのです(´・ω・`)。

最後に、これはローカル環境を想定していて、サーバに置いておくとまずいと思いますので、その辺よろしくお願いします。

以上です。

明日は、yuji.takehiroさんです。

この記事が気に入ったら
フォローしてね!

よかったらシェアしてね!

著者について

コメント

コメント一覧 (1件)

コメントする

目次
閉じる