All Projects → TypistTech → wp-admin-notices

TypistTech / wp-admin-notices

Licence: GPL-2.0 license
A simplified OOP implementation of the WordPress admin notices.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to wp-admin-notices

gin
Foundation of the Tonik WordPress Starter Theme. Provides all custom functionalities which it offers.
Stars: ✭ 29 (+81.25%)
Mutual labels:  wordpress-development, wordpress-php-library
wp-optimize
The WP Optimize class provides a wrapper to optimize WordPress and remove unnecessary or unwanted functions and scripts.
Stars: ✭ 37 (+131.25%)
Mutual labels:  wordpress-development, wordpress-php-library
wp-router
Enables developers to easily create custom routes with matching templates accordingly.
Stars: ✭ 22 (+37.5%)
Mutual labels:  wordpress-development, wordpress-php-library
wp-better-settings
A simplified OOP implementation of the WP Settings API
Stars: ✭ 14 (-12.5%)
Mutual labels:  wordpress-development, wordpress-php-library
enveigle
Deceive Ansible to template Trellis .env files to local Bedrock
Stars: ✭ 18 (+12.5%)
Mutual labels:  wordpress-development
Code Snippets
Code Snippets WordPress Plugin
Stars: ✭ 226 (+1312.5%)
Mutual labels:  wordpress-development
Brizy
Brizy is the most user-friendly visual page builder in town! No designer or developer skills required. The only tools you'll need to master are clicks and drags.
Stars: ✭ 209 (+1206.25%)
Mutual labels:  wordpress-development
Wp Tailwindcss Theme Boilerplate
A minimalist boilerplate for WordPress theme development using Tailwind CSS, SCSS, and Laravel Mix.
Stars: ✭ 199 (+1143.75%)
Mutual labels:  wordpress-development
WordPress-Distribution
This repository helps you to get a local new and fresh WordPress for everything you want (e.g. Developing, Testing, etc.).
Stars: ✭ 16 (+0%)
Mutual labels:  wordpress-development
coblocks-theme
WordPress theme for CoBlocks
Stars: ✭ 24 (+50%)
Mutual labels:  wordpress-development
wp-modular-css
Plugin to generate a custom Tachyons build from a JSON configuration.
Stars: ✭ 15 (-6.25%)
Mutual labels:  wordpress-development
Generator Chisel
Chisel is a development framework for creating easy to maintain and fast WordPress websites
Stars: ✭ 233 (+1356.25%)
Mutual labels:  wordpress-development
silk
A modern API for WordPress.
Stars: ✭ 62 (+287.5%)
Mutual labels:  wordpress-php-library
Aquila
🎨 An Advanced WordPress theme
Stars: ✭ 204 (+1175%)
Mutual labels:  wordpress-development
blade
🏃 A library for using Laravel Blade templates in WordPlate.
Stars: ✭ 28 (+75%)
Mutual labels:  wordpress-php-library
Wplib Box
The Best Local Dev Server for WordPress Developers
Stars: ✭ 204 (+1175%)
Mutual labels:  wordpress-development
wp-weixin
WordPress WeChat integration
Stars: ✭ 62 (+287.5%)
Mutual labels:  wordpress-development
barebones
React based WordPress Theme, built with create-react-wptheme. This is a starter theme with just the core WordPress functionality.
Stars: ✭ 35 (+118.75%)
Mutual labels:  wordpress-development
login-designer
Official repository of the Login Designer WordPress Plugin
Stars: ✭ 97 (+506.25%)
Mutual labels:  wordpress-development
Create React Wptheme
Create modern, React-enabled WordPress themes with a single command.
Stars: ✭ 252 (+1475%)
Mutual labels:  wordpress-development

WP Admin Notices

Latest Stable Version Total Downloads Build Status codecov Scrutinizer Code Quality PHP Versions Tested StyleCI License Donate via PayPal Hire Typist Tech

A simplified OOP implementation of the WordPress admin notices.

The Goals, or What This Package Does?

Install

Installation should be done via composer, details of how to install composer can be found at https://getcomposer.org/.

$ composer require typisttech/wp-admin-notices

You should put all WP Admin Notices classes under your own namespace to avoid class name conflicts.

Usage

Example

use TypistTech\WPAdminNotices\Factory;
use TypistTech\WPAdminNotices\Notice;
use TypistTech\WPAdminNotices\StickyNotice;

$store = Factory::build('my_unique_demo_option', 'my_unique_demo_action');

add_action('admin_init', function () use ($store) {
        $notice = new Notice('example-notice-1', 'my notice message');
        $store->add($notice);
    }
);

add_action('post_updated', function ($post_id) use ($store) {
        $notices[] = new Notice(
            'example-notice-2',
            "<p><strong>WPAdminNotices</strong>: Post ID: $post_id has been updated.</p>",
            Notice::SUCCESS
        );
        $notices[] = new StickyNotice(
            'example-notice-3',
            '<p><strong>WPAdminNotices</strong>: StickyNotice persists in database until user clicks to dismiss it.</p>'
        );
        $store->add(...$notices);
    }
);

Notice

One-off notice that guaranteed to be shown once and once only.

__construct(string $handle, string $content, string $type = null)

Notice constructor.

  • @param string $handle The notice's unique identifier.
  • @param string $content The HTML content of the notice.
  • @param string|null $type The notice's type. Expecting one of Notice::UPDATE_NAG, Notice::ERROR, Notice::WARNING, Notice::INFO, Notice::SUCCESS. Default is Notice::INFO.

Notice::UPDATE_NAG is not suitable for regular admin notices. See WordPress codex.

$notice = new Notice('example-notice', '<strong>Hello</strong> World!', Notice::SUCCESS);

StickyNotice

StickyNotice persists in database until user clicks to dismiss it.

