wpdb->prefix . self::TABLE_SUFFIX; $results = $this->wpdb->get_results( $this->wpdb->prepare( "SELECT attribute_name, attribute_value FROM {$table} WHERE component_name = %s AND group_name = %s", $componentName, self::GROUP_NAME ), ARRAY_A ); if (empty($results)) { return []; } $config = []; foreach ($results as $row) { $config[$row['attribute_name']] = $row['attribute_value'] === '1'; } return $config; } public function saveVisibilityConfig(string $componentName, array $config): void { $table = $this->wpdb->prefix . self::TABLE_SUFFIX; foreach ($config as $field => $enabled) { if (!in_array($field, self::VISIBILITY_FIELDS, true)) { continue; } $exists = $this->wpdb->get_var($this->wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE component_name = %s AND group_name = %s AND attribute_name = %s", $componentName, self::GROUP_NAME, $field )); $value = $enabled ? '1' : '0'; if ($exists) { $this->wpdb->update( $table, [ 'attribute_value' => $value, 'updated_at' => current_time('mysql'), ], [ 'component_name' => $componentName, 'group_name' => self::GROUP_NAME, 'attribute_name' => $field, ] ); } else { $this->wpdb->insert($table, [ 'component_name' => $componentName, 'group_name' => self::GROUP_NAME, 'attribute_name' => $field, 'attribute_value' => $value, 'is_editable' => 1, 'created_at' => current_time('mysql'), 'updated_at' => current_time('mysql'), ]); } } } public function hasVisibilityConfig(string $componentName): bool { $table = $this->wpdb->prefix . self::TABLE_SUFFIX; $count = $this->wpdb->get_var($this->wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE component_name = %s AND group_name = %s", $componentName, self::GROUP_NAME )); return (int) $count > 0; } public function getAllComponentNames(): array { $table = $this->wpdb->prefix . self::TABLE_SUFFIX; $results = $this->wpdb->get_col( "SELECT DISTINCT component_name FROM {$table} ORDER BY component_name" ); return $results ?: []; } public function createDefaultVisibility(string $componentName, array $defaults): void { if ($this->hasVisibilityConfig($componentName)) { return; } $this->saveVisibilityConfig($componentName, $defaults); } }