Skip to content

Instantly share code, notes, and snippets.

@ryanlund
Created Apr 24, 2015
Embed
What would you like to do?
class ParentTest{
private $log;
public function __construct(){
$this->log=fopen('test.log','a+');
add_action('send_headers',array($this,'testA'));
add_filter('the_content',array($this,'testB'));
add_action('send_headers',array($this,'testC'));
add_filter('the_content',array($this,'testD'));
add_filter('the_content',array($this,'showAll'));
}
public function testA(){
$log_message="---Test A (".get_class($this)." - hook:send_headers)---\n\n".
get_query_var('test','Can\'t retrieve test var')."\n".
get_query_var('error','Can\'t retrieve error var')."\n\n";
fwrite($this->log,$log_message);
}
public function testB($contents){
$log_message="----Test B---(".get_class($this)." - hook:the_content)\n\n".
get_query_var('test','Can\'t retrieve test var')."\n".
get_query_var('error','Can\'t retrieve error var')."\n\n";
fwrite($this->log,$log_message);
}
public function testC(){
$test=(isset($_GET['test']))? $_GET['test']: 'Can\'t retrieve test var';
$error=(isset($_GET['error']))? $_GET['error']: 'Can\'t retrieve error var';
$log_message="---Test C (".get_class($this)." - hook:send_header) ---\n\n".$test."\n".$error."\n\n";
fwrite($this->log,$log_message);
}
public function testD(){
$test=(isset($_GET['test']))? $_GET['test']: 'Can\'t retrieve test var';
$error=(isset($_GET['error']))? $_GET['error']: 'Can\'t retrieve error var';
$log_message="---Test D (".get_class($this)." - hook:the_content)---\n\n".$test."\n".$error."\n\n";
fwrite($this->log,$log_message);
}
public function showAll($contents){
global $wp_query;
$log_message="--- Show All (- hook:the_content)---\n\n".print_r($wp_query->query_vars,1)."\n\n";
fwrite($this->log,$log_message);
}
public function __destruct(){
fclose($this->log);
}
}
class TestClassA extends ParentTest{
public function __construct(){
add_action('init',function() {
global $wp;
$wp->add_query_var('test');
$wp->add_query_var('error');
});
parent::__construct();
}
}
class TestClassB extends ParentTest{
public function __construct(){
add_filter('query_vars',function($vars){
$vars[] = 'test';
$vars[] = 'error';
return $vars;
});
parent::__construct();
}
}
$a=new TestClassA;
$b=new TestClassB;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment