/** * Render the javascript to handle the notice "dismiss" functionality * * @since 3.0.0 */ public function render_admin_notice_js() { // if there were no notices, or we've already rendered the js, there's nothing to do if (empty($this->admin_notices) || self::$admin_notice_js_rendered) { return; } self::$admin_notice_js_rendered = true; ob_start(); ?> // Log dismissed notices $( '.js-wc-plugin-framework-admin-notice' ).on( 'click.wp-dismiss-notice', '.notice-dismiss', function( e ) { var $notice = $( this ).closest( '.js-wc-plugin-framework-admin-notice' ); log_dismissed_notice( $( $notice ).data( 'plugin-id' ), $( $notice ).data( 'message-id' ) ); } ); // Log and hide legacy notices $( 'a.js-wc-plugin-framework-notice-dismiss' ).click( function( e ) { e.preventDefault(); var $notice = $( this ).closest( '.js-wc-plugin-framework-admin-notice' ); log_dismissed_notice( $( $notice ).data( 'plugin-id' ), $( $notice ).data( 'message-id' ) ); $( $notice ).fadeOut(); } ); function log_dismissed_notice( pluginID, messageID ) { $.get( ajaxurl, { action: 'wc_plugin_framework_' + pluginID + '_dismiss_notice', messageid: messageID } ); } // move any delayed notices up into position .show(); $( '.js-wc-plugin-framework-admin-notice:hidden' ).insertAfter( '.js-wc-plugin-framework-admin-notice-placeholder' ).show(); <?php $javascript = ob_get_clean(); wc_enqueue_js($javascript); }
/** * Render the javascript to handle the notice "dismiss" functionality * * @since 3.0.0 */ public function render_admin_notice_js() { // if there were no notices, or we've already rendered the js, there's nothing to do if (empty($this->admin_notices) || self::$admin_notice_js_rendered) { return; } self::$admin_notice_js_rendered = true; ob_start(); ?> // hide notice $( 'a.js-wc-plugin-framework-notice-dismiss' ).click( function() { $.get( ajaxurl, { action: 'wc_plugin_framework_' + $( this ).closest( '.js-wc-plugin-framework-admin-notice' ).data( 'plugin-id') + '_dismiss_notice', messageid: $( this ).data( 'message-id' ) } ); $( this ).closest( 'div.js-wc-plugin-framework-admin-notice' ).fadeOut(); return false; } ); // move any delayed notices up into position .show(); $( '.js-wc-plugin-framework-admin-notice:hidden' ).insertAfter( '.js-wc-plugin-framework-admin-notice-placeholder' ).show(); <?php $javascript = ob_get_clean(); wc_enqueue_js($javascript); }