duckdev/wp-flash-notices 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

duckdev/wp-flash-notices

最新稳定版本:1.0.1

Composer 安装命令:

composer require duckdev/wp-flash-notices

包简介

WordPress admin notices as flash notice using transient API to display after page reload.

README 文档

README

WordPress admin notices as flash notice using transient API to display after page reload.

By default WordPress doesn't provide a solution to show admin notices after page reload. Frameworks lik CodeIgniter does have a flash message feature. Using which, you can show one time notices across user interface. With this simple library you can make use of WordPress' transient API and show one time admin notices like a flash message.

Installation

You can install this library using composer

composer require duckdev/wp-flash-notices

Or, you can download latest version of the library from releases tab.

Dependencies

  • PHP 5.4+
  • WordPress 4.0+

Usage Example

Import the library class and assign custom namespace.

use DuckDev\WP_Flash_Notices as My_Custom_Notices;

Create new instance of the notices class with our custom transient name.

$notices = new My_Custom_Notices( 'my-custom-notices' );

Notice Types

There are 4 types of notices.

Success Notice:

Notice with green bar.

// Register new success notice to the queue.
$notices->add( 'custom-success', 'This is a custom success notice.', 'success' );

Error Notice:

Notice with red bar.

// Register new error notice to the queue.
$notices->add( 'custom-error', 'This is a custom error notice.', 'error' );

Warning Notice:

Notice with yellow bar.

// Register new warning notice to the queue.
$notices->add( 'custom-warning', 'This is a custom warning notice.', 'warning' );

Info Notice:

Notice with blue bar.

// Register new info notice to the queue.
$notices->add( 'custom-info', 'This is a custom info notice.', 'info' );

Dismissible Notice

Show a dismiss button in notice.

// Register new info notice to the queue.
$notices->add( 'custom-success', 'This is a custom dismissible notice.', 'success', true );

Network Admin Notice

By default all notices are shown within single site admin screens. If you have Multisite you can add network admin notices by setting last argument as true:

// Register new info notice to the queue.
$notices->add( 'custom-success', 'This is a custom dismissible notice.', 'success', true, true );

Frontend Compatibility

If you'd like to print the notices in the front-end, then use the below action to your template.

do_action( 'front_notices' );

统计信息

  • 总下载量: 1.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2019-07-18