better singleton instance

This commit is contained in:
2025-05-07 20:26:08 -07:00
parent a9aca43246
commit 60a0472e53
3 changed files with 17 additions and 11 deletions

View File

@@ -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) {