PHPackages                             arraypress/wp-register-notices - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. arraypress/wp-register-notices

ActiveLibrary

arraypress/wp-register-notices
==============================

A declarative WordPress admin notices system with automatic GET parameter handling, conditional display, and dismissible notices

49PHP

Since Nov 23Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/arraypress/wp-register-notices)[ Packagist](https://packagist.org/packages/arraypress/wp-register-notices)[ RSS](/packages/arraypress-wp-register-notices/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Admin Notices Registration System
===========================================

[](#wordpress-admin-notices-registration-system)

A declarative, lightweight system for managing WordPress admin notices with automatic GET parameter handling, conditional display, and dismissible notices.

Features
--------

[](#features)

- **Declarative API**: Register all your notices in one place with a clean configuration array
- **Automatic Triggers**: Notices appear based on GET parameters (e.g., `?updated=1`)
- **Dynamic Messages**: Support for callbacks with data interpolation
- **Conditional Display**: Show notices based on conditions (e.g., missing API keys)
- **Dismissible Notices**: Built-in AJAX dismissal with per-user persistence
- **Page Targeting**: Limit notices to specific admin pages with wildcard support
- **Smart Type Detection**: Automatically infers notice type from key naming
- **Capability Checks**: Restrict notices based on user permissions

Installation
------------

[](#installation)

Install via Composer:

```
composer require arraypress/wp-register-notices
```

Basic Usage
-----------

[](#basic-usage)

```
use function ArrayPress\AdminNotices\register_admin_notices;

// Register your notices during plugin initialization
register_admin_notices( 'myplugin', [
    // Simple success messages
    'added'   => __( 'Item added successfully.', 'myplugin' ),
    'updated' => __( 'Item updated successfully.', 'myplugin' ),
    'deleted' => __( 'Item deleted successfully.', 'myplugin' ),
] );

// Trigger by redirecting with the parameter
wp_redirect( admin_url( 'admin.php?page=myplugin&updated=1' ) );
```

Advanced Examples
-----------------

[](#advanced-examples)

### Dynamic Messages with Data

[](#dynamic-messages-with-data)

```
register_admin_notices( 'myplugin', [
    'bulk_deleted' => [
        'message' => function( $args ) {
            $count = absint( $args['count'] ?? 0 );
            return sprintf(
                _n( '%d item deleted.', '%d items deleted.', $count, 'myplugin' ),
                $count
            );
        },
        'type' => 'success',
        'data' => ['count']  // Collect these GET parameters
    ]
] );

// Trigger: ?bulk_deleted=1&count=5
// Shows: "5 items deleted."
```

### Persistent Conditional Notices

[](#persistent-conditional-notices)

```
register_admin_notices( 'myplugin', [
    'api_key_missing' => [
        'condition' => function() {
            return empty( get_option( 'myplugin_api_key' ) );
        },
        'message' => function() {
            $url = admin_url( 'admin.php?page=myplugin-settings' );
            return sprintf(
                __( 'API key required. Configure settings.', 'myplugin' ),
                esc_url( $url )
            );
        },
        'type'        => 'warning',
        'persistent'  => true,        // Shows on every page load
        'dismissible' => false         // Can't be dismissed
    ]
] );
```

### Page-Specific Notices

[](#page-specific-notices)

```
register_admin_notices( 'myplugin', [
    'settings_saved' => __( 'Settings saved successfully.', 'myplugin' ),
    'license_activated' => __( 'License activated.', 'myplugin' ),
], [
    'pages' => ['myplugin-settings', 'myplugin-license'],  // Only these pages
    'capability' => 'manage_options'                        // Admin only
] );
```

### Error Handling

[](#error-handling)

```
register_admin_notices( 'myplugin', [
    'error' => [
        'message' => function( $args ) {
            return esc_html( $args['message'] ?? __( 'An error occurred.', 'myplugin' ) );
        },
        'type' => 'error',
        'data' => ['message']
    ]
] );

// Trigger: ?error=1&message=Invalid+email+address
// Shows: "Invalid email address"
```

### Working with IDs

[](#working-with-ids)

```
register_admin_notices( 'myplugin', [
    'item_updated' => [
        'message' => function( $args ) {
            if ( ! empty( $args['id'] ) ) {
                return sprintf( __( 'Item #%d updated.', 'myplugin' ), $args['id'] );
            }
            return __( 'Item updated.', 'myplugin' );
        },
        'data' => ['id']
    ]
] );

// Trigger: ?item_updated=1&id=123
// Shows: "Item #123 updated."
```

Configuration Options
---------------------

[](#configuration-options)

### Notice Configuration

[](#notice-configuration)

OptionTypeDescriptionDefault`message`string|callableThe notice message or callbackRequired`type`stringNotice type: `success`, `error`, `warning`, `info``success``trigger`stringGET parameter that triggers the noticeKey name`data`arrayGET parameters to pass to message callback`[]``condition`callableFunction to determine if notice should show`null``persistent`boolShows on every page load when condition is met`false``dismissible`boolWhether notice can be dismissed`true``capability`stringRequired capability to see notice`null``pages`array|stringAdmin pages where notice appears (`'all'` for global)`null`### Global Options

[](#global-options)

```
register_admin_notices( 'myplugin', $notices, [
    'pages'       => ['myplugin', 'myplugin-*'],  // Wildcard support
    'capability'  => 'manage_options',
    'dismissible' => true                          // Default for all notices
] );
```

Type Detection
--------------

[](#type-detection)

The system automatically infers notice types from key names:

```
register_admin_notices( 'myplugin', [
    'item_updated'        => 'Updated!',    // success (default)
    'item_deleted_error'  => 'Failed!',     // error (suffix)
    'warning_low_stock'   => 'Low stock',   // warning (prefix)
    'info_new_feature'    => 'New feature'  // info (prefix)
] );
```

Real-World Example
------------------

[](#real-world-example)

```
// In your plugin's main file or admin initialization
add_action( 'admin_init', function() {
    register_admin_notices( 'woocommerce_extras', [
        // Simple CRUD notifications
        'product_added'   => __( 'Product added successfully.', 'wc-extras' ),
        'product_updated' => __( 'Product updated successfully.', 'wc-extras' ),
        'product_deleted' => __( 'Product deleted successfully.', 'wc-extras' ),

        // Bulk operations with counts
        'bulk_updated' => [
            'message' => function( $args ) {
                $count = absint( $args['count'] ?? 0 );
                return sprintf(
                    _n(
                        '%d product updated.',
                        '%d products updated.',
                        $count,
                        'wc-extras'
                    ),
                    $count
                );
            },
            'data' => ['count']
        ],

        // Persistent warnings
        'shipping_not_configured' => [
            'condition' => function() {
                $zones = WC_Shipping_Zones::get_zones();
                return empty( $zones );
            },
            'message' => __( 'No shipping zones configured. Products cannot be shipped.', 'wc-extras' ),
            'type' => 'warning',
            'persistent' => true
        ],

        // Error handling
        'import_failed' => [
            'message' => function( $args ) {
                $error = $args['error'] ?? __( 'Unknown error', 'wc-extras' );
                $line = $args['line'] ?? 0;

                if ( $line > 0 ) {
                    return sprintf(
                        __( 'Import failed at line %d: %s', 'wc-extras' ),
                        $line,
                        esc_html( $error )
                    );
                }

                return sprintf( __( 'Import failed: %s', 'wc-extras' ), esc_html( $error ) );
            },
            'type' => 'error',
            'data' => ['error', 'line']
        ]
    ], [
        'pages' => ['woocommerce', 'edit-product', 'product'],
        'capability' => 'manage_woocommerce'
    ] );
} );

// In your form handler
function handle_product_save() {
    $product_id = save_product( $_POST );

    if ( is_wp_error( $product_id ) ) {
        $url = add_query_arg( [
            'import_failed' => 1,
            'error' => $product_id->get_error_message()
        ], admin_url( 'edit.php?post_type=product' ) );
    } else {
        $url = add_query_arg( [
            'product_updated' => 1,
            'id' => $product_id
        ], admin_url( 'edit.php?post_type=product' ) );
    }

    wp_redirect( $url );
    exit;
}
```

Requirements
------------

[](#requirements)

- PHP 7.4 or later
- WordPress 5.0 or later

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the GPL-2.0-or-later License.

Credits
-------

[](#credits)

Created by [David Sherlock](https://davidsherlock.com) at [ArrayPress](https://arraypress.com).

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance48

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (5 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-register-notices/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-register-notices/health.svg)](https://phpackages.com/packages/arraypress-wp-register-notices)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
