Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Admin_Assets | |
0.00% |
0 / 29 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register_script | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| enqueue_script | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
6 | |||
| enqueue_styles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Enqueue the JS for the licence tab and add the nonce for the AJAX requests. |
| 4 | * |
| 5 | * @package brianhenryie/bh-wp-plugin-updater |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\WP_Plugin_Updater\Admin; |
| 9 | |
| 10 | use BrianHenryIE\WP_Plugin_Updater\API_Interface; |
| 11 | use BrianHenryIE\WP_Plugin_Updater\Licence; |
| 12 | use BrianHenryIE\WP_Plugin_Updater\Settings_Interface; |
| 13 | |
| 14 | use function BrianHenryIE\WP_Plugin_Updater\str_dash_to_next_capitalised_first_lower; |
| 15 | |
| 16 | class Admin_Assets { |
| 17 | |
| 18 | public function __construct( |
| 19 | protected API_Interface $api, |
| 20 | protected Settings_Interface $settings, |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | public function register_script(): void { |
| 25 | } |
| 26 | |
| 27 | public function enqueue_script(): void { |
| 28 | |
| 29 | $script_handle = "{$this->settings->get_plugin_slug()}-licence"; |
| 30 | |
| 31 | $asset_file = include dirname( __DIR__, 2 ) . '/build/index.asset.php'; |
| 32 | |
| 33 | wp_enqueue_script( |
| 34 | $script_handle, |
| 35 | plugins_url( '../../build/index.js', __FILE__ ), |
| 36 | $asset_file['dependencies'], |
| 37 | $asset_file['version'], |
| 38 | true |
| 39 | ); |
| 40 | |
| 41 | try { |
| 42 | $licence_details = $this->api->get_licence_details(); |
| 43 | } catch ( \Exception $e ) { |
| 44 | $licence_details = new Licence(); |
| 45 | } |
| 46 | |
| 47 | $data = wp_json_encode( |
| 48 | array( |
| 49 | 'restUrl' => rest_url( "{$this->settings->get_rest_base()}/v1" ), |
| 50 | 'nonce' => wp_create_nonce( \BrianHenryIE\WP_Plugin_Updater\WP_Includes\Rest::class ), |
| 51 | 'licence_details' => $licence_details, |
| 52 | // 'licence_details' => $api->get_licence_details(), |
| 53 | ) |
| 54 | ); |
| 55 | |
| 56 | $script_var_name = str_dash_to_next_capitalised_first_lower( $script_handle ); |
| 57 | |
| 58 | wp_add_inline_script( |
| 59 | $script_handle, |
| 60 | "const {$script_var_name} = {$data};", |
| 61 | 'before' |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @hooked admin_enqueue_scripts |
| 67 | */ |
| 68 | public function enqueue_styles(): void { |
| 69 | |
| 70 | wp_enqueue_style( 'wp-components' ); |
| 71 | } |
| 72 | } |