Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
User_Edit | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
make_password_available_on_user_page | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * The additions to the admin user-edit page. |
4 | * |
5 | * TODO: Send magic login email button. |
6 | * |
7 | * @link https://BrianHenry.ie |
8 | * @since 1.2.0 |
9 | * |
10 | * @package bh-wp-autologin-urls |
11 | */ |
12 | |
13 | namespace BrianHenryIE\WP_Autologin_URLs\Admin; |
14 | |
15 | use BrianHenryIE\WP_Autologin_URLs\API_Interface; |
16 | use BrianHenryIE\WP_Autologin_URLs\Settings_Interface; |
17 | use WP_User; |
18 | |
19 | /** |
20 | * The extra field on the user edit page. |
21 | */ |
22 | class User_Edit { |
23 | |
24 | /** |
25 | * Plugin settings, for determining the template path. |
26 | */ |
27 | protected Settings_Interface $settings; |
28 | |
29 | /** |
30 | * Core API methods to generate password/URL. |
31 | */ |
32 | protected API_Interface $api; |
33 | |
34 | /** |
35 | * Initialize the class and set its properties. |
36 | * |
37 | * @param API_Interface $api The core plugin functions. |
38 | * @param Settings_Interface $settings The plugin settings. |
39 | * |
40 | * @since 1.0.0 |
41 | */ |
42 | public function __construct( API_Interface $api, Settings_Interface $settings ) { |
43 | $this->settings = $settings; |
44 | $this->api = $api; |
45 | } |
46 | |
47 | /** |
48 | * Add a field on the admin view of the user profile which contains a login URL. |
49 | * For use e.g. in support emails. ...tests. |
50 | * |
51 | * @hooked edit_user_profile |
52 | * @hooked show_user_profile |
53 | * |
54 | * @see wordpress/wp-admin/user-edit.php |
55 | * |
56 | * @param WP_User $profileuser The current WP_User object. |
57 | */ |
58 | public function make_password_available_on_user_page( WP_User $profileuser ): void { |
59 | |
60 | // TODO: If WooCommerce is installed, this should go to my-account. |
61 | $append = '/'; |
62 | $autologin_url = $this->api->add_autologin_to_url( get_site_url() . $append, $profileuser, WEEK_IN_SECONDS ); |
63 | |
64 | $template = 'admin/user-edit.php'; |
65 | |
66 | $template_filepath = WP_PLUGIN_DIR . '/' . plugin_dir_path( $this->settings->get_plugin_basename() ) . 'templates/' . $template; |
67 | |
68 | // Check the child theme for template overrides. |
69 | if ( file_exists( get_stylesheet_directory() . $template ) ) { |
70 | $template_filepath = get_stylesheet_directory() . $template; |
71 | } elseif ( file_exists( get_stylesheet_directory() . 'templates/' . $template ) ) { |
72 | $template_filepath = get_stylesheet_directory() . 'templates/' . $template; |
73 | } |
74 | |
75 | /** |
76 | * Allow overriding the admin settings template. |
77 | * |
78 | * @param string $template_filepath The default or child-theme-overridden template to display an autologin url on the user profile edit admin ui. |
79 | * @param array $args The variables that will be available to the template. |
80 | */ |
81 | $filtered_template_admin_settings_page = apply_filters( 'bh_wp_autologin_urls_admin_user_edit_template', $template_filepath, func_get_args() ); |
82 | |
83 | if ( file_exists( $filtered_template_admin_settings_page ) ) { |
84 | include $filtered_template_admin_settings_page; |
85 | } else { |
86 | include $template_filepath; |
87 | } |
88 | } |
89 | } |