Notices Data Edit

Namespace: core/notices.

Selectors

Top ↑

getNotices

Returns all notices as an array, optionally for a given context. Defaults to
the global context.

Usage

// This example retrieves all notices and displays their messages in a unordered list.

const ExampleComponent = () => {
    const notices = useSelect( ( select ) =>
        select( 'core/notices' ).getNotices()
    );
    return (
        <ul>
            { notices.map( ( notice ) => (
                <li key={ notice.ID }>{ notice.content }</li>
            ) ) }
        </ul>
    );
};

Parameters

  • state Object: Notices state.
  • context ?string: Optional grouping context.

Returns

  • WPNotice[]: Array of notices.

Top ↑

Actions

Top ↑

createErrorNotice

Returns an action object used in signalling that an error notice is to be
created. Refer to createNotice for options documentation.

Related

  • createNotice

Parameters

  • content string: Notice message.
  • options [Object]: Optional notice options.

Returns

  • Object: Action object.

Top ↑

createInfoNotice

Returns an action object used in signalling that an info notice is to be
created. Refer to createNotice for options documentation.

Related

  • createNotice

Parameters

  • content string: Notice message.
  • options [Object]: Optional notice options.

Returns

  • Object: Action object.

Top ↑

createNotice

Returns an action object used in signalling that a notice is to be created.

Parameters

  • status [string]: Notice status.
  • content string: Notice message.
  • options [Object]: Notice options.
  • options.context [string]: Context under which to group notice.
  • options.id [string]: Identifier for notice. Automatically assigned if not specified.
  • options.isDismissible [boolean]: Whether the notice can be dismissed by user.
  • options.type [string]: Type of notice, one of default, or snackbar.
  • options.speak [boolean]: Whether the notice content should be announced to screen readers.
  • options.actions [Array<WPNoticeAction>]: User actions to be presented with notice.
  • options.icon [Object]: An icon displayed with the notice.
  • options.explicitDismiss [boolean]: Whether the notice includes an explict dismiss button and can’t be dismissed by clicking the body of the notice.
  • options.onDismiss [Function]: Called when the notice is dismissed.

Returns

  • Object: Action object.

Top ↑

createSuccessNotice

Returns an action object used in signalling that a success notice is to be
created. Refer to createNotice for options documentation.

Related

  • createNotice

Parameters

  • content string: Notice message.
  • options [Object]: Optional notice options.

Returns

  • Object: Action object.

Top ↑

createWarningNotice

Returns an action object used in signalling that a warning notice is to be
created. Refer to createNotice for options documentation.

Related

  • createNotice

Parameters

  • content string: Notice message.
  • options [Object]: Optional notice options.

Returns

  • Object: Action object.

Top ↑

removeNotice

Returns an action object used in signalling that a notice is to be removed.

Parameters

  • id string: Notice unique identifier.
  • context [string]: Optional context (grouping) in which the notice is intended to appear. Defaults to default context.

Returns

  • Object: Action object.