2019-12-18 13:12:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Plugin Name: WooCommerce Admin Important Notice Example
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin
|
2019-12-18 13:12:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the JS.
|
|
|
|
*/
|
|
|
|
function wc_admin_important_notice_register_script() {
|
2022-03-09 14:04:34 +00:00
|
|
|
if ( ! class_exists( 'Automattic\WooCommerce\Internal\Admin\Loader' ) ) {
|
2019-12-18 13:12:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2022-03-09 14:04:34 +00:00
|
|
|
! \Automattic\WooCommerce\Admin\PageController::is_admin_page() &&
|
|
|
|
! \Automattic\WooCommerce\Admin\PageController::is_embed_page()
|
2019-12-18 13:12:32 +00:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-23 22:10:32 +00:00
|
|
|
$asset_file = require __DIR__ . '/dist/index.asset.php';
|
2019-12-18 13:12:32 +00:00
|
|
|
wp_register_script(
|
|
|
|
'wc-admin-important-notice',
|
|
|
|
plugins_url( '/dist/index.js', __FILE__ ),
|
2021-03-23 22:10:32 +00:00
|
|
|
$asset_file['dependencies'],
|
|
|
|
$asset_file['version'],
|
2019-12-18 13:12:32 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_enqueue_script( 'wc-admin-important-notice' );
|
|
|
|
}
|
|
|
|
add_action( 'admin_enqueue_scripts', 'wc_admin_important_notice_register_script' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an Admin Notice we want to remain visible.
|
|
|
|
*/
|
|
|
|
function wc_admin_add_important_notice() {
|
|
|
|
?>
|
|
|
|
<div class="updated woocommerce-message">
|
|
|
|
<p class="notice-text">Important notice targeted by inspecting DOM.</p>
|
|
|
|
</div>
|
|
|
|
<div class="updated woocommerce-admin woocommerce-message">
|
2021-03-23 22:10:32 +00:00
|
|
|
<p>Important notice targeted by class.</p>
|
2019-12-18 13:12:32 +00:00
|
|
|
</div>
|
|
|
|
<div class="updated woocommerce-admin woocommerce-message ok-to-hide">
|
|
|
|
<p>Notice excluded from importance clause targeted by class.</p>
|
|
|
|
</div>
|
|
|
|
<div id="woocommerce-admin-important-notice" class="updated woocommerce-message">
|
|
|
|
<p>Important notice targeted by ID.</p>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
add_action( 'admin_notices', 'wc_admin_add_important_notice' );
|