関数 wp_maintenance()
2014/12/05
目次
メンテナンスモードの関数を定義
定義ファイル :/blog/wp-includes/load.php
呼出元 :/blog/wp-settings.php
1 2 3 | function wp_maintenance() { if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) ) return; |
関数
file_exists() maintenanceファイルまたはディレクトリが存在するかどうか調べる
定数
ABSPATH
WP_INSTALLING
1 2 | global $upgrading; include( ABSPATH . '.maintenance' ); |
変数 $upgrading
関数 include() include 文は指定されたファイルを読み込み、評価します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | // If the $upgrading timestamp is older than 10 minutes, don't die. if ( ( time() - $upgrading ) >= 600 ) return; if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { require_once( WP_CONTENT_DIR . '/maintenance.php' ); die(); } wp_load_translations_early(); $protocol = $_SERVER["SERVER_PROTOCOL"]; if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) $protocol = 'HTTP/1.0'; header( "$protocol 503 Service Unavailable", true, 503 ); header( 'Content-Type: text/html; charset=utf-8' ); header( 'Retry-After: 600' ); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php _e( 'Maintenance' ); ?></title> </head> <body> <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1> </body> </html> <?php die(); } |
WordPress のメンテナンスモードの条件
WordPress をインストールしたディレクトリに .maintenance と言うファイルがあること
WP_INSTALLING という定数が設定されていないこと
$upgrading という変数に設定されているタイムスタンプが、現在時刻より 10 分以内であること
読込みファイル
このファイルはデフォルト(Wordpress4.0)で存在しない
maintenance.php
過去互換でこの関数は存在していると思われる
関数
wp_load_translations_early() 翻訳辞書
time() 現在時間 UNIXタイムで
require_once() 1度だけ読み込み
die() exit と同等
header() 生の HTTP ヘッダを送信する
is_rtl() 現在のロケールが右書き(文字を右から左へ書き進めること)か調べる。
_e() 現在のロケールに応じた翻訳テキストを表示する。
メンテナンスのため503エラーを準備
503 Service Unavailable
自動アップグレード処理判定
「.maintenance」ファイルが存在したら処理をします。この「.maintenance」は通常はありません。自動アップ デートのときの、処理中であるという印ファイルを作成し、印ファイルがあるときにアクセスしたら次のようなメッセージを表示しています。
Briefly unavailable for scheduled maintenance. Check back in a minute
ちょっとの間、定期メンテナンス中の為利用できません。数分後にきてください。