Created
December 18, 2011 05:29
-
-
Save RalfAlbert/1492465 to your computer and use it in GitHub Desktop.
Selector with classes
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
<?php | |
/* Plugin Name Some Code */ | |
class PluginInit | |
{ | |
/** | |
* mocking code | |
*/ | |
CONST WP_VERSION = '3.3'; | |
private function get_wp_version(){ return '3.3' ; } | |
private function get_wp_network() { return false; } | |
/*// end mocking code */ | |
private $_classname = ''; | |
public function __construct(){ | |
// check versions | |
$_wp_version = (int) version_compare( self::WP_VERSION, $this->get_wp_version(), '>=' ); | |
$_network = (int) $this->get_wp_network(); | |
$resources = new stdClass(); | |
$resources->wp = array( 'wp30', 'wp33' ); | |
$resources->network = array( 'nonetwork', 'network' ); | |
$this->_classname = $resources->wp[$_wp_version] . $resources->network[$_network]; | |
$this->do_something(); | |
} | |
private function do_something(){ | |
$class = &$this->_classname; | |
$c = new $class; | |
$c->test(); | |
$c::test2(); | |
} | |
} | |
new PluginInit(); | |
class wp33nonetwork | |
{ | |
public $classname = __CLASS__; | |
public function __construct(){ | |
echo 'WordPress Version größer-gleich 3.3, kein Netzwerk<br />'; | |
} | |
public static function test(){ | |
printf( "Wir sind in der Klasse <strong>%s</strong><br />", __CLASS__ ); | |
} | |
public function test2(){ | |
printf( "Dies ist die Methode <strong>%s</strong><br />", __METHOD__ ); | |
} | |
} | |
class wp33network {} | |
class wp30nonetwork {} | |
class wp30network {} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment