This repository has been archived by the owner on Dec 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,025 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"require": { | ||
"yahnis-elsts/plugin-update-checker": "^4.10" | ||
"yahnis-elsts/plugin-update-checker": "^4.10", | ||
"collizo4sky/persist-admin-notices-dismissal": "^1.4" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
vendor/collizo4sky/persist-admin-notices-dismissal/CHANGES.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#### 1.4.4 | ||
* Added support for extra dismissible links via `.dismiss-this` CSS class. | ||
|
||
#### 1.4.3 | ||
* Added filter hook `pand_dismiss_notice_js_url` in case you're using this in a theme or a local environment that doesn't quite find the correct URL. | ||
* Added filter hook `pand_theme_loader` that returns a boolean for simpler usage of the `pand_dismiss_notice_js_url` hook | ||
|
||
#### 1.4.2 | ||
* No changes to `class PAnD` | ||
* Updated `.gitignore` and `.gitattributes` | ||
* Now use classmap in composer's autoloader, should be more efficient | ||
|
||
#### 1.4.1 | ||
* Fixed the `forever` setting with options | ||
|
||
#### 1.4.0 | ||
* WPCS 1.1.0 linting done | ||
* Switched from storing timeout in transients to storing in the options table, this should play much better with object caching | ||
|
||
#### 1.3.x | ||
* Uses transients to store timeout |
128 changes: 128 additions & 0 deletions
128
vendor/collizo4sky/persist-admin-notices-dismissal/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Persist Admin notice Dismissals | ||
[![Latest Stable Version](https://poser.pugx.org/collizo4sky/persist-admin-notices-dismissal/v/stable)](https://packagist.org/packages/collizo4sky/persist-admin-notices-dismissal) | ||
[![Total Downloads](https://poser.pugx.org/collizo4sky/persist-admin-notices-dismissal/downloads)](https://packagist.org/packages/collizo4sky/persist-admin-notices-dismissal) | ||
|
||
Simple framework library that persists the dismissal of admin notices across pages in WordPress dashboard. | ||
|
||
## Installation | ||
|
||
Run `composer require collizo4sky/persist-admin-notices-dismissal` | ||
|
||
Alternatively, clone or download this repo into the `vendor/` folder in your plugin, and include/require the `persist-admin-notices-dismissal.php` file like so | ||
|
||
```php | ||
require __DIR__ . '/vendor/persist-admin-notices-dismissal/persist-admin-notices-dismissal.php'; | ||
add_action( 'admin_init', array( 'PAnD', 'init' ) ); | ||
``` | ||
|
||
or let Composer's autoloader do the work. | ||
|
||
## How to Use | ||
Firstly, install and activate this library within a plugin. | ||
|
||
Say you have the following markup as your admin notice, | ||
|
||
|
||
```php | ||
function sample_admin_notice__success() { | ||
?> | ||
<div class="updated notice notice-success is-dismissible"> | ||
<p><?php _e( 'Done!', 'sample-text-domain' ); ?></p> | ||
</div> | ||
<?php | ||
} | ||
add_action( 'admin_notices', 'sample_admin_notice__success' ); | ||
``` | ||
|
||
To make it hidden forever when dismissed, add the following data attribute `data-dismissible="disable-done-notice-forever"` to the div markup like so: | ||
|
||
|
||
```php | ||
function sample_admin_notice__success() { | ||
if ( ! PAnD::is_admin_notice_active( 'disable-done-notice-forever' ) ) { | ||
return; | ||
} | ||
|
||
?> | ||
<div data-dismissible="disable-done-notice-forever" class="updated notice notice-success is-dismissible"> | ||
<p><?php _e( 'Done!', 'sample-text-domain' ); ?></p> | ||
</div> | ||
<?php | ||
} | ||
add_action( 'admin_init', array( 'PAnD', 'init' ) ); | ||
add_action( 'admin_notices', 'sample_admin_notice__success' ); | ||
``` | ||
|
||
## Autoloaders | ||
When using the framework with an autoloader you **must** also load the class outside of the `admin_notices` or `network_admin_notices` hooks. The reason is that these hooks come after the `admin_enqueue_script` hook that loads the javascript. | ||
|
||
Just add the following in your main plugin file. | ||
|
||
```php | ||
add_action( 'admin_init', array( 'PAnD', 'init' ) ); | ||
``` | ||
|
||
#### Usage Instructions and Examples | ||
If you have two notices displayed when certain actions are triggered; firstly, choose a string to uniquely identify them, e.g. `notice-one` and `notice-two` | ||
|
||
To make the first notice never appear once dismissed, its `data-dismissible` attribute will be `data-dismissible="notice-one-forever"` where `notice-one` is its unique identifier and `forever` is the dismissal time period. | ||
|
||
To make the second notice only hidden for 2 days, its `data-dismissible` attribute will be `data-dismissible="notice-two-2"` where `notice-two` is its unique identifier and the `2`, the number of days it will be hidden is the dismissal time period. | ||
|
||
You **must** append the dismissal time period to the end of your unique identifier with a hyphen (`-`) and this value must be an integer. The only exception is the string `forever`. | ||
|
||
To actually make the dismissed admin notice not to appear, use the `is_admin_notice_active()` function like so: | ||
|
||
|
||
```php | ||
function sample_admin_notice__success1() { | ||
if ( ! PAnD::is_admin_notice_active( 'notice-one-forever' ) ) { | ||
return; | ||
} | ||
|
||
?> | ||
<div data-dismissible="notice-one-forever" class="updated notice notice-success is-dismissible"> | ||
<p><?php _e( 'Done 1!', 'sample-text-domain' ); ?></p> | ||
</div> | ||
<?php | ||
} | ||
|
||
function sample_admin_notice__success2() { | ||
if ( ! PAnD::is_admin_notice_active( 'notice-two-2' ) ) { | ||
return; | ||
} | ||
|
||
?> | ||
<div data-dismissible="notice-two-2" class="updated notice notice-success is-dismissible"> | ||
<p><?php _e( 'Done 2!', 'sample-text-domain' ); ?></p> | ||
</div> | ||
<?php | ||
} | ||
|
||
add_action( 'admin_init', array( 'PAnD', 'init' ) ); | ||
add_action( 'admin_notices', 'sample_admin_notice__success1' ); | ||
add_action( 'admin_notices', 'sample_admin_notice__success2' ); | ||
``` | ||
|
||
Please note that if you cleanup after your plugin deletion please try to make the removal of stored options as specific as possible. Otherwise you may end up deleting the stored options from other projects. | ||
|
||
A filter hook is available to return the proper URL to the Javascript file. An example usage is as follows, especially if this is being used in a theme. | ||
|
||
```php | ||
add_filter( 'pand_theme_loader', '__return_true' ); | ||
``` | ||
|
||
The `pand_theme_loader` runs the following hook if `true`. You can directly change the URL to the Javascript file by using another hook in the following manner by changing the return value. | ||
|
||
```php | ||
add_filter( | ||
'pand_dismiss_notice_js_url', | ||
function( $js_url, $composer_path ) { | ||
return get_stylesheet_directory_uri() . $composer_path; | ||
}, | ||
10, | ||
2 | ||
); | ||
``` | ||
|
||
Cool beans. Isn't it? |
27 changes: 27 additions & 0 deletions
27
vendor/collizo4sky/persist-admin-notices-dismissal/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "collizo4sky/persist-admin-notices-dismissal", | ||
"description": "Simple library to persist dismissal of admin notices across pages in WordPress dashboard.", | ||
"version": "1.4.4", | ||
"type": "library", | ||
"license": "GPL-3.0-or-later", | ||
"authors": [ | ||
{ | ||
"name": "Collins Agbonghama", | ||
"email": "me@w3guy.com", | ||
"role": "developer" | ||
} | ||
], | ||
"prefer-stable": true, | ||
"require": { | ||
"php": ">=5.4" | ||
}, | ||
"support": { | ||
"issues": "https://github.com/w3guy/persist-admin-notices-dismissal/issues", | ||
"source": "https://github.com/w3guy/persist-admin-notices-dismissal" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
"persist-admin-notices-dismissal.php" | ||
] | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
vendor/collizo4sky/persist-admin-notices-dismissal/dismiss-notice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(function ($) { | ||
//shorthand for ready event. | ||
$( | ||
function () { | ||
$( 'div[data-dismissible] button.notice-dismiss, div[data-dismissible] .dismiss-this' ).on("click", | ||
function (event) { | ||
event.preventDefault(); | ||
var $this = $( this ); | ||
|
||
var attr_value, option_name, dismissible_length, data; | ||
|
||
attr_value = $this.closest("div[data-dismissible]").attr( 'data-dismissible' ).split( '-' ); | ||
|
||
// remove the dismissible length from the attribute value and rejoin the array. | ||
dismissible_length = attr_value.pop(); | ||
|
||
option_name = attr_value.join( '-' ); | ||
|
||
data = { | ||
'action': 'dismiss_admin_notice', | ||
'option_name': option_name, | ||
'dismissible_length': dismissible_length, | ||
'nonce': dismissible_notice.nonce | ||
}; | ||
|
||
// We can also pass the url value separately from ajaxurl for front end AJAX implementations | ||
$.post( ajaxurl, data ); | ||
$this.closest("div[data-dismissible]").hide('slow'); | ||
} | ||
); | ||
} | ||
) | ||
|
||
}(jQuery)); |
Oops, something went wrong.