19 lines
430 B
PHP
19 lines
430 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace KbMarkdownImporter\Repository;
|
|
|
|
final class VersionRepository
|
|
{
|
|
public function ensure(string $version): int
|
|
{
|
|
$term = term_exists($version, 'kb_version');
|
|
|
|
if (! $term) {
|
|
$term = wp_insert_term($version, 'kb_version', ['slug' => sanitize_title($version)]);
|
|
}
|
|
|
|
return is_wp_error($term) ? 0 : (int) ($term['term_id'] ?? $term);
|
|
}
|
|
}
|