Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
Created December 18, 2011 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RalfAlbert/1492465 to your computer and use it in GitHub Desktop.
Save RalfAlbert/1492465 to your computer and use it in GitHub Desktop.
Selector with classes
<?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