Skip to content

Instantly share code, notes, and snippets.

@techjewel
Created September 10, 2019 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techjewel/10125dee85730817326cd5b50d9f9ba3 to your computer and use it in GitHub Desktop.
Save techjewel/10125dee85730817326cd5b50d9f9ba3 to your computer and use it in GitHub Desktop.
<?php
/*
* Code snippet to expose ninja tables data as JSON via URL
* Example URL: https://yourdomain.com/?get_ninja_table_data=1463&key=your_security_key
* In this url 1463 is the table ID that you want to access the data using JSON
* You should change the key 'your_security_key' in the url as well in the code
* to protect the endpoint
*/
add_action('init', function() {
if(isset($_GET['get_ninja_table_data'])) {
$securityKey = 'your_security_key';
$key = $_GET['key'];
if($key != $securityKey) {
exit('key mismatch');
}
$tableId = intval($_GET['get_ninja_table_data']);
$data = ninjaTablesGetTablesDataByID($tableId);
wp_send_json($data);
}
});
@codearachnid
Copy link

Thank you for showing this option - I have modernized this concept to leverage the built in REST api features of WordPress at https://gist.github.com/codearachnid/9a083f2e6dd018f3643df7622437f2a6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment