| 1 |
<?php |
| 2 |
|
| 3 |
namespace PriyoMukul\WPNotice\Utils; |
| 4 |
|
| 5 |
use PriyoMukul\WPNotice\Notices; |
| 6 |
|
| 7 |
class NoticeRemover { |
| 8 |
private static $instance = null; |
| 9 |
|
| 10 |
public static function get_instance( $version ) { |
| 11 |
if ( self::$instance == null ) { |
| 12 |
self::$instance = new static( $version ); |
| 13 |
} |
| 14 |
|
| 15 |
return self::$instance; |
| 16 |
} |
| 17 |
|
| 18 |
public function __construct( $version = '1.0.0', $instanceOf = null ) { |
| 19 |
add_action( 'init', function () use ( $version, $instanceOf ) { |
| 20 |
global $wp_filter; |
| 21 |
|
| 22 |
if ( $instanceOf === null ) { |
| 23 |
$instanceOf = Notices::class; |
| 24 |
} |
| 25 |
|
| 26 |
if(!isset($wp_filter['admin_notices']->callbacks[10])) return; |
| 27 |
|
| 28 |
foreach ( $wp_filter['admin_notices']->callbacks[10] as $callback ) { |
| 29 |
if ( is_array( $callback['function'] ) && $callback['function'][0] instanceof $instanceOf ) { |
| 30 |
$notice = $callback['function'][0]; |
| 31 |
|
| 32 |
if ( $notice->version === $version ) { |
| 33 |
remove_action( 'admin_notices', [ $notice, 'notices' ] ); |
| 34 |
remove_action( 'admin_footer', [ $notice, 'scripts' ] ); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
} ); |
| 39 |
} |
| 40 |
} |