← All changes
|
vendor/team-updraft/common-libs/src/updraft-notices/updraft-notices.php
+59
-1
3.7.0
→
trunk
View file →
| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (!defined('ABSPATH')) die('No direct access allowed'); |
| 4 | 4 | |
| 5 | -abstract class Updraft_Notices_1_2 { | |
| 5 | +abstract class Updraft_Notices_1_3 { | |
| 6 | 6 | |
| 7 | + protected $widget_title; | |
| 8 | + | |
| 7 | 9 | protected $notices_content; |
| 8 | 10 | |
| 9 | 11 | // These variables are just short-hands to be used in advert content. |
| 10 | 12 | protected $dashboard_top = array('top'); |
| @@ -10,8 +12,10 @@ | ||
| 10 | 12 | protected $dashboard_top = array('top'); |
| 11 | 13 | |
| 12 | 14 | protected $dashboard_top_or_report = array('top', 'report', 'report-plain'); |
| 13 | 15 | |
| 16 | + protected $dashboard_top_or_report_or_widget = array('top', 'report', 'report-plain', 'widget'); | |
| 17 | + | |
| 14 | 18 | protected $dashboard_bottom_or_report = array('bottom', 'report', 'report-plain'); |
| 15 | 19 | |
| 16 | 20 | protected $anywhere = array('top', 'bottom', 'report', 'report-plain'); |
| 17 | 21 | |
| @@ -216,5 +220,59 @@ | ||
| 216 | 220 | * |
| 217 | 221 | * @return mixed |
| 218 | 222 | */ |
| 219 | 223 | abstract protected function check_notice_dismissed($dismiss_time); |
| 224 | + | |
| 225 | + /** | |
| 226 | + * This function will add the seasonal notice WordPress dashboard widget. | |
| 227 | + * | |
| 228 | + * @return void | |
| 229 | + */ | |
| 230 | + public function seasonal_widget() { | |
| 231 | + global $wp_meta_boxes; | |
| 232 | + | |
| 233 | + $notice = $this->do_notice(false, 'widget', true); | |
| 234 | + if (!$notice) return; | |
| 235 | + | |
| 236 | + $widget_id = 'updraft-seasonal-widget'; | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * We only want to display one seasonal notice across all our plugins, | |
| 240 | + * so here we have a random chance to allow this plugin to replace the existing notice with it's own | |
| 241 | + */ | |
| 242 | + $random_number = rand(1, 50); | |
| 243 | + | |
| 244 | + if (isset($wp_meta_boxes['dashboard']['normal']['core'][$widget_id]) && 25 >= $random_number) return; | |
| 245 | + | |
| 246 | + if (isset($wp_meta_boxes['dashboard']['normal']['core'][$widget_id])) { | |
| 247 | + unset($wp_meta_boxes['dashboard']['normal']['core'][$widget_id]); | |
| 248 | + } | |
| 249 | + | |
| 250 | + $this->widget_enqueue(); | |
| 251 | + | |
| 252 | + if (!isset($wp_meta_boxes['dashboard']['normal']['core'][$widget_id])) { | |
| 253 | + // Initialization of the WordPress dashboard widget. | |
| 254 | + wp_add_dashboard_widget($widget_id, $this->widget_title, array($this, 'widget_view'), null, compact('notice')); | |
| 255 | + } | |
| 256 | + | |
| 257 | + } | |
| 258 | + | |
| 259 | + /** | |
| 260 | + * This function will add the dashboard widget output. | |
| 261 | + * | |
| 262 | + * @param Int $post post ID | |
| 263 | + * @param Array $callback_args callback args | |
| 264 | + * | |
| 265 | + * @return void | |
| 266 | + */ | |
| 267 | + public function widget_view($post, $callback_args) { | |
| 268 | + extract($callback_args['args']); | |
| 269 | + echo $notice; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable | |
| 270 | + } | |
| 271 | + | |
| 272 | + /** | |
| 273 | + * This function will enqueue the WordPress dashboard widget styles or scripts. | |
| 274 | + * | |
| 275 | + * @return void | |
| 276 | + */ | |
| 277 | + abstract protected function widget_enqueue(); | |
| 220 | 278 | } |