Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.48% |
19 / 21 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
Login_Assets | |
90.48% |
19 / 21 |
|
33.33% |
1 / 3 |
5.02 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
enqueue_styles | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
enqueue_scripts | |
94.12% |
16 / 17 |
|
0.00% |
0 / 1 |
2.00 |
1 | <?php |
2 | /** |
3 | * The login screen specific functionality of the plugin. |
4 | * |
5 | * @link https://BrianHenry.ie |
6 | * @since 1.7.0 |
7 | * |
8 | * @package brianhenryie/bh-wp-autologin-urls |
9 | */ |
10 | |
11 | namespace BrianHenryIE\WP_Autologin_URLs\Login; |
12 | |
13 | use BrianHenryIE\WP_Autologin_URLs\Settings_Interface; |
14 | |
15 | /** |
16 | * The login screen functionality of the plugin. |
17 | */ |
18 | class Login_Assets { |
19 | |
20 | /** |
21 | * Needed for the css/js handle, and the version for cache invalidation. |
22 | * |
23 | * @var Settings_Interface |
24 | */ |
25 | protected Settings_Interface $settings; |
26 | |
27 | /** |
28 | * Constructor |
29 | * |
30 | * @param Settings_Interface $settings Plugin settings for slug and version. |
31 | */ |
32 | public function __construct( Settings_Interface $settings ) { |
33 | $this->settings = $settings; |
34 | } |
35 | |
36 | /** |
37 | * Register the stylesheets for the admin area. |
38 | * |
39 | * @hooked admin_enqueue_scripts |
40 | * |
41 | * @since 1.0.0 |
42 | */ |
43 | public function enqueue_styles(): void { |
44 | |
45 | if ( ! $this->settings->is_magic_link_enabled() ) { |
46 | return; |
47 | } |
48 | |
49 | wp_enqueue_style( $this->settings->get_plugin_slug(), plugin_dir_url( $this->settings->get_plugin_basename() ) . 'assets/bh-wp-autologin-urls-login.css', array(), $this->settings->get_plugin_version(), 'all' ); |
50 | } |
51 | |
52 | /** |
53 | * Register the JavaScript for the admin area. |
54 | * |
55 | * @hooked admin_enqueue_scripts. |
56 | * |
57 | * @since 1.0.0 |
58 | */ |
59 | public function enqueue_scripts(): void { |
60 | |
61 | if ( ! $this->settings->is_magic_link_enabled() ) { |
62 | return; |
63 | } |
64 | |
65 | $handle = 'bh-wp-autologin-urls-login-screen'; |
66 | |
67 | wp_enqueue_script( $handle, plugin_dir_url( $this->settings->get_plugin_basename() ) . 'assets/bh-wp-autologin-urls-login.js', array( 'jquery' ), $this->settings->get_plugin_version(), true ); |
68 | |
69 | $ajax_data = array( |
70 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
71 | '_wp_nonce' => wp_create_nonce( Login_Ajax::class ), |
72 | ); |
73 | $ajax_data_json = wp_json_encode( $ajax_data, JSON_PRETTY_PRINT ); |
74 | |
75 | $script = <<<EOD |
76 | var bh_wp_autologin_urls = $ajax_data_json; |
77 | EOD; |
78 | |
79 | wp_add_inline_script( |
80 | $handle, |
81 | $script, |
82 | 'before' |
83 | ); |
84 | } |
85 | } |