Created
July 17, 2012 18:44
-
-
Save mintindeed/3131216 to your computer and use it in GitHub Desktop.
pmc-abstract
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 | |
abstract class PMC_Base { | |
private static $_instance = array(); | |
protected function __construct() {} | |
public static function get_instance() { | |
$class = get_called_class(); | |
if ( ! isset( self::$_instance[$class] ) ) { | |
self::$_instance[$class] = new $class(); | |
self::$_instance[$class]->_init(); | |
} | |
return self::$_instance[$class]; | |
} | |
abstract protected function _init(); | |
} |
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 | |
public static function get_instance( $group = 'general' ) { | |
if ( ! is_a(self::$_instance, __CLASS__) ) { | |
$class_name = __CLASS__; | |
self::$_instance = new $class_name($group); | |
} | |
return self::$_instance; | |
} | |
private function __construct( $group ) { | |
$this->post_name = $group; | |
} | |
public function init(){ | |
global $wpdb; | |
$this->post_id = wp_cache_get( $post_name, 'pmc-long-options' ); | |
if ( ! $this->post_id ) { | |
$this->post_id = $wpdb->query( $wpdb->prepare( | |
"SELECT ID FROM " . $wpdb->posts . " | |
WHERE ... | |
LIMIT 1", $post_type, $post_name | |
) ); | |
} | |
//pre-populate post meta cache | |
get_post_custom( $this->post_id ); | |
} | |
################### | |
function pmc_get_option( $name, $group_name = 'general' ){ | |
$pmc_options = PMC_Options::get_instance( $group_name ); | |
return $pmc_options->get_option( $name ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment