Code Monkey home page Code Monkey logo

wordpress-notifier's Introduction

WordPress Notifier - WP Notice Helper

WordPress Notifier is an object oriented helper library for handling WordPress admin notices inside a plugin or theme. It supports persistent notices and dismissible notices out of the box and is extendable.

Installation

Composer

composer require pxlrbt/wordpress-notifier

Manually

Download and extract the library inside your project. Then include the bootstrap.php file.

require_once '[PATH_TO_FILE]/bootstrap.php';

Usage

Create a notifier instance

Create a new notifier instance globally. This must be called on every page load since it automatically registers hooks for printing the admin notices. Afterwards you can create simple noticies by using notifiers static methods.

Notifier::getInstance();
#or
$notifier = new Notifier()

Create a notification

After creating a Notifier instance you can dispatch new notifications via it. Either use notifiers static functions for simple notifications or create a notification object yourself and configure it with it's chainable methods then dispatch it via the Notifier.

// Static functions refer to last Notifier created
Notifier::info('An update is available.');
Notifier::error('Oops, something went wrong!');

// Advanced usage
$notifier->dispatch(
    Notification::create('Plugin configuration is missing!')
        ->id('plugin_xy.config.failed')
        ->type('error')
        ->title('ERROR')
        ->dismissible(true)
        ->persistent(true);
)

Check whether notification exists

Use the notification ID to check whether the notification was already dispatched.

$id = 'plugin_xy.config.failed';
$notifier->containsNotification($id);

Remove a notification

Notifications can be dismissed manually by the user. If you need to remove persistent notification programatically set an ID and use it to remove the notification again.

$id = 'plugin_xy.config.failed';
$notifier->removeNotification($id);

wordpress-notifier's People

Contributors

pxlrbt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

reswordpress

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.