Skip to content

Commit

Permalink
chore: updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-waterson committed Aug 5, 2024
1 parent b4f0d5b commit df99104
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
```
Expand All @@ -25,3 +31,46 @@ 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
{
<category>: [
{
id: <uniqueId>
field: <supportedField>
value: <value to be returned by api>
attributes: <object holding field props that can be spread on component>
}
]
}
```

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
<key>: {
Component: <Custom | Wordpress component>,
keyProp: <Value prop for component>,
label: <Used in select dropdown>
attributes: <Props that can be easily spread on component>
}
```
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. Settings stored in db get fetched on mount `admin/components/SettingsContainer` make sure the new field can be read and updated here.


0 comments on commit df99104

Please sign in to comment.