admin管理员组文章数量:1122826
I've set up a private WP site for clients to hold documentation I get asked for all the time (rather than emailing it or adding it to their G:Drive folder). However, I can't seem to hide the site behind a log in.
// Hide From Non Logged Infunction ti_custom_login_redirect( $url, $request, $user ) {
if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if ( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} else {
$url = home_url( '/user-home/' );
}
}
return $url;
}
add_filter( 'login_redirect', 'ti_custom_login_redirect', 10, 3 );
// Log Out Page
function logout_page() {
$login_page = home_url();
wp_redirect( $login_page . "?user-login=false" );
exit;
}
add_action('wp_logout','logout_page');
add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
/**
* Allow logout without confirmation
*/
if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '/';
$location = str_replace('&', '&', wp_logout_url($redirect_to));
header("Location: $location");
die;
}
}
I've set up a private WP site for clients to hold documentation I get asked for all the time (rather than emailing it or adding it to their G:Drive folder). However, I can't seem to hide the site behind a log in.
// Hide From Non Logged Infunction ti_custom_login_redirect( $url, $request, $user ) {
if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if ( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} else {
$url = home_url( '/user-home/' );
}
}
return $url;
}
add_filter( 'login_redirect', 'ti_custom_login_redirect', 10, 3 );
// Log Out Page
function logout_page() {
$login_page = home_url();
wp_redirect( $login_page . "?user-login=false" );
exit;
}
add_action('wp_logout','logout_page');
add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
/**
* Allow logout without confirmation
*/
if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'https://www.audcomresources.com/';
$location = str_replace('&', '&', wp_logout_url($redirect_to));
header("Location: $location");
die;
}
}
Share
Improve this question
asked Sep 16, 2024 at 13:17
AJ GuitarsAJ Guitars
32 bronze badges
1 Answer
Reset to default 0Much easier to use a simple plugin that has hooks and can allow for pages/posts to be accessible by the non-logged in public. https://wordpress.org/plugins/wp-force-login/
本文标签: user rolesTrying to require log in to view any postpagestaxnomy
版权声明:本文标题:user roles - Trying to require log in to view any postpagestaxnomy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291810a1928803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论