ams_api = $ams_api; $this->ams_user_records = $ams_user_records; $this->user_factory = $user_factory; $this->translator_activation_records = $translator_activation_records; } public function add_hooks() { add_action( 'wpml_tm_ate_synchronize_translators', array( $this, 'synchronize_translators' ) ); add_action( 'wpml_tm_ate_synchronize_managers', array( $this, 'synchronize_managers' ) ); add_action( 'wpml_tm_ate_enable_subscription', array( $this, 'enable_subscription' ) ); add_action( 'deleted_user', array( $this, 'user_changed' ) ); add_action( 'profile_update', array( $this, 'user_changed' ) ); } /** * @throws \InvalidArgumentException */ public function synchronize_translators() { $result = $this->ams_api->synchronize_translators( $this->ams_user_records->get_translators() ); if ( ! is_wp_error( $result ) ) { $this->translator_activation_records->update( isset( $result['translators'] ) ? $result['translators'] : array() ); } } /** * @throws \InvalidArgumentException */ public function synchronize_managers() { $this->ams_api->synchronize_managers( $this->ams_user_records->get_managers() ); } public function enable_subscription( $user_id ) { $user = $this->user_factory->create( $user_id ); if ( ! $user->get_meta( self::ENABLED_FOR_TRANSLATION_VIA_ATE ) ) { $this->ams_api->enable_subscription( $user->user_email ); $user->update_meta( self::ENABLED_FOR_TRANSLATION_VIA_ATE, true ); } } public function user_changed() { $this->synchronize_managers(); $this->synchronize_translators(); } }