emails()->add( new MyEmail(), 'emails', 'user_emails', 70 )`. * * Adding one puts the email's accordion field into the given settings tab * and section (which must already exist), records which plugin owns it * (for the Settings screen's Pro/Woo/Tools colour coding), and calls the * email's own `register()` so it hooks the event that sends it. */ final class EmailManager { /** * Registered emails, keyed by id. * * @var array */ private array $emails = array(); /** * Constructor. * * @param SettingsRegistry $settings The settings registry. */ public function __construct( private SettingsRegistry $settings ) {} /** * Register an email. First registration of an id wins. * * @param Email $email The email. * @param string $tab Settings tab id. * @param string $section Settings section id. * @param int $priority Ordering within the section. * @return void */ public function add( Email $email, string $tab, string $section, int $priority = 10 ): void { if ( isset( $this->emails[ $email->id() ] ) ) { return; } $email->attach( $tab, $section, $this->settings->current_owner() ); $this->settings->add_field( $tab, $section, $email->field( $priority ) ); $this->emails[ $email->id() ] = $email; $email->register(); } /** * A registered email by id. * * @param string $id Email id. * @return Email|null */ public function get( string $id ): ?Email { return $this->emails[ $id ] ?? null; } /** * Every registered email. * * @return array */ public function all(): array { return $this->emails; } }