Created
September 10, 2019 06:30
-
-
Save techjewel/10125dee85730817326cd5b50d9f9ba3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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