1. Go to this page and download the library: Download rdelbem/routepress 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/ */
rdelbem / routepress example snippets
use Rdelbem\Routepress\AuthInterface;
use Rdelbem\Routepress\Types\AuthHeader;
use WP_User;
class MyAuth implements AuthInterface {
public function validateRefreshToken(string $refreshToken): bool {
// Your validation logic
}
public function createSession(WP_User $user): void {
// Create a user session
}
public function generateJwtAtLogin(): void {
// Generate JWT upon user login
}
public function generateAuthHeader(): AuthHeader {
// Generate and return an AuthHeader object
}
public function removeJwt(): void {
// Remove JWT token
}
}
use Rdelbem\Routepress\Routepress;
$auth = new MyAuth();
$routepress = new Routepress($auth, 'myplugin/v1');`
$routepress->create('POST', '/submit', function ($request) {
$data = $request->get_params();
// Process the data
return ['status' => 'success'];
}, true);
$routepress->create(['GET', 'POST'], '/data', function ($request) {
if ($request->get_method() === 'GET') {
return ['data' => 'Some data'];
} else {
// Handle POST request
}
});
bash
docker compose exec php vendor/bin/psalm
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.