{"id":15046072,"url":"https://github.com/pressmodo/wp-admin-notices","last_synced_at":"2025-04-09T12:31:49.711Z","repository":{"id":57044462,"uuid":"242371087","full_name":"Pressmodo/wp-admin-notices","owner":"Pressmodo","description":"An helper library to create persistent and dismissible WordPress admin notices.","archived":false,"fork":false,"pushed_at":"2020-05-15T15:23:30.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T03:35:01.072Z","etag":null,"topics":["admin","composer","library","notices","pressmodo","wordpress"],"latest_commit_sha":null,"homepage":"https://pressmodo.com","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/Pressmodo.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}},"created_at":"2020-02-22T16:11:58.000Z","updated_at":"2023-12-05T17:36:43.000Z","dependencies_parsed_at":"2022-08-24T04:11:12.747Z","dependency_job_id":null,"html_url":"https://github.com/Pressmodo/wp-admin-notices","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pressmodo%2Fwp-admin-notices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pressmodo%2Fwp-admin-notices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pressmodo%2Fwp-admin-notices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pressmodo%2Fwp-admin-notices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pressmodo","download_url":"https://codeload.github.com/Pressmodo/wp-admin-notices/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248040478,"owners_count":21037872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["admin","composer","library","notices","pressmodo","wordpress"],"created_at":"2024-09-24T20:52:40.262Z","updated_at":"2025-04-09T12:31:44.672Z","avatar_url":"https://github.com/Pressmodo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP Admin Notices\n\nAn helper library to create persistent and dismissible WordPress admin notices.\n\nNotices created using this method are automatically dismissible.\n\n## Usage\n\n```php\n$my_notices = new \\Pressmodo\\AdminNotices\\Notices();\n\n// Add a notice.\n$my_notices-\u003eadd( (string) $id, (string) $title, (string) $content, (array) $options );\n\n// Boot things up.\n$my_notices-\u003eboot();\n```\n\nAfter you instantiate the `Notices` object using `$my_notices = new \\Pressmodo\\AdminNotices\\Notices();` you can add new notices using the `add()` method.\n\nThe arguments of this method are:\n\n| Parameter | Type | | Description\n|---|---|---|---|\n| `$id`| `string` | Required | A unique ID for this notice. **The ID can contain lowercase latin letters and underscores**. It is used to construct the option (or user-meta) key that will be strored in the database. |\n| `$title` | `string` | Required | The title for your notice. If you don't want to use a title you can use set it to `false`. |\n| `$message` | `string` | Required | The content for the notice you want to create. Please note that the only acceptable tags here are `\u003cp\u003e`, `\u003ca\u003e`, `\u003cem\u003e`, `\u003cstrong\u003e`.|\n| `$options` | `array` | Optional | Extra arguments for this notice. Can be used to alter the notice's default behavior. |\n\nThe `$options` argument is an array that can have the following optional items:\n\n| Key | Type | Value | Default\n|---|---|---|---|\n| `scope` | `string` | Can be `global` or `user`. Determines if the dismissed status will be saved as an option or user-meta. | `global` |\n| `type` | `string` |  Can be one of `info`, `success`, `warning`, `error`. | `info`\n| `alt_style` | `bool` | Set to true if you want to use alternative styles. These have a background-color depending on the `type` argument - in contrast to the normal styles that use a white background. | `false` |\n| `dismissible` | `bool` | Set to false to make the notice non dismissible. | `true` |\n| `capability` | `string` | The user capability required to see the notice. For a list of all available capabilities please refer to the [Roles and Capabilities](https://wordpress.org/support/article/roles-and-capabilities/) article. | `edit_theme_options`\n| `screens` | `array` | An array of screens where the notice will be displayed. For a reference of all available screen-IDs, refer to [this article](https://codex.wordpress.org/Plugin_API/Admin_Screen_Reference). | `[]` |\n| `option_prefix` | `string` | The prefix that will be used to build the option (or user-meta) name. Can contain lowercase latin letters and underscores. The actual option is built by combining the `option_prefix` argument with the defined ID from the 1st argument of the `add()` method. | `pressmodo_notice_dismissed` |\n\n## Examples\nYou can add the following code within your theme's existing code.\n\nFirst we need to instantiate the `Notices` object:\n```php\nuse Pressmodo\\AdminNotices\\Notices;\n\n$my_notices = new Notices();\n```\nTo add a simple, default notice:\n```php\n$my_notices-\u003eadd(\n    'my_theme_notice',                           // Unique ID.\n    esc_html__( 'Notice Title', 'textdomain' ),  // The title for this notice.\n    esc_html__( 'Notice content', 'textdomain' ) // The content for this notice.\n);\n```\nThe above example will create a new notice that will only show on all dashboard pages. When the notice gets dismissed, a new option will be saved in the database with the key `pressmodo_notice_dismissed_my_theme_notice`. The key gets created by appending the `$id` to the default prefix for the option (`pressmodo_notice_dismissed`), separated by an underscore.\n\nTo add a more customized notice:\n\n```php\n$my_notices-\u003eadd(\n    'my_notice',                                  // Unique ID.\n    esc_html__( 'Notice Title', 'textdomain' ),   // The title for this notice.\n    esc_html__( 'Notice content', 'textdomain' ), // The content for this notice.\n    [\n        'scope'         =\u003e 'user',       // Dismiss is per-user instead of global.\n        'screens'       =\u003e [ 'themes' ], // Only show notice in the \"themes\" screen.\n        'type'          =\u003e 'warning',    // Make this a warning (orange color).\n        'alt_style'     =\u003e true,         // Use alt styles.\n        'option_prefix' =\u003e 'my_theme',   // Change the user-meta prefix.\n    ]\n);\n```\n\nThe above example will create a new notice that will only show in the \"Themes\" screen in the dashboard. When the notice gets dismissed, a new user-meta will be saved and the key for the stored user-meta will be `my_theme_my_notice`. The key gets created by appending the `$id` to our defined `option_prefix`, separated by an underscore.\n\nThe `Notices` class can be used to add multiple notices.\nOnce you have finished adding the notices, you will have to run the `boot` method so that the notices can be added to the dashboard:\n```php\n$my_notices-\u003eboot();\n```\n\nTo sum up all the above, a complete example of how to add an admin notice would look like this:\n\n```php\n$my_notices = new \\Pressmodo\\AdminNotices\\Notices();\n$my_notices-\u003eadd( 'my_theme_notice', __( 'Title', 'textdomain' ), __( 'Content', 'textdomain' ) );\n$my_notices-\u003eboot();\n```\n\n## Autoloading\n\nYou'll need to use an autoloader with this. Ideally, this would be [Composer](https://getcomposer.org).\n\n### Composer\n\nFrom the command line:\n\n```sh\ncomposer require pressmodo/wp-admin-notices\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpressmodo%2Fwp-admin-notices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpressmodo%2Fwp-admin-notices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpressmodo%2Fwp-admin-notices/lists"}