Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/hackingwp/wp-access-token-api/archive/refs/heads/master.zipNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
Simple access tokens using WordPress transients.
Installation
- Download zip and upload to your
wp-content/pluginsor install viawp-adminPlugins interface; - Activate
Docs
Each generated $token:
- is tied to a specific
$actionfor which it is requested for; - can have specified time-to-live (
$ttl), where0means it never expires; - can be used just specified number of times (
$retries), while0retries means unlimited times to use token.
Requesting a new token
$tokenAPI = WP_AccessTokenAPI::getInstance();
$action = 'post:123:delete'; // Action you want later to test against
$ttl = 5; // minutes
$retries = 2; // can be triggered max 2x
try {
$token = $tokenAPI->set($action, $ttl, $retries);
} catch (Exception $e) {
// Handle error
}
// Use token, e.g: send token to user by mail...
Validating token
$tokenAPI = WP_AccessTokenAPI::getInstance();
if (isset($_GET['token']) && strlen(trim($_GET['token'])) > 0 && isset($_GET['action']) && $_GET['action'] === 'post:123:delete') {
$authenticated = false;
$action = $_GET['action'];
$token = $_GET['token'];
try {
$authenticated = $tokenAPI->validate($action, $token);
} catch (Exception $e) {
// Handle error
}
if ($authenticated) {
// Delete post...
}
}
Removing token
try {
$removed = $tokenAPI->remove($action, $token);
} catch (Exception $e) {
// Handle error
}
Enjoy!