mirror of
https://github.com/afragen/wp-dismiss-notice.git
synced 2025-11-23 10:57:59 +08:00
Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e2c694ca8 | ||
|
|
63fbe9fd01 | ||
|
|
2e47f5fec3 |
2 changed files with 14 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "afragen/wp-dismiss-notice",
|
"name": "afragen/wp-dismiss-notice",
|
||||||
"description": "Library for time dismissible WordPress admin notices.",
|
"description": "Library for time dismissible WordPress admin notices.",
|
||||||
"version": "0.3.4",
|
"version": "0.3.7",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ class WP_Dismiss_Notice {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$js_url = plugins_url( 'js/dismiss-notice.js', __FILE__, 'wp-dismiss-notice' );
|
||||||
|
$version = json_decode( file_get_contents( __DIR__ . '/composer.json' ) )->version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter composer.json vendor directory.
|
* Filter composer.json vendor directory.
|
||||||
* Some people don't use the standard vendor directory.
|
* Some people don't use the standard vendor directory.
|
||||||
|
|
@ -36,26 +39,23 @@ class WP_Dismiss_Notice {
|
||||||
*/
|
*/
|
||||||
$vendor_dir = apply_filters( 'dismiss_notice_vendor_dir', '/vendor' );
|
$vendor_dir = apply_filters( 'dismiss_notice_vendor_dir', '/vendor' );
|
||||||
$composer_js_path = untrailingslashit( $vendor_dir ) . '/afragen/wp-dismiss-notice/js/dismiss-notice.js';
|
$composer_js_path = untrailingslashit( $vendor_dir ) . '/afragen/wp-dismiss-notice/js/dismiss-notice.js';
|
||||||
$plugin_js_url = plugins_url( 'js/dismiss-notice.js', __FILE__, 'wp-dismiss-notice' );
|
|
||||||
|
|
||||||
// Test to get correct URL for JS.
|
$theme_js_url = get_theme_file_uri( $composer_js_path );
|
||||||
$response = get_transient( 'wp-dismiss-notice_jsurl' );
|
$theme_js_file = parse_url( $theme_js_url, PHP_URL_PATH );
|
||||||
if ( ! $response || is_object( $response ) ) {
|
|
||||||
$response = wp_remote_head( $plugin_js_url );
|
if ( file_exists( ABSPATH . $theme_js_file ) ) {
|
||||||
$response = is_wp_error( $response ) ? 0 : wp_remote_retrieve_response_code( $response );
|
$js_url = $theme_js_url;
|
||||||
if ( is_int( $response ) ) {
|
}
|
||||||
set_transient( 'wp-dismiss-notice_jsurl', $response, WEEK_IN_SECONDS );
|
|
||||||
}
|
if ( '/vendor' !== $vendor_dir ) {
|
||||||
|
$js_url = home_url( $composer_js_path );
|
||||||
}
|
}
|
||||||
$js_url = ( 200 === (int) $response )
|
|
||||||
? $plugin_js_url
|
|
||||||
: get_stylesheet_directory_uri() . $composer_js_path;
|
|
||||||
|
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'dismissible-notices',
|
'dismissible-notices',
|
||||||
$js_url,
|
$js_url,
|
||||||
[ 'jquery', 'common' ],
|
[ 'jquery', 'common' ],
|
||||||
false,
|
$version,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue