Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

How to exclude a page that prints json

$
0
0

Replies: 0

Hi I’m having trouble excluding a page from the cache enabler on a site that uses keycdn.

Basically I have an object oriented wordpress plugin that has a rewrite rule setup so that anytime someone uses a certain endpoint, it would bypass the normal wordpress template and simply print out json depending on the different get requests that get sent out.

So the flow looks like this:

public function register_query_vars($vars)
{
*other vars being registered*
$vars[] = ‘get_cache’;
return $vars;
}
add_rewrite_rule(
‘pm/cache/([^/]*)/?$’,
‘index.php?get_cache=$matches[1]’,
‘top’
);

$this->loader->add_filter(‘template_include’, $this->modules[‘pm_redis’], ‘getCacheEndpoint’);

public static function getCacheEndpoint($template)
{
if (!defined(‘DONOTCACHEPAGE’)) {
define( ‘DONOTCACHEPAGE’, true );
}
$type = get_query_var(‘get_cache’, null);

if ($type) {
$template = *path to page that prints out json*
}

return $template;
}

so basically at the ‘template_include’ hook it triggers the getCacheEndpoint function which checks to see if someone is using a “get_cache” endpoint and if so it would include a php page that prints out json. However instead of just json being printed out it also prints out an html comment “<!– Cache Enabler by KeyCDN @ 17.04.2018 22:10:18 (html gzip) –>” and I would like to get rid of that.

Do I have to define DONOTCACHEPAGE in the actual template itself (referred in here as *path to page that prints out json*)? Or is there a different filter I should be using? I’ve seen posts talk about using the bypass_cache hook but that hasn’t helped either.


Viewing all articles
Browse latest Browse all 59525

Trending Articles