class-wpml-tm-ams-translator-activation-records.php
1.02 KB
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
<?php
class WPML_TM_AMS_Translator_Activation_Records {
const USER_META = 'ate_activated';
/** @var WPML_WP_User_Factory $user_factory */
private $user_factory;
public function __construct( WPML_WP_User_Factory $user_factory ) {
$this->user_factory = $user_factory;
}
public function is_activated( $user_email ) {
return $this->is_user_activated( $this->user_factory->create_by_email( $user_email ) );
}
public function is_current_user_activated() {
return $this->is_user_activated( $this->user_factory->create_current() );
}
public function is_user_activated( WPML_User $user ) {
return (bool) $user->get_option( self::USER_META );
}
public function set_activated( $user_email, $state ) {
$user = $this->user_factory->create_by_email( $user_email );
if ( $user->ID ) {
return $user->update_option( self::USER_META, $state );
}
}
public function update( array $translators ) {
foreach ( $translators as $translator ) {
$this->set_activated( $translator['email'], $translator['subscription'] );
}
}
}