__construct(string $handle, string $content, string $type = null)

StickyNotice constructor.

  • @param string $handle The notice's unique identifier. Also used to permanently dismiss a sticky notice.
  • @param string $content The HTML content of the notice.
  • @param string|null $type The notice's type. Expecting one of StickyNotice::ERROR, StickyNotice::WARNING, StickyNotice::INFO, StickyNotice::SUCCESS. Default is StickyNotice::INFO.

UPDATE_NAG is not available for StickyNotice.

$stickyNotice = new StickyNotice('example-sticky-notice', 'I wont go away until users click on me.', StickyNotice::WARNING);

Store

By default, WP Admin Notices stores notices in WordPress' wp_option table via Store. If you want to use an alternative store, see FAQ.

__construct(string $optionKey)

Store constructor.

  • @param string $optionKey Key in options table that holds all enqueued notices.
$store = new Store('my_unique_option_key');

add(NoticeInterface ...$notices)

Enqueue admin notices to database.

Not limited to Notice and StickyNotice only, any instance of NoticeInterface is accepted. See FAQ.

  • @param NoticeInterface[] ...$notices Notices to be enqueued.
$store->add($notice1, $notice2);

// To update a notice, re-add with the same handle.
$oldNotice = new Notice('i-am-unique', "Chaos isn't a pit.");
$store->add($oldNotice);

$newNotice = new Notice('i-am-unique', 'Chaos is a ladder.');
$store->add($newNotice);

delete(string $handle)

Delete an enqueued notice.

  • @param string $handle Handle of the notice to be deleted.
$store->delete('i-am-unique');

Notifier

Notifier handles all interactions between WordPress and this package via action hooks. You have to hook it into WordPress via add_action unless you use Factory.

__construct(string $action, StoreInterface $store)

Notifier constructor.

  • @param string $action AJAX request's 'action' property for sticky notices.
  • @param StoreInterface $store Connector to notice storage.
$store = new Store('my_unique_option_key');
$notifier = new Notifier('my_unique_action', $store);

add_action('admin_notices', [$notifier, 'renderNotices']);
add_action("wp_ajax_my_unique_action", [$notifier, 'dismissNotice']);
add_action('admin_footer', [$notifier, 'renderScript']);

Factory

Factory is a helper class to reduce boilerplate code for those who use default Store class. If you use a custom store, don't use this class.

build(string $optionKey, string $action): Store

  • @param string $optionKey Key in options table that holds all enqueued notices.
  • @param string $action AJAX request's 'action' property for sticky notices.
  • @return Store
$store = Factory::build('my_unique_option_key', 'my_unique_action');

Frequently Asked Questions

Can I implement my own notice classes?

Of course! Just implements the NoticeInterface.

Take a look at classes Notice and StickyNotice as well as their tests for example implementations of StoreInterface.

If you'd like to create a open-source package to do this to help others, open a new issue to let us know, we'd love to help you with it.

Can I use a different storage scheme other than wp_option table?

Of course! WP Admin Notices data store is completely swappable, and always has been.

To implement a custom store:

  1. Implement StoreInterface
  2. Pass you custom store to Notifier
class MyCustomStore implements StoreInterface
{
  // Implements all the required methods.
}

$store = new MyCustomStore;
$action = 'my_unique_action';
$notifier = new Notifier($action, $store);

add_action('admin_notices', [$notifier, 'renderNotices']);
add_action("wp_ajax_$action", [$notifier, 'dismissNotice']);
add_action('admin_footer', [$notifier, 'renderScript']);

Take a look at the Store class and StoreTest for an example implementation of StoreInterface.

If you'd like to create a open-source package to do this to help others, open a new issue to let us know, we'd love to help you with it.

Is this a plugin?

No, this is a package that should be part of your plugin.

What to do when wp.org plugin team tell me to clean up the vendor folder?

Re-install packages via the following command. This package exports only necessary files to dist.

$ composer install --no-dev --prefer-dist --optimize-autoloader

Can two different plugins use this package at the same time?

Yes, if put all WP Admin Notices classes under your own namespace to avoid class name conflicts.

Do you have a demo plugin that use this package?

You can install this demo plugin by

$ wp plugin install https://github.com/TypistTech/wp-admin-notices/archive/nightly.zip --activate

Check out wp-admin-notices.php. We use it for acceptance tests.

Do you have real life examples that use this package?

Here you go:

Add your own plugin here

It looks awesome. Where can I find some more goodies like this?

Support

Love wp-admin-notices? Help me maintain it, a donation here can help with it.

Why don't you hire me?

Ready to take freelance WordPress jobs. Contact me via the contact form here or, via email [email protected]

Want to help in other way? Want to be a sponsor?

Contact: Tang Rufus

Developing

To setup a developer workable version you should run these commands:

$ composer create-project --keep-vcs --no-install typisttech/wp-admin-notices:dev-master
$ cd wp-admin-notices
$ composer install

Running the Tests

WP Admin Notices run tests on Codeception and relies wp-browser to provide WordPress integration. Before testing, you have to install WordPress locally and add a codeception.yml file. See *.suite.example.yml for Local by Flywheel configuration examples.

Actually run the tests:

$ composer test

We also test all PHP files against PSR-2: Coding Style Guide and part of the WordPress coding standard.

Check the code style with $ composer check-style.

Feedback

Please provide feedback! We want to make this package useful in as many projects as possible. Please submit an issue and point out what you do and don't like, or fork the project and make suggestions. No issue is too small.

Change log

Please see CHANGELOG for more information on what has changed recently.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Credits

WP Admin Notices is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire.

Full list of contributors can be found here.

License

WP Admin Notices is licensed under the GPLv2 (or later) from the Free Software Foundation. Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].