Skip to content

Instantly share code, notes, and snippets.

@ericmann
Last active December 19, 2015 11:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericmann/5949377 to your computer and use it in GitHub Desktop.
Save ericmann/5949377 to your computer and use it in GitHub Desktop.
Pseudo-singleton for WordPress.
<?php
class Example {
public function __construct() {
$this->instantiate();
}
public function instantiate() {
static $instance = null;
if ( null === $instance ) {
add_filter( 'example_instance', array( $this, 'instantiate' ) );
$instance = $this;
}
return $instance;
}
public function do_something_useful() {
}
protected function do_something_in_secret() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment