| 1 |
<?php |
| 2 |
/** |
| 3 |
* Bootstrap for the Jetpack menu-badges package. |
| 4 |
* |
| 5 |
* @package automattic/jetpack-menu-badges |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\Menu_Badges; |
| 9 |
|
| 10 |
/** |
| 11 |
* Wires the notification-count registry into the admin menu and enqueues the client. |
| 12 |
*/ |
| 13 |
class Menu_Badges { |
| 14 |
|
| 15 |
const PACKAGE_VERSION = '0.2.1'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Initialize the package. Idempotent. |
| 19 |
* |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
public static function init() { |
| 23 |
static $done = false; |
| 24 |
if ( $done ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
$done = true; |
| 28 |
|
| 29 |
// Render badges late, after products have registered their menus and counts. |
| 30 |
add_action( 'admin_menu', array( Menu_Renderer::class, 'render' ), 100000 ); |
| 31 |
|
| 32 |
// Client live-update API. |
| 33 |
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_client' ) ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Enqueue the vanilla client that owns live badge updates. |
| 38 |
* |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public static function enqueue_client() { |
| 42 |
\Automattic\Jetpack\Assets::register_script( |
| 43 |
'jetpack-menu-badges', |
| 44 |
'../src/js/menu-badges.js', |
| 45 |
__FILE__, |
| 46 |
array( |
| 47 |
'enqueue' => true, |
| 48 |
'in_footer' => true, |
| 49 |
) |
| 50 |
); |
| 51 |
} |
| 52 |
} |
| 53 |
|