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 SandhillsUtilsPersistent_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.

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。