{"id":24247450,"url":"https://github.com/arraypress/wp-register-notices","last_synced_at":"2026-03-01T12:02:40.003Z","repository":{"id":271924135,"uuid":"914053743","full_name":"arraypress/wp-register-notices","owner":"arraypress","description":"A streamlined WordPress admin notices registration system with support for dismissible notices and error handling","archived":false,"fork":false,"pushed_at":"2025-11-22T19:12:57.000Z","size":21,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-22T21:09:24.864Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arraypress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-08T21:24:55.000Z","updated_at":"2025-11-22T19:13:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"37dc4fb8-8ae5-4ec8-bb74-07770aa00cd9","html_url":"https://github.com/arraypress/wp-register-notices","commit_stats":null,"previous_names":["arraypress/wp-register-notices"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arraypress/wp-register-notices","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-register-notices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-register-notices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-register-notices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-register-notices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arraypress","download_url":"https://codeload.github.com/arraypress/wp-register-notices/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-register-notices/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29969243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T11:43:06.159Z","status":"ssl_error","status_checked_at":"2026-03-01T11:43:03.887Z","response_time":124,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-14T23:46:13.715Z","updated_at":"2026-03-01T12:02:39.989Z","avatar_url":"https://github.com/arraypress.png","language":"PHP","readme":"# WordPress Admin Notices Registration System\n\nA declarative, lightweight system for managing WordPress admin notices with automatic GET parameter handling, conditional display, and dismissible notices.\n\n## Features\n\n* **Declarative API**: Register all your notices in one place with a clean configuration array\n* **Automatic Triggers**: Notices appear based on GET parameters (e.g., `?updated=1`)\n* **Dynamic Messages**: Support for callbacks with data interpolation\n* **Conditional Display**: Show notices based on conditions (e.g., missing API keys)\n* **Dismissible Notices**: Built-in AJAX dismissal with per-user persistence\n* **Page Targeting**: Limit notices to specific admin pages with wildcard support\n* **Smart Type Detection**: Automatically infers notice type from key naming\n* **Capability Checks**: Restrict notices based on user permissions\n\n## Installation\n\nInstall via Composer:\n```bash\ncomposer require arraypress/wp-register-notices\n```\n\n## Basic Usage\n```php\nuse function ArrayPress\\AdminNotices\\register_admin_notices;\n\n// Register your notices during plugin initialization\nregister_admin_notices( 'myplugin', [\n    // Simple success messages\n    'added'   =\u003e __( 'Item added successfully.', 'myplugin' ),\n    'updated' =\u003e __( 'Item updated successfully.', 'myplugin' ),\n    'deleted' =\u003e __( 'Item deleted successfully.', 'myplugin' ),\n] );\n\n// Trigger by redirecting with the parameter\nwp_redirect( admin_url( 'admin.php?page=myplugin\u0026updated=1' ) );\n```\n\n## Advanced Examples\n\n### Dynamic Messages with Data\n```php\nregister_admin_notices( 'myplugin', [\n    'bulk_deleted' =\u003e [\n        'message' =\u003e function( $args ) {\n            $count = absint( $args['count'] ?? 0 );\n            return sprintf(\n                _n( '%d item deleted.', '%d items deleted.', $count, 'myplugin' ),\n                $count\n            );\n        },\n        'type' =\u003e 'success',\n        'data' =\u003e ['count']  // Collect these GET parameters\n    ]\n] );\n\n// Trigger: ?bulk_deleted=1\u0026count=5\n// Shows: \"5 items deleted.\"\n```\n\n### Persistent Conditional Notices\n```php\nregister_admin_notices( 'myplugin', [\n    'api_key_missing' =\u003e [\n        'condition' =\u003e function() {\n            return empty( get_option( 'myplugin_api_key' ) );\n        },\n        'message' =\u003e function() {\n            $url = admin_url( 'admin.php?page=myplugin-settings' );\n            return sprintf( \n                __( 'API key required. \u003ca href=\"%s\"\u003eConfigure settings\u003c/a\u003e.', 'myplugin' ),\n                esc_url( $url )\n            );\n        },\n        'type'        =\u003e 'warning',\n        'persistent'  =\u003e true,        // Shows on every page load\n        'dismissible' =\u003e false         // Can't be dismissed\n    ]\n] );\n```\n\n### Page-Specific Notices\n```php\nregister_admin_notices( 'myplugin', [\n    'settings_saved' =\u003e __( 'Settings saved successfully.', 'myplugin' ),\n    'license_activated' =\u003e __( 'License activated.', 'myplugin' ),\n], [\n    'pages' =\u003e ['myplugin-settings', 'myplugin-license'],  // Only these pages\n    'capability' =\u003e 'manage_options'                        // Admin only\n] );\n```\n\n### Error Handling\n```php\nregister_admin_notices( 'myplugin', [\n    'error' =\u003e [\n        'message' =\u003e function( $args ) {\n            return esc_html( $args['message'] ?? __( 'An error occurred.', 'myplugin' ) );\n        },\n        'type' =\u003e 'error',\n        'data' =\u003e ['message']\n    ]\n] );\n\n// Trigger: ?error=1\u0026message=Invalid+email+address\n// Shows: \"Invalid email address\"\n```\n\n### Working with IDs\n```php\nregister_admin_notices( 'myplugin', [\n    'item_updated' =\u003e [\n        'message' =\u003e function( $args ) {\n            if ( ! empty( $args['id'] ) ) {\n                return sprintf( __( 'Item #%d updated.', 'myplugin' ), $args['id'] );\n            }\n            return __( 'Item updated.', 'myplugin' );\n        },\n        'data' =\u003e ['id']\n    ]\n] );\n\n// Trigger: ?item_updated=1\u0026id=123\n// Shows: \"Item #123 updated.\"\n```\n\n## Configuration Options\n\n### Notice Configuration\n\n| Option | Type | Description | Default |\n|--------|------|-------------|---------|\n| `message` | string\\|callable | The notice message or callback | Required |\n| `type` | string | Notice type: `success`, `error`, `warning`, `info` | `success` |\n| `trigger` | string | GET parameter that triggers the notice | Key name |\n| `data` | array | GET parameters to pass to message callback | `[]` |\n| `condition` | callable | Function to determine if notice should show | `null` |\n| `persistent` | bool | Shows on every page load when condition is met | `false` |\n| `dismissible` | bool | Whether notice can be dismissed | `true` |\n| `capability` | string | Required capability to see notice | `null` |\n| `pages` | array\\|string | Admin pages where notice appears (`'all'` for global) | `null` |\n\n### Global Options\n```php\nregister_admin_notices( 'myplugin', $notices, [\n    'pages'       =\u003e ['myplugin', 'myplugin-*'],  // Wildcard support\n    'capability'  =\u003e 'manage_options',\n    'dismissible' =\u003e true                          // Default for all notices\n] );\n```\n\n## Type Detection\n\nThe system automatically infers notice types from key names:\n```php\nregister_admin_notices( 'myplugin', [\n    'item_updated'        =\u003e 'Updated!',    // success (default)\n    'item_deleted_error'  =\u003e 'Failed!',     // error (suffix)\n    'warning_low_stock'   =\u003e 'Low stock',   // warning (prefix)\n    'info_new_feature'    =\u003e 'New feature'  // info (prefix)\n] );\n```\n\n## Real-World Example\n```php\n// In your plugin's main file or admin initialization\nadd_action( 'admin_init', function() {\n    register_admin_notices( 'woocommerce_extras', [\n        // Simple CRUD notifications\n        'product_added'   =\u003e __( 'Product added successfully.', 'wc-extras' ),\n        'product_updated' =\u003e __( 'Product updated successfully.', 'wc-extras' ),\n        'product_deleted' =\u003e __( 'Product deleted successfully.', 'wc-extras' ),\n        \n        // Bulk operations with counts\n        'bulk_updated' =\u003e [\n            'message' =\u003e function( $args ) {\n                $count = absint( $args['count'] ?? 0 );\n                return sprintf( \n                    _n( \n                        '%d product updated.', \n                        '%d products updated.', \n                        $count, \n                        'wc-extras' \n                    ), \n                    $count \n                );\n            },\n            'data' =\u003e ['count']\n        ],\n        \n        // Persistent warnings\n        'shipping_not_configured' =\u003e [\n            'condition' =\u003e function() {\n                $zones = WC_Shipping_Zones::get_zones();\n                return empty( $zones );\n            },\n            'message' =\u003e __( 'No shipping zones configured. Products cannot be shipped.', 'wc-extras' ),\n            'type' =\u003e 'warning',\n            'persistent' =\u003e true\n        ],\n        \n        // Error handling\n        'import_failed' =\u003e [\n            'message' =\u003e function( $args ) {\n                $error = $args['error'] ?? __( 'Unknown error', 'wc-extras' );\n                $line = $args['line'] ?? 0;\n                \n                if ( $line \u003e 0 ) {\n                    return sprintf( \n                        __( 'Import failed at line %d: %s', 'wc-extras' ), \n                        $line, \n                        esc_html( $error ) \n                    );\n                }\n                \n                return sprintf( __( 'Import failed: %s', 'wc-extras' ), esc_html( $error ) );\n            },\n            'type' =\u003e 'error',\n            'data' =\u003e ['error', 'line']\n        ]\n    ], [\n        'pages' =\u003e ['woocommerce', 'edit-product', 'product'],\n        'capability' =\u003e 'manage_woocommerce'\n    ] );\n} );\n\n// In your form handler\nfunction handle_product_save() {\n    $product_id = save_product( $_POST );\n    \n    if ( is_wp_error( $product_id ) ) {\n        $url = add_query_arg( [\n            'import_failed' =\u003e 1,\n            'error' =\u003e $product_id-\u003eget_error_message()\n        ], admin_url( 'edit.php?post_type=product' ) );\n    } else {\n        $url = add_query_arg( [\n            'product_updated' =\u003e 1,\n            'id' =\u003e $product_id\n        ], admin_url( 'edit.php?post_type=product' ) );\n    }\n    \n    wp_redirect( $url );\n    exit;\n}\n```\n\n## Requirements\n\n- PHP 7.4 or later\n- WordPress 5.0 or later\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the GPL-2.0-or-later License.\n\n## Credits\n\nCreated by [David Sherlock](https://davidsherlock.com) at [ArrayPress](https://arraypress.com).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fwp-register-notices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farraypress%2Fwp-register-notices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fwp-register-notices/lists"}