Jake Vanderwerf
2026-09-04 32ce5c542c90be348895328078e392dde2052957
inc/registrar/Fields.php
@@ -19,7 +19,7 @@
class Fields {
   protected array $fields;
   private ?Registrar $registrar = null;
   private ?Registrar $registrar;
   protected ?string $type;
   public function __construct(?string $type = null, ?Registrar $registrar = null) {
@@ -28,7 +28,6 @@
      switch ($type) {
         case 'post':
            $this->addPostFields();
            //TODO: Add fields to post edit screen
//          add_action('add_meta_boxes', [$this, 'registerPostFields']);
            break;
         case 'term':
@@ -36,6 +35,9 @@
            break;
         case 'user':
            $this->addUserFields();
            if ($registrar->hasAnyIntegrations()) {
               $this->addIntegrationSetupField();
            }
            break;
      }
   }
@@ -190,18 +192,22 @@
         'first_name'   => [
            'type'   => 'text',
            'label'  => 'First Name',
            'section'=> 'your-account'
         ],
         'last_name' => [
            'type'   => 'text',
            'label'  => 'Last Name',
            'section'=> 'your-account'
         ],
         'user_email'   => [
            'type'   => 'email',
            'label'  => 'Your Email',
            'section'=> 'your-account'
         ],
         'display_name' => [
            'type'   => 'text',
            'label'  => 'Display Name',
            'section'=> 'your-account'
         ],
//       'website'   => [
//          'type'   => 'url',
@@ -228,8 +234,21 @@
      $field->$property($value);
   }
   public function getFields():array
   public function getFields(bool $includeDefaults = true):array
   {
      if (!$includeDefaults) {
         $added = array_keys(match($this->type) {
            'post'  => $this->defaultPostFields(),
            'term'  => $this->defaultTermFields(),
            'user'  => $this->defaultUserFields(),
         });
         $fields = array_filter($this->fields, function($field) use ($added) {
            return !in_array($field, $added);
         }, ARRAY_FILTER_USE_KEY);
         return array_filter($fields, function($field) {
            return !$field->isHidden();
         });
      }
      return $this->fields;
   }
@@ -454,4 +473,17 @@
   {
      return (new self())->defaultUserFields();
   }
   protected function addIntegrationSetupField():void
   {
      $integrations = $this->registrar->getIntegrations();
      foreach (array_keys($integrations) as $integration) {
         $this->addField('integration_'.$integration.'_connected', [
            'type'   => 'true_false',
            'hidden' => true,
            'label'     => 'Connected to '.$integration,
            'default'   => false,
         ]);
      }
   }
}