Git Product home page Git Product logo

wp-flash-messages's Introduction

wp-flash-messages

Simple flash message functionality for your WordPress plugin.

Use the function queue_flash_message() to enqueue a flash message that will be displayed on the next admin page load.

queue_flash_message() takes the following form:

<?php queue_flash_message( $message, $class = 'updated' ); ?>

The two parameters are:

  • $message - The string to be displayed. HTML is okay, but keep in mind that your $message will be wrapped in a p and a div tag. (See output example below.)
  • $class - the CSS class to be applied to the div element.

The output will look like this:

<div class="$class">
	<p>$message</p>
</div>

This is the same markup that WordPress generates for its own flash messages.

By default, only the two built-in messages classes of updated and error are allowed, but you can modify the array of allowed classes using the flash_messages_allowed_classes filter, like so:

function my_flash_classes($allowed_classes) {
    $allowed_classes[] = 'notice'; //adds 'notice' class to allowed array
    return $allowed_classes;
}
add_filter('flash_messages_allowed_classes', 'my_flash_classes');

If an invalid class name is used when queueing a message, the default class updated is used instead. Of course, you can also change this with a filter:

function my_flash_default_class($default_class_name) {
    return 'error'; //makes 'error' the default class name
}
add_filter('flash_messages_default_class', 'my_flash_default_class');

wp-flash-messages's People

Watchers

 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.