self::ID, 'name' => __( 'Email delivery', 'forensix-digital' ), 'description' => __( 'Sends your site\'s email through your own mail account, so form messages and password resets arrive. Includes a test button that explains problems in plain words.', 'forensix-digital' ), 'category' => 'tools', 'edition' => Edition::FREE, 'features' => array( 'C-09' => Edition::FREE, ), 'deactivation_effects' => array( __( 'WordPress goes back to sending email the way it did before.', 'forensix-digital' ), __( 'Your saved mail settings stay, and the password stays encrypted.', 'forensix-digital' ), ), 'factory' => static fn(): self => new self(), ) ); } /** * Settings service with the mail scope declared. */ private static function settings(): Settings { $settings = Plugin::container()->get( Settings::class ); $settings->register( MailConfig::SCOPE, MailConfig::defaults(), array( MailConfig::class, 'sanitize' ) ); return $settings; } /** * Hooks the app while it is active. */ public function register(): void { $this->mailer = new Mailer( self::settings(), Vault::default() ); $this->mailer->register(); add_action( 'rest_api_init', array( $this, 'register_routes' ) ); add_filter( 'forensix_admin_screens', array( $this, 'add_screen' ) ); } /** * Registers the REST routes. */ public function register_routes(): void { ( new MailRoutes( self::settings(), Vault::default() ) )->register(); } /** * Adds the Email page to the Forensix menu. * * @param array $screens Screens. * @phpstan-param array $screens * @return array */ public function add_screen( array $screens ): array { $screens['forensix-mail'] = array( 'key' => 'mail', 'title' => __( 'Email', 'forensix-digital' ), 'capability' => Capabilities::MANAGE_SETTINGS, ); return $screens; } /** * Nothing to set up. */ public function activate(): void {} /** * Removes the hooks; WordPress sends mail as before. */ public function deactivate(): void { if ( null !== $this->mailer ) { $this->mailer->unregister(); } remove_action( 'rest_api_init', array( $this, 'register_routes' ) ); remove_filter( 'forensix_admin_screens', array( $this, 'add_screen' ) ); } /** * Deletes the saved mail settings and the last test result. */ public function delete_data(): void { delete_option( Settings::OPTION_PREFIX . MailConfig::SCOPE ); delete_option( TestMail::LAST ); } }