Preferences

Namespace: core/preferences.

Selectors

get

Returns a boolean indicating whether a prefer is active for a particular scope.

Parameters

  • state Object: The store state.
  • scope string: The scope of the feature (e.g. core/edit-post).
  • name string: The name of the feature.

Returns

  • *: Is the feature enabled?

Actions

set

Returns an action object used in signalling that a preference should be set to a value

Parameters

  • scope string: The preference scope (e.g. core/edit-post).
  • name string: The preference name.
  • value *: The value to set.

Returns

  • Object: Action object.

setDefaults

Returns an action object used in signalling that preference defaults should be set.

Parameters

  • scope string: The preference scope (e.g. core/edit-post).
  • defaults Object<string, *>: A key/value map of preference names to values.

Returns

  • Object: Action object.

setPersistenceLayer

Sets the persistence layer.

When a persistence layer is set, the preferences store will:

  • call get immediately and update the store state to the value returned.
  • call set with all preferences whenever a preference changes value.

setPersistenceLayer should ideally be dispatched at the start of an application’s lifecycle, before any other actions have been dispatched to the preferences store.

Parameters

  • persistenceLayer WPPreferencesPersistenceLayer: The persistence layer.

Returns

  • Object: Action object.

toggle

Returns an action object used in signalling that a preference should be toggled.

Parameters

  • scope string: The preference scope (e.g. core/edit-post).
  • name string: The preference name.