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
Add a comment  | 

1 Answer 1

Reset to default 0

Much 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