juvo / wp-admin-notices
Adds a wrapper layer to store notices for wptrt/admin-notices
Installs: 1 959
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: >=7.0.0
- wptrt/admin-notices: ^1.0
This package is auto-updated.
Last update: 2024-10-15 07:19:18 UTC
README
This is an extension for the wptrt/admin-notices package to store notices in a transient. The goal is to allow a dynamic storing process throughout WordPress. Since this package is only a proxy that stores the notices in the database, you can find examples and options in the wptrt/admin-notices repository.
Usage
// Display stored notices add_action( 'admin_init', function() { $notices = new \juvo\WordPressAdminNotices\Manager(); $notices->notices(); } ); // Add a notice. \juvo\WordPressAdminNotices\Manager::add((string) $id, (string) $title, (string) $content, (array) $options); // Remove a notice. \juvo\WordPressAdminNotices\Manager::remove((string) $id, (bool) $onlyGlobal); //Example: Check if Advanced Custom Fields Pro is installed if ( ! class_exists( 'acf_pro' ) ) { // Add a notice. Manager::add( "missing_plugin", "Required plugin missing","The advanced custom fields plugin is required for this plugin to work" ), [ "type" => "error" ] ); } else { Manager::remove( "missing_plugin"); }
wptrt/admin-notices parameters are fully supported. If a notice with global scope is dismissed, it will be automatically removed from the transient. Additionally a max_age
parameter can be passed to the Manager
constructor.
All notices older than this value will be removed. Notices with a user scope are not removed from the transient by dismissing them. They will only be removed if they exceed the max_age
. The transient itself does not expire at all.
Composer
From the command line:
composer require juvo/wp-admin-notices