Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.