Giter Site home page Giter Site logo

wp-admin-notices's Introduction

WP Admin Notices

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

wp-admin-notices's People

Contributors

juvojustin avatar

Watchers

James Cloos avatar  avatar

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.