Created
April 24, 2015 21:59
-
-
Save ryanlund/e644b10a9e50ae7b03e6 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
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