Skip to content

Instantly share code, notes, and snippets.

@hendratno64
Forked from atwellpub/example-hook.php
Last active August 29, 2015 14:13
Show Gist options
  • Save hendratno64/7da2700a24d3d73d4678 to your computer and use it in GitHub Desktop.
Save hendratno64/7da2700a24d3d73d4678 to your computer and use it in GitHub Desktop.
<?php
/* place in theme's functions.php file */
/* disable json api if api key not correct */
add_action('init','json_api_apikey_check' , 1 );
function json_api_apikey_check()
{
$api_key = 'hello';
$base = get_option('json_api_base', 'api');
$this_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if ( ( isset($_REQUEST['json'] ) || strstr($this_url , $base.'/') ) && ( !isset($_REQUEST['apikey']) || $_REQUEST['apikey'] != $api_key ) )
{
print "[error:99] Permission denied!";
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment