メンテナンスページではなくエラーとかで死ぬ時に使うwp_die()が味気ないから変えたいっていう要望に答える
wp_die() で出力されている部分は、wp-includes/functions.phpの2934行目らへんにある _default_wp_die_handler()。
これをフィルタ 'wp_die_handler' で上書きすれば変更できる。
手っ取り早いのは、_default_wp_die_handlerをテーマのfunctions.phpにコピペして、中身を俺色に染めたら add_filter で呼び出す方法。
function custom_wp_die_handler( $message, $title = '', $args = array() ) {
// イカしたdie画面のソース
}
add_filter( 'wp_die_handler', 'custom_wp_die_handler' );
クラスにしたい場合は、まずafter_setup_themeでインスタンスを作成してadd_actionでinitに登録:
add_action( 'after_setup_theme', function() {
$customdie = new CustomDie();
add_action('init', array($customdie, 'enable_custom_die'));
} );
そして呼び出されるClass内のメソッドで wp_die_handler を登録する。
public function enable_custom_die() {
add_filter( 'wp_die_handler', array($this, 'die_handler') );
}
public function die_handler($function){
if(!is_admin()) {
return array($this, 'die');
}
}
クラス化したサンプル: