Password.php
870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace ACP\Editing\Service\User;
use ACP\Editing\Service\BasicStorage;
use ACP\Editing\Storage;
use ACP\Editing\View;
use RuntimeException;
class Password extends BasicStorage {
public function __construct() {
parent::__construct( new Storage\User\Field( 'user_pass' ) );
}
public function get_view( string $context ): ?View {
return $context === self::CONTEXT_BULK
? null
: new View\WpPassword();
}
public function get_value( int $id ) {
if ( ! current_user_can( 'administrator' ) ) {
return null;
}
return '';
}
public function update( int $id, $data ): void {
if ( ! current_user_can( 'administrator' ) ) {
throw new RuntimeException( __( "You're not allowed to change the password" ) );
}
if ( ! $data ) {
throw new RuntimeException( __( "A password is required" ) );
}
parent::update( $id, $data );
}
}