Function
Admin notification center functions
On this page
- rpress_register_admin_notice()
- rpress_admin_notice_registry()
- rpress_admin_notice_meta_key()
- rpress_get_admin_notices()
- rpress_admin_problem_count()
- rpress_admin_notices_enabled()
- rpress_admin_toast()
- rpress_admin_notices_register_core()
- rpress_dismiss_admin_notice()
- rpress_admin_notices_ajax_dismiss()
- rpress_admin_notices_admin_bar()
- rpress_admin_notice_html()
- rpress_admin_notices_footer()
- rpress_admin_notice_on_screen()
- rpress_admin_notices_banner()
- rpress_admin_notices_menu_count()
- rpress_admin_notices_dashboard_card()
- rpress_admin_notices_assets()
- rpress_admin_register_notify_script()
- rpress_admin_action_messages()
- rpress_admin_toasts_from_request()
- rpress_admin_notice_return_url()
- rpress_w3tc_session_problem()
- rpress_admin_removable_query_args()
Functions for the admin notices and the Dashboard suggestion card, added in RestroPress 3.5.1.
24 functions. Each entry shows the signature, parameters, return value and where it is defined. Functions marked internal are hook callbacks, screen renderers and other plumbing that extensions normally do not call.
rpress_register_admin_notice()#
Registers a suggestion or problem in the admin notification center.
Call it on the rpress_register_admin_notices action. Optional $args keys are kind (suggestion or problem), title, message, actions (each with label, url, primary, external), capability (default manage_shop_settings), condition, dismissible (default true for suggestions only), dismiss, screens (page slugs or screen IDs for a problem banner, * for all) and priority (default 10, lower first). Registering an existing ID replaces it.
rpress_register_admin_notice( $id, $args )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$id | string | Required | Unique notice ID, passed through sanitize_key(). An empty result is ignored. |
$args | array | Required | Notice settings. |
Example
add_action( 'rpress_register_admin_notices', function () {
rpress_register_admin_notice(
'myplugin_missing_key',
array(
'kind' => 'problem',
'title' => 'API key missing',
'message' => 'Add an API key to finish the setup.',
'actions' => array(
array( 'label' => 'Open settings', 'url' => admin_url( 'admin.php?page=rpress-settings' ), 'primary' => true ),
),
'condition' => function () {
return '' === (string) get_option( 'myplugin_api_key', '' );
},
'screens' => array( 'rpress-dashboard' ),
)
);
} );
Note: Title, message and action labels are shown as plain text. With a custom dismiss callback, the condition callback must also hide the notice once dismissed.
Defined in includes/features/admin-notices/loader.php, line 48.
rpress_admin_notice_registry()#
Returns all registered admin notices, keyed by ID.
Fires the rpress_register_admin_notices action first if it has not run in this request. The list is not filtered by capability, condition or dismissal.
rpress_admin_notice_registry()
Returns array: Notice definitions keyed by ID.
Internal. Defined in includes/features/admin-notices/loader.php, line 81.
rpress_admin_notice_meta_key()#
Returns the user meta key that stores the dismissal of a notice.
Used for notices that have no dismiss callback of their own.
rpress_admin_notice_meta_key( $id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$id | string | Required | Notice ID. |
Returns string: _rpress_notice_{id}_dismissed.
Internal. Defined in includes/features/admin-notices/loader.php, line 94.
rpress_get_admin_notices()#
Returns the admin notices that currently apply to the logged-in user.
Applies each notice's capability, condition and stored dismissal, then lists problems before suggestions, each ordered by priority. The result passes through the rpress_admin_notices filter and is cached for the request until a notice is registered or dismissed.
rpress_get_admin_notices()
Returns array: List of notice definitions.
Example
foreach ( rpress_get_admin_notices() as $notice ) {
error_log( $notice['kind'] . ': ' . $notice['title'] );
}
Note: The first call fires rpress_register_admin_notices, so add your callback to that action before then.
Defined in includes/features/admin-notices/loader.php, line 104.
rpress_admin_problem_count()#
Returns the number of problem notices for the current user.
rpress_admin_problem_count()
Returns int: Number of notices of kind problem.
Defined in includes/features/admin-notices/loader.php, line 141.
rpress_admin_notices_enabled()#
Checks whether the notification bell is available to the current user.
Requires an admin request, a logged-in user and the manage_shop_settings capability, which can be changed with the rpress_admin_notices_capability filter.
rpress_admin_notices_enabled()
Returns bool: True when the bell should be shown.
Internal. Defined in includes/features/admin-notices/loader.php, line 157.
rpress_admin_toast()#
Queues a confirmation toast for the current admin page.
HTML tags are removed from the message, and an empty message is ignored. Queued toasts are printed on admin_footer at priority 5.
rpress_admin_toast( $message, $type = 'success' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$message | string | Required | Plain text message. |
$type | string | 'success' | success, info or error. Other values become success. |
Example
add_action( 'admin_head', function () {
if ( isset( $_GET['myplugin_saved'] ) && current_user_can( 'manage_shop_settings' ) ) {
rpress_admin_toast( 'Settings saved.' );
}
} );
Note: The queue is not kept across requests. Call it before the footer of the same page; a toast queued before a redirect or during an AJAX request is not shown.
Defined in includes/features/admin-notices/loader.php, line 169.
rpress_admin_notices_register_core()#
Registers the core RestroPress admin notices.
Hooked to rpress_register_admin_notices at priority 5. It registers problems for a missing menu items page, a missing checkout page and test mode, plus a licence key problem when rp_addon_licence_problem() is available.
rpress_admin_notices_register_core()
Internal. Defined in includes/features/admin-notices/loader.php, line 187.
rpress_dismiss_admin_notice()#
Dismisses an admin notice for the current user.
Uses the notice's dismiss callback when it has one, otherwise saves the time in user meta. The notice must be dismissible and the user must have its capability.
rpress_dismiss_admin_notice( $id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$id | string | Required | Notice ID. |
Returns bool: True when the dismissal was handled, false for an unknown or non-dismissible notice or a missing capability.
Example
$dismissed = rpress_dismiss_admin_notice( 'myplugin_welcome' );
Defined in includes/features/admin-notices/loader.php, line 278.
rpress_admin_notices_ajax_dismiss()#
Handles the AJAX request that dismisses an admin notice.
Handles wp_ajax_rpress_dismiss_admin_notice after a nonce check. On success it returns the remaining notice count and problem count.
rpress_admin_notices_ajax_dismiss()
Note: Sends a JSON response and ends the request.
Internal. Defined in includes/features/admin-notices/loader.php, line 300.
rpress_admin_notices_admin_bar()#
Adds the notification bell with its count to the admin bar.
Hooked to admin_bar_menu at priority 85. It does nothing when rpress_admin_notices_enabled() is false.
rpress_admin_notices_admin_bar( $bar )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$bar | WP_Admin_Bar | Required | Admin bar instance. |
Internal. Defined in includes/features/admin-notices/loader.php, line 325.
rpress_admin_notice_html()#
Returns the HTML for one admin notice.
The same markup serves the panel, the banner and the Dashboard card. It includes the action links and, for dismissible notices, a dismiss button.
rpress_admin_notice_html( $notice, $context = 'panel' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$notice | array | Required | Notice definition. |
$context | string | 'panel' | panel, banner or card. The banner leaves out the "Needs attention" tag. |
Returns string: Escaped HTML.
Internal. Defined in includes/features/admin-notices/loader.php, line 359.
rpress_admin_notices_footer()#
Outputs the notification panel and the queued toasts in the admin footer.
Hooked to admin_footer at priority 5. The hidden panel is printed only when the bell is available; queued toasts are printed as a JSON script block.
rpress_admin_notices_footer()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/admin-notices/loader.php, line 391.
rpress_admin_notice_on_screen()#
Checks whether a notice's banner belongs on the current admin screen.
Matches the notice's screens list against the page query argument or the current screen ID. A * entry matches every screen.
rpress_admin_notice_on_screen( $notice )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$notice | array | Required | Notice definition with a screens key. |
Returns bool: True when the banner should show here.
Internal. Defined in includes/features/admin-notices/loader.php, line 417.
rpress_admin_notices_banner()#
Outputs a banner for the first problem notice that belongs on the current screen.
Hooked to admin_notices at priority 5. At most one banner is printed by this function.
rpress_admin_notices_banner()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/admin-notices/loader.php, line 431.
rpress_admin_notices_menu_count()#
Adds the problem count badge to the RestroPress admin menu item.
Hooked to admin_menu at priority 999. It changes the global $menu only when the user can see the bell and has at least one problem.
rpress_admin_notices_menu_count()
Internal. Defined in includes/features/admin-notices/loader.php, line 444.
rpress_admin_notices_dashboard_card()#
Outputs the first applicable suggestion as a card on the RestroPress Dashboard.
Hooked to rpress_command_center_before_panels. Suggestions are ordered by priority.
rpress_admin_notices_dashboard_card()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/admin-notices/loader.php, line 467.
rpress_admin_notices_assets()#
Enqueues the message bar and notification panel assets on admin screens.
Hooked to admin_enqueue_scripts at priority 20. It also passes the AJAX URL, a nonce and interface strings to the panel script.
rpress_admin_notices_assets()
Internal. Defined in includes/features/admin-notices/loader.php, line 488.
rpress_admin_register_notify_script()#
Re-registers the jquery-tata-toast script handle to load the RestroPress message bar.
Hooked to admin_enqueue_scripts at priority 11. It deregisters any existing script with that handle, registers rp-notify.js and localizes its strings. It does not enqueue the script.
rpress_admin_register_notify_script()
Internal. Defined in includes/features/admin-notices/loader.php, line 522.
rpress_admin_action_messages()#
Returns the toast messages for rpress-message result values.
Each entry is an array of required capability, toast type and text. Add or change entries with the rpress_admin_action_messages filter.
rpress_admin_action_messages()
Returns array: Message entries keyed by rpress-message value.
Internal. Defined in includes/features/admin-notices/messages.php, line 21.
rpress_admin_toasts_from_request()#
Queues toasts based on result parameters in the current admin URL.
Hooked to admin_head. It handles rpress-message (checked against the capability of the message), rpress_reorder_enabled, rpress_order_alerts_enabled and the reservation bulk update parameters.
rpress_admin_toasts_from_request()
Internal. Defined in includes/features/admin-notices/messages.php, line 62.
rpress_admin_notice_return_url()#
Returns the admin page to go back to after acting on a notice.
Uses the referring URL when it is inside the site's admin, with the rpress-message, rpress_reorder_enabled and rpress_order_alerts_enabled arguments removed.
rpress_admin_notice_return_url( $fallback )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$fallback | string | Required | URL to use when there is no admin referrer. |
Returns string: Referrer or fallback URL.
Example
// Inside your own handler, after checking the nonce and capability.
wp_safe_redirect( rpress_admin_notice_return_url( admin_url( 'admin.php?page=rpress-settings' ) ) );
exit;
Defined in includes/features/admin-notices/messages.php, line 106.
rpress_w3tc_session_problem()#
Checks whether W3 Total Cache database caching is missing the _wp_session_ exclusion.
rpress_w3tc_session_problem()
Returns bool: True when database caching is enabled and _wp_session_ is not in the ignored query stems; false otherwise or when W3 Total Cache is not detected.
Internal. Defined in includes/features/admin-notices/messages.php, line 119.
rpress_admin_removable_query_args()#
Adds the RestroPress result parameters to WordPress's removable query arguments.
Callback for the removable_query_args filter. It stops a page refresh from repeating a toast.
rpress_admin_removable_query_args( $args )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$args | array | Required | Removable query argument names. |
Returns array: The list with the RestroPress parameters appended.
Internal. Defined in includes/features/admin-notices/messages.php, line 155.
