Skip to content
Docs
Get RestroPress

Action

rpress_register_admin_notices

Updated
On this page

Fires when admin notices should be registered with the notification center.

Fired the first time the notice registry is read in a request. Call rpress_register_admin_notice( $id, $args ) from your callback to add a suggestion or a problem. Core registers its own problems on this action (some at priority 5, the W3 Total Cache one at the default priority). Use the condition argument to control whether a notice currently applies.

Available since RestroPress 3.5.1.

Example#

add_action( 'rpress_register_admin_notices', 'my_register_notice', 10, 0 );
function my_register_notice() {
	rpress_register_admin_notice(
		'my_missing_api_key',
		array(
			'kind'      => 'problem',
			'title'     => __( 'API key missing', 'my-plugin' ),
			'message'   => __( 'Add your API key to keep syncing orders.', 'my-plugin' ),
			'actions'   => array(
				array(
					'label'   => __( 'Open settings', 'my-plugin' ),
					'url'     => admin_url( 'admin.php?page=rpress-settings' ),
					'primary' => true,
				),
			),
			'condition' => 'my_api_key_is_missing',
			'screens'   => array( 'rpress-dashboard' ),
		)
	);
}
function my_api_key_is_missing() {
	return '' === get_option( 'my_api_key', '' );
}

Notes#

Add your callback before the registry is first read; hooking it when your plugin loads is enough.

Source#

Fired from:

  • includes/features/admin-notices/loader.php (line 83), in rpress_admin_notice_registry()

See also#

Was this page helpful?