2023-01-18 15:04:12 +00:00
|
|
|
package theme
|
|
|
|
|
|
|
|
import (
|
2023-05-04 12:37:06 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/theme/wp"
|
2024-01-22 12:29:17 +00:00
|
|
|
str "github.com/fthvgb1/wp-go/helper/strings"
|
2023-05-04 13:44:17 +00:00
|
|
|
"github.com/fthvgb1/wp-go/safety"
|
2023-01-18 15:04:12 +00:00
|
|
|
)
|
|
|
|
|
2023-05-04 13:44:17 +00:00
|
|
|
var themeMap = safety.NewMap[string, func(*wp.Handle)]()
|
2023-01-18 15:04:12 +00:00
|
|
|
|
2024-08-31 12:01:52 +00:00
|
|
|
func AddTheme(name string, fn func(handle *wp.Handle)) {
|
2023-05-04 13:44:17 +00:00
|
|
|
themeMap.Store(name, fn)
|
2023-01-18 15:04:12 +00:00
|
|
|
}
|
|
|
|
|
2024-08-31 12:01:52 +00:00
|
|
|
func DelTheme(name string) {
|
|
|
|
themeMap.Delete(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetTheme(name string) (func(*wp.Handle), bool) {
|
|
|
|
return themeMap.Load(name)
|
|
|
|
}
|
|
|
|
|
2024-01-22 12:29:17 +00:00
|
|
|
func IsThemeHookFuncExist(name string) bool {
|
|
|
|
_, ok := themeMap.Load(name)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2023-05-04 13:44:17 +00:00
|
|
|
func Hook(themeName string, h *wp.Handle) {
|
|
|
|
fn, ok := themeMap.Load(themeName)
|
2023-01-18 15:04:12 +00:00
|
|
|
if ok && fn != nil {
|
2023-05-04 13:44:17 +00:00
|
|
|
fn(h)
|
2023-01-18 15:04:12 +00:00
|
|
|
return
|
|
|
|
}
|
2024-01-22 12:29:17 +00:00
|
|
|
panic(str.Join("theme ", themeName, " don't exist"))
|
2023-01-18 15:04:12 +00:00
|
|
|
}
|