From 41fc3fd9b0a369821e2c50e5f394253868594867 Mon Sep 17 00:00:00 2001 From: Dom Waterson Date: Mon, 5 Aug 2024 11:44:56 +0100 Subject: [PATCH] chore: updated readme --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/README.md b/README.md index 6303636..05ef47a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Site Settings +Plugin to create global site settings. Using supported components from the wordpress component library. + +Settings are split into three categories: general, analytics and styles. + +Using the floating action button at the bottom left you can configure your own setting for the category. + ## Local Development or Manual Install Clone the repository into your `plugins` or `client-mu-plugins` directory. ``` @@ -25,3 +31,47 @@ Dev watch mode ``` npm run watch:dev ``` + +## Setting storage + +Settings are stored in the `wp_options` table. This plugin uses backbone.js in `admin/services/settingServices` to fetch and save settings. + +The setting are stored as JSON with the following structure: + +```json +{ + : [ + { + id: + field: + value: + attributes: + } + ] +} +``` + +We currently support three categories (General, Analytics and Styles) as definded in `admin/schema/supportedCategories` + +## Settings validation + +When reading settings from db or about to save setting we validate using `admin/schema/settingSchema`. If this validation fails a notice will be displayed on top of the main settings view. + + +## Add new supported field + +1. Add to `admin/fields/supported-fields` Following this structure: +```js +: { + Component: , + keyProp: , + label: + attributes: +} +``` +2. Check for new field in `admin/components/FieldConfigurator` and add your own custom field configurator to handle creating new field. +3. Just handle updating the props, when saving (submitting form) it will get passed `admin/schema/formatSetting` and then passed to the provider which will validate the settings before saving to db. +4. Update the `getSettingValue` in `admin/schema/formatSetting` function for new field +5. Settings stored in db get fetched on mount `admin/components/SettingsContainer` make sure the new field can be read and updated here. + +