wp-go/internal/theme/hook.go

25 lines
508 B
Go
Raw Normal View History

2023-01-18 15:04:12 +00:00
package theme
import (
2023-02-09 09:12:33 +00:00
"github.com/fthvgb1/wp-go/internal/theme/twentyfifteen"
2023-03-01 05:17:12 +00:00
"github.com/fthvgb1/wp-go/internal/theme/wp"
2023-01-18 15:04:12 +00:00
)
2023-03-01 05:17:12 +00:00
var themeMap = map[string]func(*wp.Handle){}
2023-01-18 15:04:12 +00:00
2023-03-01 05:17:12 +00:00
func addThemeHookFunc(name string, fn func(handle *wp.Handle)) {
2023-01-18 15:04:12 +00:00
if _, ok := themeMap[name]; ok {
panic("exists same name theme")
}
themeMap[name] = fn
}
2023-03-01 05:17:12 +00:00
func Hook(themeName string, handle *wp.Handle) {
2023-01-18 15:04:12 +00:00
fn, ok := themeMap[themeName]
if ok && fn != nil {
fn(handle)
2023-01-18 15:04:12 +00:00
return
}
2023-02-09 09:12:33 +00:00
themeMap[twentyfifteen.ThemeName](handle)
2023-01-18 15:04:12 +00:00
}