1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* The dashboard-specific functionality of the plugin. |
5
|
|
|
* |
6
|
|
|
* @link https://log.pt |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
* |
9
|
|
|
* @package RedmineEmbed |
10
|
|
|
* @subpackage RedmineEmbed/Admin |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace logoscon\WP\RedmineEmbed\Admin; |
14
|
|
|
|
15
|
|
|
use logoscon\WP\RedmineEmbed\Plugin; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The dashboard-specific functionality of the plugin. |
19
|
|
|
* |
20
|
|
|
* Defines the plugin name, version, and two examples hooks for how to |
21
|
|
|
* enqueue the dashboard-specific stylesheet and JavaScript. |
22
|
|
|
* |
23
|
|
|
* @package RedmineEmbed |
24
|
|
|
* @subpackage RedmineEmbed/Admin |
25
|
|
|
* @author log.OSCON, Lda. <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class UserSettings { |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The plugin's instance. |
31
|
|
|
* |
32
|
|
|
* @since 1.0.0 |
33
|
|
|
* @access private |
34
|
|
|
* @var Plugin $plugin This plugin's instance. |
35
|
|
|
*/ |
36
|
|
|
private $plugin; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Initialize the class and set its properties. |
40
|
|
|
* |
41
|
|
|
* @since 1.0.0 |
42
|
|
|
* |
43
|
|
|
* @param Plugin $plugin This plugin's instance. |
44
|
|
|
*/ |
45
|
|
|
public function __construct( Plugin $plugin ) { |
46
|
|
|
$this->plugin = $plugin; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Display the user profile form field. |
51
|
|
|
* |
52
|
|
|
* @param \WP_User $user User instance. |
53
|
|
|
*/ |
54
|
|
|
public function show_user_profile( \WP_User $user ) { |
55
|
|
|
$url = $this->plugin->get_option( 'root_url', '' ); |
56
|
|
|
|
57
|
|
|
if ( empty( $url ) ) { |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ( ! \current_user_can( 'edit_user', $user->ID ) ) { |
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$api_key = \get_user_option( 'redmine_embed_api_key', $user->ID ); |
66
|
|
|
|
67
|
|
|
?> |
68
|
|
|
<h3><?php \_e( 'Redmine', 'redmine-embed' ); ?></h3> |
69
|
|
|
<table class="form-table"> |
70
|
|
|
<tr> |
71
|
|
|
<th><label for="redmine_embed_api_key"><?php |
72
|
|
|
\_e( 'API Key', 'redmine-embed' ); |
73
|
|
|
?></label></th> |
74
|
|
|
<td> |
75
|
|
|
<input type="text" name="redmine_embed_api_key" |
76
|
|
|
id="redmine_embed_api_key" class="regular-text" |
77
|
|
|
value="<?php echo \esc_attr( $api_key ); ?>"> |
78
|
|
|
<br> |
79
|
|
|
<span class="description"><?php |
80
|
|
|
printf( |
81
|
|
|
\__( 'Enter your API key for the Redmine install at %s. It may be found on the right-hand pane of your account page.', 'redmine-embed' ), |
82
|
|
|
\esc_url( $url ) |
83
|
|
|
); |
84
|
|
|
?></span> |
85
|
|
|
</td> |
86
|
|
|
</tr> |
87
|
|
|
</table> |
88
|
|
|
<?php |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Update saved fields on the edited user profile. |
93
|
|
|
* @param int $user_id Edited user ID. |
94
|
|
|
*/ |
95
|
|
|
public function edit_user_profile_update( $user_id ) { |
|
|
|
|
96
|
|
|
if ( ! \current_user_can( 'edit_user', $user_id ) ) { |
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$api_key = \sanitize_key( $_POST['redmine_embed_api_key'] ); |
101
|
|
|
|
102
|
|
|
\update_user_option( $user_id, 'redmine_embed_api_key', $api_key ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: