Coder Social home page Coder Social logo

awesomemotive / persistent-dismissible Goto Github PK

View Code? Open in Web Editor NEW
22.0 3.0 3.0 45 KB

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

License: GNU General Public License v3.0

PHP 100.00%
wordpress plugins utility admin-notice persistent dismissible

persistent-dismissible's Introduction

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.

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.