Skip to content

Instantly share code, notes, and snippets.

@mintindeed
Created July 17, 2012 18:44
Show Gist options
  • Save mintindeed/3131216 to your computer and use it in GitHub Desktop.
Save mintindeed/3131216 to your computer and use it in GitHub Desktop.
pmc-abstract
<?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();
}
<?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