所以我删除了缓存文件夹,删除了很多插件,编辑了.htaccess 文件等仍然无法工作。
我想,如果在登录后缓存问题丢失,并且由于此网站设计为匿名使用,那么请登录一个假用户。
我创建了一个用户anonuser 添加了订阅服务器角色functions.php 此代码用于自动登录(source):
function auto_login() {
$loginusername = \'anonuser\';
if (!is_user_logged_in()) {
//get user\'s ID
$user = get_user_by(\'login\', $loginusername);
$user_id = $user->ID;
wp_set_current_user($user_id, $loginusername);
wp_set_auth_cookie($user_id);
do_action(\'wp_login\', $loginusername);
show_admin_bar(false);
exit;
}
}
add_action(\'wp\', \'auto_login\');
最后,以防有人来访
wp-admin 手动注销并显示登录页面(
source):
add_action( \'init\', \'my_custom_dashboard_access_handler\');
function my_custom_dashboard_access_handler() {
// Check if the current page is an admin page
// && and ensure that this is not an ajax call
if ( is_admin() && !( defined( \'DOING_AJAX\' ) && DOING_AJAX ) ){
//Get all capabilities of the current user
$user = get_userdata( get_current_user_id() );
$caps = ( is_object( $user) ) ? array_keys($user->allcaps) : array();
//All capabilities/roles listed here are not able to see the dashboard
$block_access_to = array(\'subscriber\', \'contributor\', \'my-custom-role\', \'my-custom-capability\');
if(array_intersect($block_access_to, $caps)) {
wp_logout();
wp_redirect( wp_login_url() );
exit;
}
}
}