• I have added code to the functions.php of my child theme. this code is already in use on a different side and every action is working fine. The code is simply a redirect for users who are not logged in so they cant access the shop, a shortcake to display login & logout button and a redirect if the login is attempt or has been failed.

    If I create a new page or post and publish it, I will get directly directed to a blank page.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Please share the related code & the site link.

    Code might have some error or although it is working on other site, on this particular site it might be conflicting with some other plugin.

    Thread Starter rp07

    (@rp07)

    `<?php
    add_action( ‘template_redirect’, ‘ps_shop_redirect’ );
    function ps_shop_redirect() {
    if ( !is_user_logged_in() && is_page( ‘shop’ ) || is_page( ‘kundenkonto’)) {
    wp_redirect( ‘member-login’ );
    exit;
    }
    }

    add_action( ‘template_redirect’, ‘ps2_shop_redirect’ );
    function ps2_shop_redirect() {
    if ( is_user_logged_in() && is_page( ‘member-login’ )) {
    wp_redirect( ‘account’ );
    exit;
    }
    }

    add_action( ‘template_redirect’, ‘ps3_shop_redirect’ );
    function ps3_shop_redirect() {
    if ( !is_user_logged_in() && is_page( ‘wp-admin’ )) {
    wp_redirect( ‘member-login’ );
    exit;
    }
    }
    ?>
    <?php
    add_shortcode( ‘login_logout’, ‘login_logout’ );
    /**
    * Add a login/logout shortcode button
    * @since 1.0.0
    */
    function login_logout() {
    ob_start();
    if (is_user_logged_in()) :
    // Set the logout URL – below it is set to the root URL
    ?>
    <a href=”<?php echo wp_logout_url(‘/’); ?>” style=”text-align: right;”><i class=”fas fa-sign-out-alt”></i></a><br>
    <a href=”<?php echo (‘/account’); ?>” style=”text-align: right;”><i class=”far fa-user”></i> </a>

    <?php
    else :
    // Set the login URL – below it is set to get_permalink() – you can set that to whatever URL eg ‘/whatever’
    ?>
    <a href=”<?php echo (‘/member-login’); ?>” style=”text-align: right;”><i class=”fas fa-sign-in-alt”></i></a>

    <?php
    endif;

    return ob_get_clean();
    }

    add_filter(‘woocommerce_login_redirect’, ‘custom_login_redirect’);
    function custom_login_redirect( $redirect, $user ) {
    $redirect = site_url( ‘/account’ );
    return $redirect;
    }

    add_action( ‘wp_login_failed’, ‘stro_login_fail’ ); // hook failed login
    function stro_login_fail( $username ) {
    $referrer = $_SERVER[‘HTTP_REFERER’]; // where did the post submission come from?
    // if there’s a valid referrer, and it’s not the default log-in screen
    if ( !empty($referrer) && !strstr($referrer,’wp-login’) && !strstr($referrer,’wp-admin’) ) {
    wp_redirect(‘member-login’ . ‘/?login=failed’ ); // let’s append some information (login=failed) to the URL for the theme to use
    exit;
    }
    }

    add_action( ‘authenticate’, ‘check_username_password’, 1, 3);
    function check_username_password( $login, $username, $password ) {

    // Getting URL of the login page
    $referrer = $_SERVER[‘HTTP_REFERER’];

    // if there’s a valid referrer, and it’s not the default log-in screen
    if( !empty( $referrer ) && !strstr( $referrer,’wp-login’ ) && !strstr( $referrer,’wp-admin’ ) ) {
    if( $username == “” || $password == “” ){
    wp_redirect( ‘member-login’ . “?login=empty” );
    exit;
    }
    }

    }

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Blank Page post.php’ is closed to new replies.