new file: olm-login.php
This commit is contained in:
@@ -5,6 +5,11 @@ namespace KbMarkdownImporter\Repository;
|
||||
|
||||
final class ProductRepository
|
||||
{
|
||||
public const META_GROUP_NAME = '_kb_product_group_name';
|
||||
public const META_GROUP_SLUG = '_kb_product_group_slug';
|
||||
public const META_PART_LABEL = '_kb_product_part_label';
|
||||
public const META_CATEGORY = '_kb_product_category';
|
||||
|
||||
public function ensure(string $name, string $slug = ''): int
|
||||
{
|
||||
$slug = $slug ? sanitize_title($slug) : sanitize_title($name);
|
||||
@@ -54,13 +59,14 @@ final class ProductRepository
|
||||
'term' => $term,
|
||||
'page_count' => count($pageIds),
|
||||
'versions' => array_values($versions),
|
||||
'meta' => $this->frontendMeta($term),
|
||||
];
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function update(int $termId, string $name, string $slug): \WP_Term|\WP_Error
|
||||
public function update(int $termId, string $name, string $slug, array $frontend = []): \WP_Term|\WP_Error
|
||||
{
|
||||
$name = trim($name);
|
||||
$slug = sanitize_title($slug ?: $name);
|
||||
@@ -82,6 +88,23 @@ final class ProductRepository
|
||||
update_post_meta($pageId, '_kb_product_slug', $slug);
|
||||
}
|
||||
|
||||
$groupName = sanitize_text_field((string) ($frontend['group_name'] ?? ''));
|
||||
$groupName = '' !== trim($groupName) ? $groupName : $name;
|
||||
$groupSlugInput = sanitize_title((string) ($frontend['group_slug'] ?? ''));
|
||||
$groupSlug = $groupSlugInput ?: sanitize_title($groupName);
|
||||
|
||||
if ($groupSlugInput === $slug && 0 !== strcasecmp($groupName, $name)) {
|
||||
$groupSlug = sanitize_title($groupName);
|
||||
}
|
||||
|
||||
$partLabel = sanitize_text_field((string) ($frontend['part_label'] ?? ''));
|
||||
$category = sanitize_text_field((string) ($frontend['category'] ?? ''));
|
||||
|
||||
update_term_meta($termId, self::META_GROUP_NAME, $groupName ?: $name);
|
||||
update_term_meta($termId, self::META_GROUP_SLUG, $groupSlug ?: $slug);
|
||||
update_term_meta($termId, self::META_PART_LABEL, $partLabel);
|
||||
update_term_meta($termId, self::META_CATEGORY, $category);
|
||||
|
||||
$term = get_term((int) $updated['term_id'], 'kb_product');
|
||||
|
||||
return $term instanceof \WP_Term ? $term : new \WP_Error('kb_product_missing', __('Product could not be loaded after update.', 'kb-markdown-importer'));
|
||||
@@ -115,6 +138,27 @@ final class ProductRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
public function frontendMeta(\WP_Term $term): array
|
||||
{
|
||||
$storedGroupName = trim((string) get_term_meta($term->term_id, self::META_GROUP_NAME, true));
|
||||
$storedGroupSlug = sanitize_title((string) get_term_meta($term->term_id, self::META_GROUP_SLUG, true));
|
||||
$groupName = '' !== $storedGroupName ? $storedGroupName : $term->name;
|
||||
$groupSlug = '' !== $storedGroupSlug ? $storedGroupSlug : ('' !== $storedGroupName ? sanitize_title($groupName) : $term->slug);
|
||||
$partLabel = trim((string) get_term_meta($term->term_id, self::META_PART_LABEL, true));
|
||||
$category = trim((string) get_term_meta($term->term_id, self::META_CATEGORY, true));
|
||||
|
||||
if ('' !== $storedGroupName && $groupSlug === $term->slug && 0 !== strcasecmp($groupName, $term->name)) {
|
||||
$groupSlug = sanitize_title($groupName);
|
||||
}
|
||||
|
||||
return [
|
||||
'group_name' => $groupName,
|
||||
'group_slug' => '' !== $groupSlug ? $groupSlug : $term->slug,
|
||||
'part_label' => $partLabel,
|
||||
'category' => $category,
|
||||
];
|
||||
}
|
||||
|
||||
private function pageIdsForProduct(int $termId, array $postStatus = ['publish']): array
|
||||
{
|
||||
$query = new \WP_Query([
|
||||
|
||||
Reference in New Issue
Block a user