Download the PHP package duckdev/wp-flash-notices without Composer

On this page you can find all versions of the php package duckdev/wp-flash-notices. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-flash-notices

WP Flash Notices

WP Flash Notices is a small WordPress library that turns admin notices into flash notices: you queue a notice during one request (typically right before a redirect), and it is printed on the next page load and then cleared. It borrows the idea from framework flash messages and implements it on top of the WordPress transient API.

Notices queued during a request are held in memory and flushed to storage once, on shutdown, so queueing ten notices still costs a single database write. Multisite network notices are kept in a separate queue, and both the storage and the rendering layers are swappable.

📖 Full documentation: docs.foxelabs.com

Requirements

Installation

The library autoloads under the FoxeLabs\Notices\ namespace via PSR-4.

Architecture

The library is organised as a tiny container wired up by the entry class FoxeLabs\Notices\Notices. The folder layout mirrors the namespace:

Services receive their collaborators by constructor injection so they can be unit-tested without WordPress in the loop. Construction has no side effects — call register() to attach the hooks.

Usage

Initialisation

Each instance is scoped to a single prefix. Every transient key and every hook name is namespaced under it, so two plugins using this library on the same site never see each other's notices:

Call register() once, early — plugins_loaded is a good place. You can also instantiate directly, which is what you want when injecting your own store or renderer:

Anywhere else in your plugin, Notices::get_instance( 'my_plugin' ) hands back the same container, so you don't need to pass it around.

Adding a notice

Parameter Type Description
$key string Unique key. Re-using a key replaces the earlier notice.
$message string Notice body. Limited HTML allowed (run through wpautop() + wp_kses()).
$type string success, info, warning or error. Unknown types fall back to info.
$dismissible bool Show the dismiss button.
$network bool Queue as a network admin notice (multisite only).

It returns the queued Notice, and throws NoticeException when the key or message is empty.

Off multisite, a notice queued with $network = true silently falls back to the regular site queue.

Reading and clearing

Pass true as the last argument to any of these to work on the network queue.

Notice is an immutable value object with key(), message(), type(), is_dismissible() and to_array().

Front-end notices

Notices are printed automatically on admin_notices and network_admin_notices. To print them in a front-end template, fire the prefixed action yourself:

Hooks

Every hook name is prefixed with your instance prefix — the examples below assume my_plugin.

Filters

Hook Arguments Purpose
my_plugin_flash_notice_types string[] $types Register custom notice types. A type maps to the notice-{type} CSS class.
my_plugin_flash_notice_item Notice $notice, bool $network Replace a notice just before it is queued. Return a Notice to override.
my_plugin_flash_notices_fetch Notice[] $notices, bool $network Modify the notices read from storage.
my_plugin_flash_notices_auto_render bool $enable, bool $network Return false to stop the library printing notices — nothing is cleared either.
my_plugin_flash_notices_auto_clear bool $enable, bool $network Return false to keep notices after rendering. You must then call clear() yourself.

Actions

Hook Arguments
my_plugin_flash_notices_after_queue Notice $notice, bool $network, Notice[] $queue, Notice[] $network_queue
my_plugin_flash_notices_after_save Notice[] $queue, Notice[] $network_queue
my_plugin_flash_notices_after_render Notice[] $notices, bool $network
my_plugin_flash_notices_after_clear bool $network
my_plugin_front_notices — (fire it yourself to print notices on the front end)

Custom storage and rendering

Implement StoreInterface to change where the queue lives, or RendererInterface to change the markup, and pass your implementation to the constructor:

TransientStore also takes an expiration (default one day), so an unread queue cannot linger in the options table forever:

Upgrading from 1.x

Version 2.0.0 is a breaking rewrite. If you are coming from duckdev/wp-flash-notices:

1.x 2.0.0
duckdev/wp-flash-notices foxelabs/wp-flash-notices
DuckDev\WP_Flash_Notices FoxeLabs\Notices\Notices
Constructor took a transient name Constructor takes a prefix; keys are derived from it
Hooks attached in the constructor Call register() explicitly
wp_flash_notices_* hooks {prefix}_flash_notices_* / {prefix}_flash_notice_*
front_notices action {prefix}_front_notices
get() / fetch() returned arrays Return Notice objects (null / [] when absent)
clear_after_render() public method Removed; clearing is internal to render()
Notices stored forever Stored with an expiration (default one day)

Stored 1.x transients are not migrated — any notice left in the old transient at upgrade time is simply not shown.

Two 1.x bugs are fixed along the way: network notices were saved from the wrong queue (so the site queue was written to the network transient), and the auto-clear callback received mismatched arguments, so notices were not reliably cleared after rendering.

Development

License

GPL-2.0-or-later. See LICENSE.


All versions of wp-flash-notices with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package duckdev/wp-flash-notices contains the following files

Loading the files please wait ...