如何使wordpress博客对公众完全不可见[非私有] [英] How to make wordpress blog completely invisible to public [Not Private]
问题描述
我想关闭我从公众那里获得的wordpress博客,并仅保留给我自己.
I want to close a wordpress blog I have from the public and keep it only for myself.
我知道我可以将其设置为私有,但是它显示了一个不稳定的登录页面,并且我不希望人们尝试访问它(使用随机的用户名/密码等),或者认为它仍然处于打开状态,但对于具有帐户或诸如此类的东西.
I know I can set it to private but it shows an uggly log-in page and I dont want people trying to access it (using random usernames/pass etc) or think that its still open but its for members with accounts or anything like that.
我希望博客指向公众的未找到服务器",当我以管理员身份登录时可以看到我的帖子和后端以及前端.
I would like the blog to point to a " server not found " for the public and when I am logged in as admin to be able to see my posts and backend aswell as frontend.
我怎样才能做到这一点?
How can I make this possible?
推荐答案
我的建议如下:
function is_login_page() {
return in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) );
}
function wpse_make_blog_private() {
if ( ! is_user_logged_in() && ! is_admin() && ! is_login_page() ) {
global $wp_query;
$wp_query->set_404();
}
}
add_action( 'wp', 'wpse_make_blog_private' );
它将在所有页面上显示404,但仍然允许您登录.登录的用户将看到该站点正常.
It will show a 404 on all pages but still allow you to login. Logged in users will see the site as normal.
根据您的要求显示一个完整的站点,请将以下代码添加到functions.php中.请注意,这是上面的代码.
On your request to show a completely broken site add the following code to functions.php. Be aware that this is instead of the code above.
function is_login_page() {
return in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) );
}
function wpse_make_blog_private() {
if ( ! is_user_logged_in() && ! is_admin() && ! is_login_page() ) {
die();
}
}
add_action( 'wp', 'wpse_make_blog_private' );
您可以选择使用wp_die来添加样式最少的错误消息.请参阅: https://codex.wordpress.org/Function_Reference/wp_die
You have the option of using wp_die instead to add an error message with minimal styling. See: https://codex.wordpress.org/Function_Reference/wp_die
这篇关于如何使wordpress博客对公众完全不可见[非私有]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!