ユーザー情報(ユーザー名や権限)を出力しないようにする。
「?author=ユーザーID」をurlにつけるとID1の投稿者アーカイブにユーザー名が表示されてしまう。
投稿者アーカイブにアクセスできないようにする。
※トップページにリダイレクトさせる
function.phpに記述
add_filter( 'author_rewrite_rules', '__return_empty_array' );
function disable_author_archive() {
if( $_GET['author'] || preg_match('#/author/.+#', $_SERVER['REQUEST_URI']) ){
wp_redirect( home_url( '/404.php' ) );
exit;
}
}
add_action('init', 'disable_author_archive');
WordPressはWP REST APIという仕組みで外部からJSON形式でデータ取得できる。
hogehoge.com/wp-json/wp/v2/usersでユーザーデータが取得できる。
この出力を止める
function.phpに記述
function filter_rest_endpoints( $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]+)'] );
}
return $endpoints;
}
add_filter( 'rest_endpoints', 'filter_rest_endpoints' );
コメント機能を使っているとコメントテンプレートであるcomment-template.phpにより、コメント欄が出力される。
このテンプレートでは投稿者名のクラスが付与されるのでクラスの出力を止める。
function.phpに記述
function remove_comment_author_class( $classes ) {
foreach( $classes as $key => $class ) {
if(strstr($class, "comment-author-")) {
unset( $classes[$key] );
}
}
return $classes;
}
add_filter( 'comment_class' , 'remove_comment_author_class' );