Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Release v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joppuyo committed Dec 5, 2021
1 parent bd28ee6 commit 4137364
Show file tree
Hide file tree
Showing 18 changed files with 1,025 additions and 68 deletions.
3 changes: 2 additions & 1 deletion composer.json
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"
}
}
45 changes: 43 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ This plugin does continue working in WordPress 5.8 but be aware of this alternat

## Changelog

### 1.4.0 (2021-12-05)
* Feature: Add a notice to encourage people to update to the new version in the plugin directory

### 1.3.1 (2021-09-20)
* Fix: Fix deprecation error in WordPress 5.8

Expand Down
16 changes: 15 additions & 1 deletion remove-drop-cap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin name: Disable Drop Cap
* Description: Plugin to disable drop cap in Gutenberg editor paragraph block
* Plugin URI: https://github.com/joppuyo/remove-drop-cap
* Version: 1.3.1
* Version: 1.4.0
* Author: Johannes Siipola
* Author URI: https://siipo.la
* License: GPLv2 or later
Expand Down Expand Up @@ -94,3 +94,17 @@ function disable_drop_cap_admin_footer() {
</script>
HTML;
}

function disable_drop_cap_update_nag() {
if (!PAnD::is_admin_notice_active('disable-drop-cap-update-nag-7')) {
return;
}

echo '<div data-dismissible="disable-drop-cap-update-nag-7" class="notice notice-warning is-dismissible">';
echo '<p>Version 1 of Disable Drop Cap is no longer being maintained. Please update to version 2 which is <a href="https://wordpress.org/plugins/disable-drop-cap/" target="_blank">available in the WordPress plugin directory</a>. You can deactivate and remove the old version once you have installed the new version.</p>';
echo '</div>';
}

add_action('admin_notices', 'disable_drop_cap_update_nag');

add_action('admin_init', ['PAnD', 'init']);
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit6b3a6389b7d72aaaaf51a85d6ae6c5ba::getLoader();
return ComposerAutoloaderInit64d54a85282dbc7f92303909c59370ac::getLoader();
21 changes: 21 additions & 0 deletions vendor/collizo4sky/persist-admin-notices-dismissal/CHANGES.md
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 vendor/collizo4sky/persist-admin-notices-dismissal/README.md
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 vendor/collizo4sky/persist-admin-notices-dismissal/composer.json
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"
]
}
}
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));
Loading

0 comments on commit 4137364

Please sign in to comment.