Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created April 26, 2017 17:56
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 tommcfarlin/e27db4b35ff6ed7fba3b506dccb8ad2d to your computer and use it in GitHub Desktop.
Save tommcfarlin/e27db4b35ff6ed7fba3b506dccb8ad2d to your computer and use it in GitHub Desktop.
[WordPress] Singletons in WordPress, Revisited
<?php
class Date_Formatter {
public static function get() {
$default_format = 'm/d/Y';
$format = get_option( 'yhd_directory_importer', false );
if ( false === $format ) {
return $default_format;
}
$format = $format['date'];
$format =
( isset( $format ) && isset( $format['format'] ) ) ?
$format['format'] :
$default_format;
return $format;
}
}
<?php
class Date_Formatter {
private static $instance;
private function __construct() {
}
private static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
public static function get() {
self::get_instance();
$default_format = 'm/d/Y';
$format = get_option( 'yhd_directory_importer', false );
if ( false === $format ) {
return $default_format;
}
$format = $format['date'];
$format =
( isset( $format ) && isset( $format['format'] ) ) ?
$format['format'] :
$default_format;
return $format;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment