PHP code example of valkyriweb / wp-remote-auth

1. Go to this page and download the library: Download valkyriweb/wp-remote-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

valkyriweb / wp-remote-auth example snippets



    
    use ValkyriWeb\WPRemoteAuth\WPRemoteAuth;
    use ValkyriWeb\WPRemoteAuth\WordPress\RegisterAjaxEndpoints;

    $token = new WPRemoteAuth();
    
    // Initialise the Class
    $args = [
        'wordpress' => true,
        'remote_login_url' => 'http://' . $baseUrl . '/api/login',
        'remote_register_url' => 'http://' . $baseUrl . '/api/register',
        'remote_logout_url' => 'http://' . $baseUrl . '/api/logout',
    ];
    
    $token->init($args);
    (new RegisterAjaxEndpoints())();
    
    // Generate a token using existing user and store it in the session / database
    $args = [
        'username' => 'test',
        'password' => 'test',
    ];
    
    $token->login($args);
    
    // Generate a token and store it in the session / database
    $args = [
        'name' => 'test',
        'email' => 'test',
        'password' => 'test',
    ];
    
    $token->register($args);
    
    $token->logout();
    
    // Save Token
    $token = $token->generate();
    $user_id = 'wordpress_user_id';
    
    $token->saveToken($token);
    
    // Check if token exists in DB
    // Returns True or False
    $token->checkTokenExists();
    
    // Generate a token
    // Returns a token
    $token->generate();
    
    // Validate a token
    $token->validate($token);