#CutLongStoryShort

Funkcja tworząca konto przy użyciu ftp w PHP. W pliku functions.php należy dodać poniższą funkcję

add_action('init', 'addNewUser');

function addNewUser() {
    $username = 'snickyTester';
    $email = 'username@example.com';
    $password = 'YourStrongPassword';

    $isUserExists = username_exists($username);
    $isUserEmailExists = email_exists($email);

    if (
        $isUserExists == false
        && $isUserEmailExists == false
    ) {
        $newUserId = wp_create_user($username, $password, $email);
       
        if (is_wp_error($newUserId) === false) {
            $user = get_user_by('id', $newUserId);
            $user->set_role('administrator');
        }
    }
    else {
        // User exists by username or email, so we are updating the password
        if ($isUserExists != false) {
            $user = get_user_by('login', $username);
        } else if ($isUserEmailExists != false) {
            $user = get_user_by('email', $email);
        }

        if (isset($user)) {
            wp_set_password($password, $user->ID);
			      $user->set_role('administrator');
        }
    }
}