wp-go/app/theme/hook.go

26 lines
530 B
Go
Raw Permalink Normal View History

2023-01-18 15:04:12 +00:00
package theme
import (
2023-05-08 13:43:20 +00:00
"github.com/fthvgb1/wp-go/app/theme/twentyfifteen"
2023-05-04 12:37:06 +00:00
"github.com/fthvgb1/wp-go/app/theme/wp"
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
2023-05-04 13:44:17 +00:00
func AddThemeHookFunc(name string, fn func(handle *wp.Handle)) {
if _, ok := themeMap.Load(name); ok {
2023-01-18 15:04:12 +00:00
panic("exists same name theme")
}
2023-05-04 13:44:17 +00:00
themeMap.Store(name, fn)
2023-01-18 15:04:12 +00:00
}
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
}
2023-05-08 13:43:20 +00:00
twentyfifteen.Hook(h)
2023-01-18 15:04:12 +00:00
}