Move into wp-content path
Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
18
wp-content/plugins/github-updater/vendor/collizo4sky/persist-admin-notices-dismissal/CHANGES.md
vendored
Normal file
18
wp-content/plugins/github-updater/vendor/collizo4sky/persist-admin-notices-dismissal/CHANGES.md
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
#### 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
wp-content/plugins/github-updater/vendor/collizo4sky/persist-admin-notices-dismissal/README.md
vendored
Normal file
128
wp-content/plugins/github-updater/vendor/collizo4sky/persist-admin-notices-dismissal/README.md
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
# Persist Admin notice Dismissals
|
||||
[](https://packagist.org/packages/collizo4sky/persist-admin-notices-dismissal)
|
||||
[](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?
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "collizo4sky/persist-admin-notices-dismissal",
|
||||
"description": "Simple library to persist dismissal of admin notices across pages in WordPress dashboard.",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Collins Agbonghama",
|
||||
"email": "me@w3guy.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"persist-admin-notices-dismissal.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
(function ($) {
|
||||
//shorthand for ready event.
|
||||
$(
|
||||
function () {
|
||||
$( 'div[data-dismissible] button.notice-dismiss' ).click(
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
var $this = $( this );
|
||||
|
||||
var attr_value, option_name, dismissible_length, data;
|
||||
|
||||
attr_value = $this.parent().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 );
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
|
||||
}(jQuery));
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Persist Admin notices Dismissal
|
||||
*
|
||||
* Copyright (C) 2016 Collins Agbonghama <http://w3guy.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package Persist Admin notices Dismissal
|
||||
* @author Collins Agbonghama
|
||||
* @author Andy Fragen
|
||||
* @license http://www.gnu.org/licenses GNU General Public License
|
||||
* @version 1.4.3
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exit if called directly.
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PAnD' ) ) {
|
||||
|
||||
/**
|
||||
* Class PAnD
|
||||
*/
|
||||
class PAnD {
|
||||
|
||||
/**
|
||||
* Init hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) );
|
||||
add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) );
|
||||
|
||||
/**
|
||||
* Filter to activate another filter providing a simpler use case.
|
||||
*
|
||||
* @since 1.4.3
|
||||
*
|
||||
* @param bool
|
||||
*/
|
||||
if ( apply_filters( 'pand_theme_loader', false ) ) {
|
||||
add_filter(
|
||||
'pand_dismiss_notice_js_url',
|
||||
function( $js_url, $composer_path ) {
|
||||
return get_stylesheet_directory_uri() . $composer_path;
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue javascript and variables.
|
||||
*/
|
||||
public static function load_script() {
|
||||
|
||||
if ( is_customize_preview() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$js_url = plugins_url( 'dismiss-notice.js', __FILE__ );
|
||||
$composer_path = '/vendor/collizo4sky/persist-admin-notices-dismissal/dismiss-notice.js';
|
||||
|
||||
/**
|
||||
* Filter dismiss-notice.js URL.
|
||||
*
|
||||
* @since 1.4.3
|
||||
*
|
||||
* @param string $js_url URL to the Javascript file.
|
||||
* @param string $composer_path Relative path of Javascript file from composer install.
|
||||
*/
|
||||
$js_url = apply_filters( 'pand_dismiss_notice_js_url', $js_url, $composer_path );
|
||||
wp_enqueue_script(
|
||||
'dismissible-notices',
|
||||
$js_url,
|
||||
array( 'jquery', 'common' ),
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'dismissible-notices',
|
||||
'dismissible_notice',
|
||||
array(
|
||||
'nonce' => wp_create_nonce( 'dismissible-notice' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles Ajax request to persist notices dismissal.
|
||||
* Uses check_ajax_referer to verify nonce.
|
||||
*/
|
||||
public static function dismiss_admin_notice() {
|
||||
$option_name = sanitize_text_field( $_POST['option_name'] );
|
||||
$dismissible_length = sanitize_text_field( $_POST['dismissible_length'] );
|
||||
|
||||
if ( 'forever' != $dismissible_length ) {
|
||||
// If $dismissible_length is not an integer default to 1
|
||||
$dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length;
|
||||
$dismissible_length = strtotime( absint( $dismissible_length ) . ' days' );
|
||||
}
|
||||
|
||||
check_ajax_referer( 'dismissible-notice', 'nonce' );
|
||||
self::set_admin_notice_cache( $option_name, $dismissible_length );
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is admin notice active?
|
||||
*
|
||||
* @param string $arg data-dismissible content of notice.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_admin_notice_active( $arg ) {
|
||||
$array = explode( '-', $arg );
|
||||
$length = array_pop( $array );
|
||||
$option_name = implode( '-', $array );
|
||||
$db_record = self::get_admin_notice_cache( $option_name );
|
||||
|
||||
if ( 'forever' == $db_record ) {
|
||||
return false;
|
||||
} elseif ( absint( $db_record ) >= time() ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns admin notice cached timeout.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|bool $id admin notice name or false.
|
||||
*
|
||||
* @return array|bool The timeout. False if expired.
|
||||
*/
|
||||
public static function get_admin_notice_cache( $id = false ) {
|
||||
if ( ! $id ) {
|
||||
return false;
|
||||
}
|
||||
$cache_key = 'pand-' . md5( $id );
|
||||
$timeout = get_site_option( $cache_key );
|
||||
$timeout = 'forever' === $timeout ? time() + 60 : $timeout;
|
||||
|
||||
if ( empty( $timeout ) || time() > $timeout ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets admin notice timeout in site option.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Data Identifier.
|
||||
* @param string|bool $timeout Timeout for admin notice.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function set_admin_notice_cache( $id, $timeout ) {
|
||||
$cache_key = 'pand-' . md5( $id );
|
||||
update_site_option( $cache_key, $timeout );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user