Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Announcements | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
4.01 | |
0.00% |
0 / 1 |
| register_script_module | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
4.01 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jetpack Announcements: a channel to tell users what is new. |
| 4 | * |
| 5 | * @package automattic/jetpack-announcements |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Announcements; |
| 9 | |
| 10 | /** |
| 11 | * The package itself. `actions.php` hooks what it serves. |
| 12 | */ |
| 13 | class Announcements { |
| 14 | |
| 15 | const PACKAGE_VERSION = '0.1.0-alpha'; |
| 16 | |
| 17 | /** |
| 18 | * Id of the script module a host imports: the name of the js-package that holds its contract. |
| 19 | */ |
| 20 | const SCRIPT_MODULE_ID = '@automattic/jetpack-announcements'; |
| 21 | |
| 22 | /** |
| 23 | * Registers the What's new module under the name hosts import, with its translations. Hooked on `admin_init`. |
| 24 | * |
| 25 | * Always the minified bundle: a production build replaces the other one with a stub. |
| 26 | * Its classic script dependencies are not enqueued, as wp-build leaves them to the page. |
| 27 | * |
| 28 | * @param string $asset_file Optional. Asset file of the built module. Defaults to the package's own. |
| 29 | * @return void |
| 30 | */ |
| 31 | public static function register_script_module( $asset_file = '' ) { |
| 32 | if ( '' === $asset_file ) { |
| 33 | $asset_file = dirname( __DIR__ ) . '/build/modules/whats-new/index.min.asset.php'; |
| 34 | } |
| 35 | |
| 36 | if ( ! file_exists( $asset_file ) ) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | $asset = require $asset_file; |
| 41 | |
| 42 | wp_register_script_module( |
| 43 | self::SCRIPT_MODULE_ID, |
| 44 | plugins_url( 'index.min.js', $asset_file ), |
| 45 | $asset['module_dependencies'] ?? array(), |
| 46 | $asset['version'] ?? false |
| 47 | ); |
| 48 | |
| 49 | // WordPress 7.0 prints the translations of a module. On an older core the surface stays in English. |
| 50 | if ( function_exists( 'wp_set_script_module_translations' ) ) { |
| 51 | wp_set_script_module_translations( self::SCRIPT_MODULE_ID, 'jetpack-announcements' ); |
| 52 | } |
| 53 | } |
| 54 | } |