streams/Code/Extend/Widget.php

53 lines
1 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Extend;
2021-12-02 23:02:31 +00:00
class Widget
{
2022-08-21 07:36:09 +00:00
public static function register($file, $widget): void
2021-12-02 23:02:31 +00:00
{
$rt = self::get();
$rt[] = [$file, $widget];
self::set($rt);
}
2022-08-21 07:36:09 +00:00
public static function unregister($file, $widget): void
2021-12-02 23:02:31 +00:00
{
$rt = self::get();
if ($rt) {
$n = [];
foreach ($rt as $r) {
if ($r[0] !== $file && $r[1] !== $widget) {
$n[] = $r;
}
}
self::set($n);
}
}
2022-08-21 07:36:09 +00:00
public static function unregister_by_file($file): void
2021-12-02 23:02:31 +00:00
{
$rt = self::get();
if ($rt) {
$n = [];
foreach ($rt as $r) {
if ($r[0] !== $file) {
$n[] = $r;
}
}
self::set($n);
}
}
public static function get()
{
return get_config('system', 'widgets', []);
}
public static function set($r)
{
return set_config('system', 'widgets', $r);
}
}