wp-go/internal/wpconfig/options.go

29 lines
643 B
Go
Raw Normal View History

2022-11-17 08:29:39 +00:00
package wpconfig
2022-11-15 03:11:08 +00:00
import (
"context"
2023-01-13 06:04:32 +00:00
"github/fthvgb1/wp-go/internal/pkg/models"
2023-01-12 12:42:16 +00:00
"github/fthvgb1/wp-go/model"
2022-11-15 03:11:08 +00:00
"github/fthvgb1/wp-go/safety"
)
var Options safety.Map[string, string]
func InitOptions() error {
ctx := context.Background()
2023-01-12 12:42:16 +00:00
ops, err := model.SimpleFind[models.Options](ctx, model.SqlBuilder{{"autoload", "yes"}}, "option_name, option_value")
2022-11-15 03:11:08 +00:00
if err != nil {
return err
}
if len(ops) == 0 {
2023-01-12 12:42:16 +00:00
ops, err = model.SimpleFind[models.Options](ctx, nil, "option_name, option_value")
2022-11-15 03:11:08 +00:00
if err != nil {
return err
}
}
for _, options := range ops {
Options.Store(options.OptionName, options.OptionValue)
}
return nil
}