3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Wordpressのユーザー名(ログインID)を隠そう!

Last updated at Posted at 2019-01-25

URL末尾に?author=1を入れると、ユーザー名がダダ漏れ。
そのための対策をまとめてみた。

プラグイン「Edit Author Slug」で設定

管理画面の[ユーザー]>[各ユーザープロフィール]から、任意の文字列を設定できる。
スクリーンショット 2019-01-25 18.07.12.png
「2」を選択、保存した場合、
http://example.jp/?author=2
で検索すると、URLが
http://example.jp/author/2
と書き換えられる。
その際のページの表示は、投稿者アーカイブ。あくまで、URLのみの変更。

仮に
http://example.jp/author/ユーザー名
で検索されてしまっても、
http://example.jp/author/2
に書き換えられる。
セキュリティとして高く、かつ自然な動き。

プラグイン「All In One WP Security」で設定

管理画面の[WP Security]>[Miscellaneous]>[Users Enumeration]から、
Disable Users Enumerationにチェック。
スクリーンショット 2019-01-25 18.11.36.png
?author=1で外部から管理者情報にアクセスしようとすると、
「Accessing author info via link is forbidden」というエラーページが表示される。
スクリーンショット 2019-01-25 18.06.24.png

直打ちで、http://example.jp/author/ユーザー名で検索されてしまっても、
URLは書き変わらない。(つまり、ユーザーIDがバレてしまう可能性あり)

functions.phpで、投稿者アーカイブ非表示リダイレクト

?author=1でアクセスしようとすると、フロントページにリダイレクトされる。
管理画面やURLの直打ちで投稿者アーカイブを見ようとしても、同じようにリダイレクトされてしまう。

functions.php
function author_archive_redirect() {
  if( is_author() ) {
    wp_redirect( home_url());
    exit;
  }
}
add_action( 'template_redirect', 'author_archive_redirect' );

参考URL

3
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?