setup_action(); } protected function setup_action() { $this->set_integration(self::INTEGRATION_CODE); $this->set_action_code(self::ACTION_CODE); $this->set_action_meta(self::ACTION_META); $this->set_sentence( // translators: %s: the trigger meta sprintf(__('Change the email address for a subscriber {{Email address:%s}}', 'acymailing-integration-for-uncanny-automator'), $this->get_action_meta()) ); $this->set_readable_sentence(__('Change the {{email address}} for a subscriber', 'acymailing-integration-for-uncanny-automator')); $this->set_options_callback([$this, 'load_options']); $this->register_action(); } public function load_options(): array { return Automator()->utilities->keep_order_of_options( [ 'options' => [ Automator()->helpers->recipe->field->text( [ 'option_code' => $this->get_action_meta(), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch 'label' => __('Email address', 'uncanny-automator'), 'input_type' => 'email', ] ), ], ] ); } protected function process_action($user_id, $action_data, $recipe_id, $args, $parsed) { $newEmail = Automator()->parse->text($action_data['meta'][$this->get_action_meta()], $recipe_id, $user_id, $args); if (empty($user_id) || empty($newEmail)) { return; } $userClass = new UserClass(); $existingUser = $userClass->getOneByEmail($newEmail); if (!empty($existingUser)) { return; } $currentUser = $userClass->getOneByCMSId($user_id); if (empty($currentUser)) { return; } $currentUser->email = $newEmail; $userClass->save($currentUser); // complete this action successfully Automator()->complete->action($user_id, $action_data, $recipe_id); } }