| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Campaigns\Actions; |
| 4 |
|
| 5 |
/** |
| 6 |
* @since 4.0.0 |
| 7 |
*/ |
| 8 |
class AddNewBadgeToAdminMenuItem { |
| 9 |
/** |
| 10 |
* @return void |
| 11 |
*/ |
| 12 |
public function __invoke() |
| 13 |
{ |
| 14 |
// only continue if in admin |
| 15 |
if (!is_admin()) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
// only show badge for existing users who have upgraded from a version prior to 4.0.0 |
| 20 |
if (version_compare((string)get_option('give_version_upgraded_from', '4.0.0'), '4.0.0', '>=')) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
// only show badge if not dismissed |
| 25 |
if (get_option('givewp_new_notification_campaigns_dismissed', false) !== false) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
// add "NEW" badge to the GiveWP menu item |
| 30 |
add_action( 'admin_menu', function() { |
| 31 |
global $menu; |
| 32 |
array_walk($menu, static function (&$item) { |
| 33 |
if ($item[0] === 'GiveWP') { |
| 34 |
$title = $item[0]; |
| 35 |
$item[0] = sprintf('<span>%s </span><span class="update-plugins">%s</span>', $title, __('NEW', 'give')); |
| 36 |
} |
| 37 |
}); |
| 38 |
}); |
| 39 |
|
| 40 |
// dismiss the notice when visiting the campaigns list page |
| 41 |
if (isset($_GET['page']) && $_GET['page'] === 'give-campaigns') { |
| 42 |
update_option('givewp_new_notification_campaigns_dismissed', true); |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|