Compare commits

...

13 commits
0.2.2 ... main

Author SHA1 Message Date
Andy Fragen
3e2c694ca8 add test for install to theme 2023-05-30 14:45:15 -07:00
Andy Fragen
63fbe9fd01 oops, remove test code 2023-05-30 13:35:45 -07:00
Andy Fragen
2e47f5fec3 load JS where it exists
stop messing with tests for URL and transients
2023-05-30 13:29:06 -07:00
Andy Fragen
a195d3badb save int to transient, check for object
object is stale cache
2023-04-05 13:00:28 -07:00
Andy Fragen
606c0d5222 cast to int 2023-04-04 18:03:20 -07:00
Andy Fragen
5a3dd3198c parse response and save 2023-03-30 14:37:09 -07:00
Andy Fragen
2c421b09e8 use JSON as safe data storage
Bypass unserialize from get_transient wanting to load class of stored object
2023-03-30 13:06:00 -07:00
Andy Fragen
8b690bc045 update to not conflict with users of PaND 2023-01-02 11:27:07 -08:00
Andy Fragen
d6511c4eea add filter for non-standard composer vendor-dir 2022-07-25 08:44:19 -07:00
Andy Fragen
71029356cc more specific transient name 2022-05-16 09:32:39 -07:00
Andy Fragen
a5c05306a4 save wp_remote_get check for a week in transient 2022-05-15 17:35:10 -07:00
Andy Fragen
21949732f1 bump 2021-12-19 13:53:57 -08:00
Andy Fragen
3b9d3b775f slightly better test for JS, allow for WP_Error
WP_Error assumes JS in plugin's vendor folder.
2021-12-19 13:50:51 -08:00
4 changed files with 35 additions and 9 deletions

View file

@ -18,3 +18,13 @@ Example using a 14 day dismissible notice.
```html
<div class="notice-warning notice is-dismissible" data-dismissible="my_admin_notice_<hash>-14">...</div>
```

Use the filter `dismiss_notice_vendor_dir` if you have set the composer `vendor-dir` to a non-standard location.

/**
* Filter composer.json vendor directory.
* Some people don't use the standard vendor directory.
*
* @param string Composer vendor directory.
*/
$vendor_dir = apply_filters( 'dismiss_notice_vendor_dir', '/vendor' );

View file

@ -1,7 +1,7 @@
{
"name": "afragen/wp-dismiss-notice",
"description": "Library for time dismissible WordPress admin notices.",
"version": "0.2.2",
"version": "0.3.7",
"type": "library",
"license": "MIT",
"authors": [

View file

@ -23,7 +23,7 @@
option_name = attr_value.join('-');

data = {
'action': 'dismiss_admin_notice',
'action': 'wp_dismiss_notice',
'option_name': option_name,
'dismissible_length': dismissible_length,
'nonce': window.wp_dismiss_notice.nonce

View file

@ -16,7 +16,7 @@ class WP_Dismiss_Notice {
*/
public static function init() {
add_action( 'admin_enqueue_scripts', [ __CLASS__, 'load_script' ] );
add_action( 'wp_ajax_dismiss_admin_notice', [ __CLASS__, 'dismiss_admin_notice' ] );
add_action( 'wp_ajax_wp_dismiss_notice', [ __CLASS__, 'dismiss_admin_notice' ] );
}

/**
@ -28,18 +28,34 @@ class WP_Dismiss_Notice {
return;
}

$composer_js_path = '/vendor/afragen/wp-dismiss-notice/js/dismiss-notice.js';
$plugin_js_url = plugins_url( 'js/dismiss-notice.js', __FILE__, 'wp-dismiss-notice' );
$js_url = plugins_url( 'js/dismiss-notice.js', __FILE__, 'wp-dismiss-notice' );
$version = json_decode( file_get_contents( __DIR__ . '/composer.json' ) )->version;

$js_url = 200 === wp_remote_retrieve_response_code( wp_remote_head( $plugin_js_url ) )
? $plugin_js_url
: get_stylesheet_directory_uri() . $composer_js_path;
/**
* Filter composer.json vendor directory.
* Some people don't use the standard vendor directory.
*
* @param string Composer vendor directory.
*/
$vendor_dir = apply_filters( 'dismiss_notice_vendor_dir', '/vendor' );
$composer_js_path = untrailingslashit( $vendor_dir ) . '/afragen/wp-dismiss-notice/js/dismiss-notice.js';

$theme_js_url = get_theme_file_uri( $composer_js_path );
$theme_js_file = parse_url( $theme_js_url, PHP_URL_PATH );

if ( file_exists( ABSPATH . $theme_js_file ) ) {
$js_url = $theme_js_url;
}

if ( '/vendor' !== $vendor_dir ) {
$js_url = home_url( $composer_js_path );
}

wp_enqueue_script(
'dismissible-notices',
$js_url,
[ 'jquery', 'common' ],
false,
$version,
true
);