• Hello

    I need to build website where different clients have access only to their personal pages. My idea is to use wp_dropdown_pages() as login. Basically each client (USER in WP) is named same as personal PAGE. I managed to make things work till the moment when I need to combine dropdown data with login form.
    Does anyone know how to send data (page name) from dropdown to wp_login_form() as LOGIN and just type password in the box?
    This is my code:

    // Add login form to menu
    add_filter(‘wp_nav_menu_items’, ‘add_login_logout_link’, 10, 2);

    function add_login_logout_link($items, $args) {
    // start buffering
    ob_start();
    // this is the actual form function
    $login_args = array(
    ‘redirect’ => admin_url(),
    ‘form_id’ => ‘loginform-custom’,
    ‘label_username’ => __( ‘Username custom text’ ),
    ‘label_password’ => __( ‘Password custom text’ ),
    ‘label_remember’ => __( ‘Remember Me custom text’ ),
    ‘label_log_in’ => __( ‘Log In custom text’ ),
    ‘remember’ => false
    );

    $dropdown_pages_args = array(
    ‘depth’ => 0,
    ‘child_of’ => 6,
    ‘selected’ => 0,
    ‘echo’ => 1,
    ‘name’ => ‘page_id’,
    ‘id’ => null, // string
    ‘class’ => null, // string
    ‘show_option_none’ => null, // string
    ‘show_option_no_change’ => null, // string
    ‘option_none_value’ => null, // string
    );

    //Dropdown Pages
    wp_dropdown_pages( $dropdown_pages_args );

    wp_login_form($login_args);
    // get buffering
    $loginoutform = ob_get_contents();
    // clean buffering
    ob_end_clean();
    $items .= $loginoutform ; // concatenate buffering with items …
    return $items;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    If the dropdown is on the same page as the login form, you’d have to use javascript to load the username field with the selection from the dropdown. In order to use PHP the dropdown page would request the login page, passing the selection as an URL parameter, which is then taken from $_GET and used in the arguments array for wp_login_form().

    Thread Starter WanderlustShutter

    (@wanderlustshutter)

    Thanks. Do You know where I can find examples of this kind of use?

    Moderator bcworkz

    (@bcworkz)

    Sorry, no.

    Another thought though. Replicate the HTML output of wp_login_form(), but use the dropdown in place of the user name text field. Assigning it the same name attribute should result in the same form data being submitted.

    The tricky part will be replicating the hidden nonce field. This could be done by examining what the source of wp_login_form() does.

    I can imagine this is a challenge without an example, but break it down into small parts, it’s easier to find such examples. Then use common sense logic to sting the parts together into your custom hack. It’ll be slow going, but you’ll get there if you’re patient and methodical.

    Thread Starter WanderlustShutter

    (@wanderlustshutter)

    Ok. I will try to figure it out. For now the code I posted stopped working :/ It doesn’t show anything in the menu bar anymore.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Login with wp_dropdown_pages’ is closed to new replies.