Download the PHP package wptrt/admin-notices without Composer

On this page you can find all versions of the php package wptrt/admin-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 admin-notices

WPTRT Admin Notices

This is a custom class allowing WordPress theme authors to add admin notices to the WordPress dashboard. Its primary purpose is for providing a standardized method of creating admin notices in a consistent manner using the default WordPress styles.

Notices created using this method are automatically dismissible.

Usage

After you instantiate the Notices object using $my_theme_notices = new \WPTRT\AdminNotices\Notices(); you can add new notices using the add() method.

The arguments of this method are:

Parameter Type Description
$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.
$title string Required The title for your notice. If you don't want to use a title you can use set it to false.
$message string Required The content for the notice you want to create. Please note that the only acceptable tags here are <p>, <a>, <em>, <strong>.
$options array Optional Extra arguments for this notice. Can be used to alter the notice's default behavior.

The $options argument is an array that can have the following optional items:

Key Type Value Default
scope string Can be global or user. Determines if the dismissed status will be saved as an option or user-meta. global
type string Can be one of info, success, warning, error. info
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
capability string The user capability required to see the notice. For a list of all available capabilities please refer to the Roles and Capabilities article. edit_theme_options
screens array An array of screens where the notice will be displayed. For a reference of all available screen-IDs, refer to this article. []
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. wptrt_notice_dismissed

Examples

You can add the following code within your theme's existing code.

First we need to instantiate the Notices object:

To add a simple, default notice:

The 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 wptrt_notice_dismissed_my_theme_notice. The key gets created by appending the $id to the default prefix for the option (wptrt_notice_dismissed), separated by an underscore.

To add a more customized notice:

The 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.

The Notices class can be used to add multiple notices. Once you have finished adding the notices, you will have to run the boot method so that the notices can be added to the dashboard:

To sum up all the above, a complete example of how to add an admin notice would look like this:

Autoloading

You'll need to use an autoloader with this. Ideally, this would be Composer. However, we have a basic autoloader available to include with themes if needed.

Composer

From the command line:

WPTRT Autoloader

If using the WPTRT autoloader, use the following code:


All versions of admin-notices with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
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 wptrt/admin-notices contains the following files

Loading the files please wait ....