毎度うっかりするからまとめた。
1. 不要なファイルは消す
- readme.html
- license.txt
- wp-admin/install.php
2. ログインエラーの変更
詳細な内容からふわっとした内容に変える。
add_filter( 'login_errors', function( $error ) {
global $errors;
$err_codes = $errors->get_error_codes();
// Invalid username.
// Default: '<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password</a>?'
if ( in_array( 'invalid_username', $err_codes ) ) {
$error = '<strong>エラー</strong>: ログインできません';
}
// Incorrect password.
// Default: '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password</a>?'
if ( in_array( 'incorrect_password', $err_codes ) ) {
$error = '<strong>エラー</strong>: ログインできません';
}
return $error;
} );
3. authorページを表示しない
ログインIDの特定に利用されるため。
/** * authorページを表示しない */ add_filter( 'author_rewrite_rules', '__return_empty_array' );
4. 著者アーカイブを表示しない
これもIDの特定に利用されるため。
/**
* 著者アーカイブを表示しない
*/
add_action('init', function () {
if( is_author() || ($_GET && array_key_exists('author', $_GET)) || preg_match('#/author/.+#', $_SERVER['REQUEST_URI']) ){
wp_redirect( home_url( '/404' ) );
exit;
}
});
5. REST APIでusersリクエストを返さない
これもIDの特定に利用されるため。
add_filter( 'rest_endpoints', function( $endpoints ){
if ( isset( $endpoints['/wp/v2/users'] ) ) {
unset( $endpoints['/wp/v2/users'] );
}
if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
}
if ( isset( $endpoints['/wp/v2/users/me'] ) ) {
unset( $endpoints['/wp/v2/users/me'] );
}
return $endpoints;
});
全部または特定のデフォルトエンドポイントを消すならこれで。
6. feedの出力をしない or 限定する
/**
* Feedの出力全部殺す
*/
add_action( 'parse_query', function ( $obj ) {
if ( $obj->is_comment_feed || $obj->is_feed ) {
wp_die('', '', array( 'response' => 404, "back_link" => true ));
}
});
post_typeなどで殺すのを選ぶ場合は条件を追加する
// post_type=news 以外を殺す
( $obj->is_feed && $obj->get('post_type') !== 'news')
7. headタグから不要なmeta情報を消す
自動フィードリンクしないのは前のfeed殺すのと併用か、自作テーマでリンク入るところを限定したい時に一旦全部消す場合などに。
add_action( 'after_setup_theme', function() {
// generatorを非表示にする
remove_action('wp_head', 'wp_generator');
// EditURIを非表示にする
remove_action('wp_head', 'rsd_link');
// wlwmanifestを非表示にする
remove_action('wp_head', 'wlwmanifest_link');
//自動フィードリンクしない
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
});