← All changes
|
vendor/priyomukul/wp-notice/src/Utils/CacheBank.php
+36
-23
3.3.4
→
4.9.3
View file →
| @@ -5,8 +5,10 @@ | ||
| 5 | 5 | use PriyoMukul\WPNotice\Notices; |
| 6 | 6 | |
| 7 | 7 | #[\AllowDynamicProperties] |
| 8 | 8 | class CacheBank { |
| 9 | + use Helper; | |
| 10 | + | |
| 9 | 11 | private static $instance; |
| 10 | 12 | |
| 11 | 13 | private static $accounts = []; |
| 12 | 14 | |
| @@ -91,26 +93,33 @@ | ||
| 91 | 93 | return $this->get_current_account(); |
| 92 | 94 | } |
| 93 | 95 | |
| 94 | 96 | public function notices() { |
| 95 | - if ( get_transient( $this->priority_key ) ) { | |
| 96 | - return; | |
| 97 | + $notice = $this->get(); | |
| 98 | + | |
| 99 | + if( $notice && ! $notice->dev_mode ) { | |
| 100 | + if ( get_transient( $this->priority_key ) ) { | |
| 101 | + return; | |
| 102 | + } | |
| 97 | 103 | } |
| 98 | 104 | |
| 99 | - $notice = $this->get(); | |
| 100 | - | |
| 101 | 105 | if ( $notice instanceof Notices ) { |
| 102 | 106 | $notice->notices(); |
| 103 | 107 | } |
| 104 | 108 | } |
| 105 | 109 | |
| 110 | + /** | |
| 111 | + * @return void | |
| 112 | + */ | |
| 106 | 113 | public function scripts() { |
| 107 | - if ( get_transient( $this->priority_key ) ) { | |
| 108 | - return; | |
| 114 | + $notice = $this->get(); | |
| 115 | + | |
| 116 | + if( $notice && ! $notice->dev_mode ) { | |
| 117 | + if ( get_transient( $this->priority_key ) ) { | |
| 118 | + return; | |
| 119 | + } | |
| 109 | 120 | } |
| 110 | 121 | |
| 111 | - $notice = $this->get(); | |
| 112 | - | |
| 113 | 122 | if ( $notice instanceof Notices ) { |
| 114 | 123 | $notice->scripts(); |
| 115 | 124 | } |
| 116 | 125 | } |
| @@ -124,24 +133,28 @@ | ||
| 124 | 133 | * |
| 125 | 134 | * @return array |
| 126 | 135 | */ |
| 127 | 136 | private function eligible_notices( $notices = [], $queue = [] ) { |
| 128 | - $_sorted_queue = []; | |
| 137 | + return $this->get_sorted_queue($notices, $queue); | |
| 138 | + } | |
| 129 | 139 | |
| 130 | - if ( ! empty ( $queue ) ) { | |
| 131 | - array_walk( $queue, function ( $value, $key ) use ( &$_sorted_queue, $notices ) { | |
| 132 | - $notice = isset( $notices[ $key ] ) ? $notices[ $key ] : null; | |
| 133 | - if ( ! is_null( $notice ) ) { | |
| 134 | - if ( ! $notice->dismiss->is_dismissed() && ! $notice->is_expired() ) { | |
| 135 | - $_sorted_queue[ $notice->options( 'start' ) ] = $key; | |
| 136 | - } | |
| 137 | - } | |
| 138 | - } ); | |
| 139 | - } | |
| 140 | + public function clear_notices_in_( $screens, $app, $re_initiate = false ) { | |
| 141 | + add_action( 'in_admin_header', function() use( $screens, $app, $re_initiate ) { | |
| 142 | + $this->clear( $screens, $app, $re_initiate ); | |
| 143 | + } ); | |
| 144 | + } | |
| 140 | 145 | |
| 141 | - ksort( $_sorted_queue ); | |
| 146 | + public function clear( $screens, $app, $re_initiate = false ) { | |
| 147 | + $current_screen = get_current_screen(); | |
| 142 | 148 | |
| 143 | - return $_sorted_queue; | |
| 149 | + if( in_array( $current_screen->id, $screens, true ) ) { | |
| 150 | + remove_all_actions( 'admin_notices' ); | |
| 151 | + | |
| 152 | + if( $re_initiate ) { | |
| 153 | + self::$accounts = []; | |
| 154 | + self::$instance = new self(); | |
| 155 | + self::$instance->create_account( $app ); | |
| 156 | + self::$instance->calculate_deposits( $app ); | |
| 157 | + } | |
| 158 | + } | |
| 144 | 159 | } |
| 145 | - | |
| 146 | - | |
| 147 | 160 | } |