Jake Vanderwerf
2026-03-29 275c0d74cd68677622a5431505c5c870c473063d
inc/admin/SEOAdmin.php
@@ -88,7 +88,9 @@
      'sponsor',
      'containsInPlace',
      'containsPlace',
      'openingHours'
      'openingHours',
      'id',
      'ignore',
   ];
   protected array $hints = [
@@ -114,7 +116,8 @@
   protected function setChecks():void
   {
      $checks = [
         'website'
         'website',
         'organization'
      ];
      $this->checks = array_merge($checks, Registrar::getRegistered());
   }
@@ -287,14 +290,14 @@
   }
   public function renderFieldsFor(string $class, array $stored):void
   {
      $fields = $this->getFieldsFor($class);
      $fields = $this->getFieldsForClass($class);
      $instance = new $class();
      foreach ($fields as $property => $value) {
         $this->renderProperty($property, $stored[$property]??null, $instance);
      }
   }
   public function getFieldsFor(string $class):array
   public function getFieldsForClass(string $class):array
   {
      if (!class_exists($class)) {
         error_log('Class not found: '.$class);
@@ -331,7 +334,7 @@
      }
      $_POST['type'] = $type;
      $result = $this->saveFields($action, $type, $_POST);
@@ -344,6 +347,7 @@
   public function saveFields(string $action, string $class, array $data):array
   {
      $action = strtolower($action);
      if (!in_array($action, $this->checks)) {
         error_log('[SEOAdmin]Action is not allowed: '.$action);
         return [
@@ -352,39 +356,13 @@
         ];
      }
      $allowed = $this->getFieldsFor($class);
      if (empty($allowed)) {
         return [
            'jvb_notice'   => 'error',
            'jvb_message'  => 'Could not get fields from class'
         ];
      }
      $checked = array_filter($data, function ($item) use ($allowed) {
         return array_key_exists($item, $allowed);
      }, ARRAY_FILTER_USE_KEY);
      $stored = get_option(BASE.ucfirst($action).'Schema', []);
      $updates = [];
      foreach ($checked as $property => $value) {
         $sanitized = Sanitizer::sanitize($value, $this->buildConfig($property));
         if (!array_key_exists($property, $stored) || $stored[$property] !== $sanitized)
         $updates[$property] = $sanitized;
      }
      if (!empty($updates)) {
         $history = get_option(BASE.ucfirst($action).'SchemaHistory', []);
         array_unshift($history, $stored);
         if (count($history) > 5){
            array_pop($history);
         }
         update_option(BASE.ucfirst($action).'SchemaHistory', $history);
         $update = array_merge($stored, $updates);
         update_option(BASE.ucfirst($action).'Schema', $update);
      }
      return [
      $success = JVB()->schemaHelper()->updateSchema($action, $data);
      return $success ? [
         'jvb_notice'   => 'success',
         'jvb_message'  => 'Saved changes successfully'
      ] : [
         'jvb_notice'   => 'error',
         'jvb_message'  => 'Something went wrong...'
      ];
   }
}