WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Front-End Login using PHP

[Resolved] Front-End Login using PHP

Viewing 11 replies - 1 through 11 (of 11 total)
  • What do you mean by account management? Are you referring to the dashboard?

    The other things are covered with the following code:

    <?php
    if ( ! is_user_logged_in() ) { // Display WordPress login form:
        $args = array(
            'redirect' => admin_url(),
            'form_id' => 'loginform-custom',
            'label_username' => __( 'Username' ),
            'label_password' => __( 'Password' ),
            'label_log_in' => __( 'Log In' ),
            'remember' => true
            );
        wp_login_form( $args );
        echo wp_lostpassword_url( $redirect );
        echo wp_registration_url();
    } else { // If logged in:
        wp_loginout( home_url() ); // Display "Log Out" link.
        echo " | ";
        wp_register('', ''); // Display "Site Admin" link.
    }
    ?>

    Thanks for responding! The Dashboard, that’s correct.

    I’ve entered the new code into the widget, which results in this (Chrome):

    http://i.imgur.com/CzT4e5L.jpg

    Just to be clear, you want the admin link to show if they are logged in correct? If not they would just be redirected to another login screen which would be pointless unless I’m missing something.

    Try this for displaying lost password and registration links:

    <?php
    if ( ! is_user_logged_in() ) { // Display WordPress login form:
        $args = array(
            'redirect' => admin_url(),
            'form_id' => 'loginform-custom',
            'label_username' => __( 'Username' ),
            'label_password' => __( 'Password' ),
            'label_log_in' => __( 'Log In' ),
            'remember' => true
            );
        wp_login_form( $args );
        wp_lostpassword_url( $redirect );
        wp_registration_url();
    } else { // If logged in:
        wp_loginout( home_url() ); // Display "Log Out" link.
        echo " | ";
        wp_register('', ''); // Display "Site Admin" link.
    }
    ?>

    That’s correct, yes.

    I’ve copied in the latest code, and now nothing displays for the

    wp_login_form( $args );
        wp_lostpassword_url( $redirect );
        wp_registration_url();

    part (whereas before we had plain text as the picture in my last post illustrates).

    Sorry, try this. Of course you may need to style this with css:

    <?php
    if ( ! is_user_logged_in() ) { // Display WordPress login form:
        $args = array(
            'redirect' => admin_url(),
            'form_id' => 'loginform-custom',
            'label_username' => __( 'Username' ),
            'label_password' => __( 'Password' ),
            'label_log_in' => __( 'Log In' ),
            'remember' => true
            );
        wp_login_form( $args );
        echo '<a href="' . wp_lostpassword_url( $redirect ) . '">Lost Password?</a>';
        echo '<a href="' . wp_registration_url() . '">Register</a>';
    } else { // If logged in:
        wp_loginout( home_url() ); // Display "Log Out" link.
        echo " | ";
        wp_register('', ''); // Display "Site Admin" link.
    }
    ?>

    Thank you so much graphical_force, that has cracked it! Now I’ll spend some time figuring out how to make it appear like this:

    Register | Lost Password?

    I’m trying

    echo '<a href="' . wp_registration_url() . '">Register</a>';
        echo " | ";
        echo '<a href="' . wp_lostpassword_url( $redirect ) . '">Lost Password?</a>';

    There are a few ways to do that. The way you are doing it there should work as well.

    Would you be kind enough to share the other methods with me? Mine didn’t end up displaying the | at all unfortunately.

    Try this:

    <?php
    if ( ! is_user_logged_in() ) { // Display WordPress login form:
        $args = array(
            'redirect' => admin_url(),
            'form_id' => 'loginform-custom',
            'label_username' => __( 'Username' ),
            'label_password' => __( 'Password' ),
            'label_log_in' => __( 'Log In' ),
            'remember' => true
            );
        wp_login_form( $args );
        echo '<a href="' . wp_lostpassword_url( $redirect ) . '">Lost Password?</a> | <a href="' . wp_registration_url() . '">Register</a>';
    } else { // If logged in:
        wp_loginout( home_url() ); // Display "Log Out" link.
        echo " | ";
        wp_register('', ''); // Display "Site Admin" link.
    }
    ?>

    Perfect, thank you so much graphical_force. Your help is greatly appreciated! 🙂

    No problem. 🙂

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] Front-End Login using PHP’ is closed to new replies.
Skip to toolbar