Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Utility PHP class to simplify interacting with persistent dismissible WordPress notices, promos, and banners

License

Notifications You must be signed in to change notification settings

awesomemotive/persistent-dismissible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Persistent Dismissible

A class for encapsulating the logic required to maintain a relationship between the database, a dismissible UI element (with an optional lifespan), and a user's desire to dismiss that UI element.

Think of this like a WordPress Transient, but without in-memory cache support, and that uses the wp_usermeta database table instead of wp_options.

We invented this utility to centralize and minimize the code required to execute multiple different calls and checks to the User Meta and User Options APIs inside of WordPress Core.

We use this as the engine to power if and when we should show persistent admin-area notices to logged-in WordPress users. Dismissals can be set to expire after some number of seconds. They are global by default in a multisite environment, but can be per-site. Custom values can be saved if necessary.

Setup

Include in your plugin or theme however you feel is best.

Use with a PHP use statement:

use Sandhills\Utils\Persistent_Dismissible as PD;

Set

PD::set( [
	'id' => 'sh_dismissible_promotion_xyz'
] );

Get

$is_dismissed = PD::get( [
	'id' => 'sh_dismissible_promotion_xyz'
] );

Delete

PD::delete( [
	'id' => 'sh_dismissible_promotion_xyz'
] );

Arguments

/**
 * @param array|string $args {
 *     Array or string of arguments to identify the persistent dismissible.
 *
 *     @type string      $id       Required. ID of the persistent dismissible.
 *     @type string      $user_id  Optional. User ID. Default to current user ID.
 *     @type int|string  $value    Optional. Value to store. Default to true.
 *     @type int|string  $life     Optional. Lifespan. Default to 0 (infinite)
 *     @type bool        $global   Optional. Multisite, all sites. Default true.
 * }
 */

This project was created by (and is managed by) Sandhills Development, LLC, where we aim to craft superior experiences through ingenuity, with deep commitment to (and appreciation for) the human element.

About

Utility PHP class to simplify interacting with persistent dismissible WordPress notices, promos, and banners

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages