Skip to content

Instantly share code, notes, and snippets.

@Sean-Spallen
Created November 19, 2019 23:00
Show Gist options
  • Save Sean-Spallen/8cb9e6ef1743169f6d27d591a2acfae5 to your computer and use it in GitHub Desktop.
Save Sean-Spallen/8cb9e6ef1743169f6d27d591a2acfae5 to your computer and use it in GitHub Desktop.
Wordpress Rest API
<?php
/**
* Template Name: Custom API Endpoint
# Updating views and storage
https://example.com/custom-api/?views=9435345&storage=2334242&site_id=2394&token=token_key
*/
// Capture query string as variables
$token = $_GET['token'];
$storage = $_GET['storage'];
$views = $_GET['views'];
$site_id = $_GET['site_id'];
// Define a random token to valid request. No symbols.
$token_key = "RANDOM_TOKEN_KEY_HERE";
// Verifies valid token
if ( $token == $token_key ) {
// Run custom code here
if ($views and $storage) {
update_field("field_57e0b2b17eb2a", $storage, $site_id);
update_field("field_57e0b2c07eb2b", $views, $site_id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment