better singleton instance
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
return [
|
||||
"debug" => true,
|
||||
"flex-file-prefix" => "flex",
|
||||
"excerpt-more-text" => "…",
|
||||
|
||||
/**
|
||||
* excerpt-length
|
||||
@@ -75,8 +76,6 @@ return [
|
||||
"menus",
|
||||
],
|
||||
|
||||
"excerpt_more_text" => "…",
|
||||
|
||||
/**
|
||||
* disable
|
||||
*
|
||||
|
||||
@@ -5,12 +5,7 @@ require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use ofc\Site;
|
||||
|
||||
# Declare a new Site object
|
||||
$site = new Site();
|
||||
|
||||
# Allow the Site object to be accessed in other files
|
||||
function site(): Site
|
||||
{
|
||||
global $site;
|
||||
return $site;
|
||||
return Site::getInstance();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,18 @@ class Site
|
||||
private $templateDirectory;
|
||||
public $cptSlugs = [];
|
||||
|
||||
public function __construct($config = [])
|
||||
// singleton instance goes here
|
||||
private static ?Site $instance = null;
|
||||
|
||||
public static function getInstance(): Site
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct($config = [])
|
||||
{
|
||||
if ($config == [] && file_exists(TEMPLATEPATH . "/config.php")) {
|
||||
$config = include(TEMPLATEPATH . "/config.php");
|
||||
@@ -34,8 +45,8 @@ class Site
|
||||
wp_dequeue_style('classic-theme-styles');
|
||||
}, 20);
|
||||
|
||||
if (isset($this->config["excerpt_more_text"])) {
|
||||
add_filter('excerpt_more', fn ($more) => $this->config["excerpt_more_text"]);
|
||||
if (isset($this->config["excerpt-more-text"])) {
|
||||
add_filter('excerpt_more', fn ($more) => $this->config["excerpt-more-text"]);
|
||||
}
|
||||
|
||||
// disable various things
|
||||
@@ -601,6 +612,7 @@ class Site
|
||||
"flex" => \ofc\RadThemeEngine::processFlex(),
|
||||
"nl2br" => \ofc\RadThemeEngine::nl2br(),
|
||||
"assetURL" => \ofc\RadThemeEngine::assetURL(),
|
||||
"assetUrl" => \ofc\RadThemeEngine::assetURL(),
|
||||
"assetContents" => \ofc\RadThemeEngine::assetContents(),
|
||||
];
|
||||
foreach ($helpers as $name => $callback) {
|
||||
|
||||
Reference in New Issue
Block a user