Skip to content

Instantly share code, notes, and snippets.

@tloudon
Created October 6, 2015 22:40
Show Gist options
  • Save tloudon/57365bf58c4eefdc3741 to your computer and use it in GitHub Desktop.
Save tloudon/57365bf58c4eefdc3741 to your computer and use it in GitHub Desktop.
example api check
$api_check = FALSE;
$headers = getallheaders();
foreach($headers as $key => $value) {
if (stripos($key, 'X-API') !== FALSE) {
$api_check = TRUE;
}
}
// you get the idea ^
// so contrib modules can get patches to opt-out of expensive hook_init/hook_boot or whatever rendering
// needs that may be horribly expensive and unnecessary for an API call
// eg
// some_awesome_module_init() {
// if (i_can_has_api()) {
// return;
// }
// // beautiful, world-changing code that sadly does not help w/ teh JSONs...
// }
@mikeytown2
Copy link

hook_page_build/hook_page_alter is where a lot of hook_init code should go. I use this inside the advagg font module http://cgit.drupalcode.org/advagg/tree/advagg_font/advagg_font.module#n23

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