| @@ -54,20 +54,29 @@ | ||
| 54 | 54 | /** |
| 55 | 55 | * @param string $id |
| 56 | 56 | * @param string $title |
| 57 | 57 | * @param string $module_unique_affix |
| 58 | + * @param bool $is_network_and_blog_admins Whether or not the message should be shown both on network and | |
| 59 | + * blog admin pages. | |
| 58 | 60 | * |
| 59 | 61 | * @return FS_Admin_Notices |
| 60 | 62 | */ |
| 61 | - static function instance( $id, $title = '', $module_unique_affix = '' ) { | |
| 63 | + static function instance( $id, $title = '', $module_unique_affix = '', $is_network_and_blog_admins = false ) { | |
| 62 | 64 | if ( ! isset( self::$_instances[ $id ] ) ) { |
| 63 | - self::$_instances[ $id ] = new FS_Admin_Notices( $id, $title, $module_unique_affix ); | |
| 65 | + self::$_instances[ $id ] = new FS_Admin_Notices( $id, $title, $module_unique_affix, $is_network_and_blog_admins ); | |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | return self::$_instances[ $id ]; |
| 67 | 69 | } |
| 68 | 70 | |
| 69 | - protected function __construct( $id, $title = '', $module_unique_affix = '' ) { | |
| 71 | + /** | |
| 72 | + * @param string $id | |
| 73 | + * @param string $title | |
| 74 | + * @param string $module_unique_affix | |
| 75 | + * @param bool $is_network_and_blog_admins Whether or not the message should be shown both on network and | |
| 76 | + * blog admin pages. | |
| 77 | + */ | |
| 78 | + protected function __construct( $id, $title = '', $module_unique_affix = '', $is_network_and_blog_admins = false ) { | |
| 70 | 79 | $this->_id = $id; |
| 71 | 80 | $this->_title = $title; |
| 72 | 81 | $this->_module_unique_affix = $module_unique_affix; |
| 73 | 82 | $this->_is_multisite = is_multisite(); |
| @@ -78,8 +87,9 @@ | ||
| 78 | 87 | $this->_network_notices = FS_Admin_Notice_Manager::instance( |
| 79 | 88 | $id, |
| 80 | 89 | $title, |
| 81 | 90 | $module_unique_affix, |
| 91 | + $is_network_and_blog_admins, | |
| 82 | 92 | true |
| 83 | 93 | ); |
| 84 | 94 | } |
| 85 | 95 | |
| @@ -86,8 +96,9 @@ | ||
| 86 | 96 | $this->_notices = FS_Admin_Notice_Manager::instance( |
| 87 | 97 | $id, |
| 88 | 98 | $title, |
| 89 | 99 | $module_unique_affix, |
| 100 | + false, | |
| 90 | 101 | $this->_blog_id |
| 91 | 102 | ); |
| 92 | 103 | } |
| 93 | 104 | |
| @@ -113,15 +124,12 @@ | ||
| 113 | 124 | $type = 'success', |
| 114 | 125 | $is_sticky = false, |
| 115 | 126 | $id = '', |
| 116 | 127 | $store_if_sticky = true, |
| 117 | - $network_level_or_blog_id = null | |
| 128 | + $network_level_or_blog_id = null, | |
| 129 | + $is_dimissible = null | |
| 118 | 130 | ) { |
| 119 | - if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) { | |
| 120 | - $notices = $this->_network_notices; | |
| 121 | - } else { | |
| 122 | - $notices = $this->get_site_notices( $network_level_or_blog_id ); | |
| 123 | - } | |
| 131 | + $notices = $this->get_site_or_network_notices( $id, $network_level_or_blog_id ); | |
| 124 | 132 | |
| 125 | 133 | $notices->add( |
| 126 | 134 | $message, |
| 127 | 135 | $title, |
| @@ -127,9 +135,13 @@ | ||
| 127 | 135 | $title, |
| 128 | 136 | $type, |
| 129 | 137 | $is_sticky, |
| 130 | 138 | $id, |
| 131 | - $store_if_sticky | |
| 139 | + $store_if_sticky, | |
| 140 | + null, | |
| 141 | + null, | |
| 142 | + false, | |
| 143 | + $is_dimissible | |
| 132 | 144 | ); |
| 133 | 145 | } |
| 134 | 146 | |
| 135 | 147 | /** |
| @@ -137,10 +149,11 @@ | ||
| 137 | 149 | * @since 1.0.7 |
| 138 | 150 | * |
| 139 | 151 | * @param string|string[] $ids |
| 140 | 152 | * @param int|null $network_level_or_blog_id |
| 153 | + * @param bool $store | |
| 141 | 154 | */ |
| 142 | - function remove_sticky( $ids, $network_level_or_blog_id = null ) { | |
| 155 | + function remove_sticky( $ids, $network_level_or_blog_id = null, $store = true ) { | |
| 143 | 156 | if ( ! is_array( $ids ) ) { |
| 144 | 157 | $ids = array( $ids ); |
| 145 | 158 | } |
| 146 | 159 | |
| @@ -149,9 +162,9 @@ | ||
| 149 | 162 | } else { |
| 150 | 163 | $notices = $this->get_site_notices( $network_level_or_blog_id ); |
| 151 | 164 | } |
| 152 | 165 | |
| 153 | - return $notices->remove_sticky( $ids ); | |
| 166 | + return $notices->remove_sticky( $ids, $store ); | |
| 154 | 167 | } |
| 155 | 168 | |
| 156 | 169 | /** |
| 157 | 170 | * Check if sticky message exists by id. |
| @@ -164,13 +177,9 @@ | ||
| 164 | 177 | * |
| 165 | 178 | * @return bool |
| 166 | 179 | */ |
| 167 | 180 | function has_sticky( $id, $network_level_or_blog_id = null ) { |
| 168 | - if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) { | |
| 169 | - $notices = $this->_network_notices; | |
| 170 | - } else { | |
| 171 | - $notices = $this->get_site_notices( $network_level_or_blog_id ); | |
| 172 | - } | |
| 181 | + $notices = $this->get_site_or_network_notices( $id, $network_level_or_blog_id ); | |
| 173 | 182 | |
| 174 | 183 | return $notices->has_sticky( $id ); |
| 175 | 184 | } |
| 176 | 185 | |
| @@ -179,13 +188,18 @@ | ||
| 179 | 188 | * |
| 180 | 189 | * @author Vova Feldman (@svovaf) |
| 181 | 190 | * @since 1.0.7 |
| 182 | 191 | * |
| 183 | - * @param string $message | |
| 184 | - * @param string $id Message ID | |
| 185 | - * @param string $title | |
| 186 | - * @param string $type | |
| 187 | - * @param int|null $network_level_or_blog_id | |
| 192 | + * @param string $message | |
| 193 | + * @param string $id Message ID | |
| 194 | + * @param string $title | |
| 195 | + * @param string $type | |
| 196 | + * @param int|null $network_level_or_blog_id | |
| 197 | + * @param number|null $wp_user_id | |
| 198 | + * @param string|null $plugin_title | |
| 199 | + * @param bool $is_network_and_blog_admins Whether or not the message should be shown both on network and | |
| 200 | + * blog admin pages. | |
| 201 | + * @param bool $is_dismissible | |
| 188 | 202 | */ |
| 189 | 203 | function add_sticky( |
| 190 | 204 | $message, |
| 191 | 205 | $id, |
| @@ -190,20 +204,38 @@ | ||
| 190 | 204 | $message, |
| 191 | 205 | $id, |
| 192 | 206 | $title = '', |
| 193 | 207 | $type = 'success', |
| 194 | - $network_level_or_blog_id = null | |
| 208 | + $network_level_or_blog_id = null, | |
| 209 | + $wp_user_id = null, | |
| 210 | + $plugin_title = null, | |
| 211 | + $is_network_and_blog_admins = false, | |
| 212 | + $is_dismissible = true, | |
| 213 | + $data = array() | |
| 195 | 214 | ) { |
| 196 | - if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) { | |
| 197 | - $notices = $this->_network_notices; | |
| 198 | - } else { | |
| 199 | - $notices = $this->get_site_notices( $network_level_or_blog_id ); | |
| 200 | - } | |
| 215 | + $notices = $this->get_site_or_network_notices( $id, $network_level_or_blog_id ); | |
| 201 | 216 | |
| 202 | - $notices->add_sticky( $message, $id, $title, $type ); | |
| 217 | + $notices->add_sticky( $message, $id, $title, $type, $wp_user_id, $plugin_title, $is_network_and_blog_admins, $is_dismissible, $data ); | |
| 203 | 218 | } |
| 204 | 219 | |
| 205 | 220 | /** |
| 221 | + * Retrieves the data of a sticky notice. | |
| 222 | + * | |
| 223 | + * @author Leo Fajardo (@leorw) | |
| 224 | + * @since 2.4.3 | |
| 225 | + * | |
| 226 | + * @param string $id | |
| 227 | + * @param int|null $network_level_or_blog_id | |
| 228 | + * | |
| 229 | + * @return array|null | |
| 230 | + */ | |
| 231 | + function get_sticky( $id, $network_level_or_blog_id ) { | |
| 232 | + $notices = $this->get_site_or_network_notices( $id, $network_level_or_blog_id ); | |
| 233 | + | |
| 234 | + return $notices->get_sticky( $id ); | |
| 235 | + } | |
| 236 | + | |
| 237 | + /** | |
| 206 | 238 | * Clear all sticky messages. |
| 207 | 239 | * |
| 208 | 240 | * @author Vova Feldman (@svovaf) |
| 209 | 241 | * @since 2.0.0 |
| @@ -208,10 +240,11 @@ | ||
| 208 | 240 | * @author Vova Feldman (@svovaf) |
| 209 | 241 | * @since 2.0.0 |
| 210 | 242 | * |
| 211 | 243 | * @param int|null $network_level_or_blog_id |
| 244 | + * @param bool $is_temporary | |
| 212 | 245 | */ |
| 213 | - function clear_all_sticky( $network_level_or_blog_id = null ) { | |
| 246 | + function clear_all_sticky( $network_level_or_blog_id = null, $is_temporary = false ) { | |
| 214 | 247 | if ( ! $this->_is_multisite || |
| 215 | 248 | false === $network_level_or_blog_id || |
| 216 | 249 | 0 == $network_level_or_blog_id || |
| 217 | 250 | is_null( $network_level_or_blog_id ) |
| @@ -216,15 +249,15 @@ | ||
| 216 | 249 | 0 == $network_level_or_blog_id || |
| 217 | 250 | is_null( $network_level_or_blog_id ) |
| 218 | 251 | ) { |
| 219 | 252 | $notices = $this->get_site_notices( $network_level_or_blog_id ); |
| 220 | - $notices->clear_all_sticky(); | |
| 253 | + $notices->clear_all_sticky( $is_temporary ); | |
| 221 | 254 | } |
| 222 | 255 | |
| 223 | 256 | if ( $this->_is_multisite && |
| 224 | 257 | ( true === $network_level_or_blog_id || is_null( $network_level_or_blog_id ) ) |
| 225 | 258 | ) { |
| 226 | - $this->_network_notices->clear_all_sticky(); | |
| 259 | + $this->_network_notices->clear_all_sticky( $is_temporary ); | |
| 227 | 260 | } |
| 228 | 261 | } |
| 229 | 262 | |
| 230 | 263 | /** |
| @@ -263,8 +296,9 @@ | ||
| 263 | 296 | return FS_Admin_Notice_Manager::instance( |
| 264 | 297 | $this->_id, |
| 265 | 298 | $this->_title, |
| 266 | 299 | $this->_module_unique_affix, |
| 300 | + false, | |
| 267 | 301 | $blog_id |
| 268 | 302 | ); |
| 269 | 303 | } |
| 270 | 304 | |
| @@ -295,8 +329,25 @@ | ||
| 295 | 329 | return $network_level_or_blog_id; |
| 296 | 330 | } |
| 297 | 331 | |
| 298 | 332 | return fs_is_network_admin(); |
| 333 | + } | |
| 334 | + | |
| 335 | + /** | |
| 336 | + * Retrieves an instance of FS_Admin_Notice_Manager. | |
| 337 | + * | |
| 338 | + * @author Leo Fajardo (@leorw) | |
| 339 | + * @since 2.5.0 | |
| 340 | + * | |
| 341 | + * @param string $id | |
| 342 | + * @param int|null $network_level_or_blog_id | |
| 343 | + * | |
| 344 | + * @return FS_Admin_Notice_Manager | |
| 345 | + */ | |
| 346 | + private function get_site_or_network_notices( $id, $network_level_or_blog_id ) { | |
| 347 | + return $this->should_use_network_notices( $id, $network_level_or_blog_id ) ? | |
| 348 | + $this->_network_notices : | |
| 349 | + $this->get_site_notices( $network_level_or_blog_id ); | |
| 299 | 350 | } |
| 300 | 351 | |
| 301 | 352 | #endregion |
| 302 | 353 | } |