1

I'm building a website in wordpress, and I need to make a login page & register page / popup with ajax + account page with some custom fields that I need to put thier like adress, phone number, etc...

I want to make that without any plugins - Can someone give me a tutorial or small explaination how to make it? how to start?

PS - I know PHP SQL in high level - without wordpress I would build that easily, I just need a small help how to make that in wordpress system

Thanks for all :)

0

I am doing the same thing at the moment and I just use the standard WP login/register systems/pages.

You can use wp_signon() to do logon.

Then on a standard page, you can create a custom template and use this for retrieving their info: wp_get_current_user()

You will also need to get the customer user meta information you store too using: get_user_meta()

Hope that helps you :)

| improve this answer | |
0

for find out and init actions

if (!is_user_logged_in()) {
    add_action('init', 'ajax_login_init');
} else {
    add_action('init', 'ajax_logout_init');
}
function ajax_login_init()
{
    add_action('wp_ajax_nopriv_ajax_login', 'ajax_login');
    add_action('wp_ajax_nopriv_ajax_register', 'ajax_register');
}
function ajax_logout_init()
{
    add_action('wp_ajax_ajax_logout', 'ajax_logout');
}

login function

function ajax_login()
{
    check_ajax_referer('ajax-login-nonce', 'security');
    $info = array();
    $info['user_login'] = $_POST['login_username'];
    $info['user_password'] = $_POST['login_password'];
    $info['remember'] = $_POST['remember'];

    $user_signon = wp_signon($info, false);
    if (is_wp_error($user_signon)) {
        wp_send_json(array('status' => 0, 'message' => $user_signon->get_error_message()));
    } else {
        wp_send_json(array('status' => 1, 'message' => __('you currectly logined')));;
    }
}

register function

function ajax_register()
{
    check_ajax_referer('ajax-register-nonce', 'security');
    // Post values
    $username = sanitize_text_field($_POST['register_username']);
    $password = sanitize_text_field($_POST['register_password']);
    $email = sanitize_text_field($_POST['register_email']);
    $name = sanitize_text_field($_POST['register_name']);
    $nick = sanitize_text_field($_POST['register_name']);

    $userdata = array(
        'user_login' => $username,
        'user_pass' => $password,
        'user_password' => $password,
        'user_email' => $email,
        'first_name' => $name,
        'nickname' => $nick,
    );

    $user_id = wp_insert_user($userdata);

    // add user meta
    $custom_user_meta_value = 'custom_user_meta_value';
    add_user_meta( $user_id, 'custom_user_meta', $custom_user_meta_value);

    // Return
    if (!is_wp_error($user_id)) {
        $user_signon = wp_signon($userdata, false);
        if (!is_wp_error($user_signon)) {
            wp_send_json(array('status' => 2, 'message' => __('your registration is successfuled and logined.')));
        } else {
            wp_send_json(array('status' => 1, 'message' => __('your registration is successfuled and logined')));
        }
    } else {
        wp_send_json(array('status' => 0, 'message' => __($user_id->get_error_message())));
    }
}

logout function

function ajax_logout()
{
    check_ajax_referer('ajax-logout-nonce', 'ajaxsecurity');

    wp_logout();
    ob_clean(); // probably overkill for this, but good habit
    echo 'adios!!';
    wp_die();
}

add_action('wp_logout', 'auto_redirect_after_logout');
function auto_redirect_after_logout()
{
    wp_redirect(home_url());
    exit();
}
| improve this answer | |
  • You should try and explain the code you're providing. I know what all the functions you've supplied are supposed to do, but you haven't really explained anything to the user who specified that they don't know WP that well. – Tony Djukic May 17 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.