feat(topics): restore topic taxonomy workflow
This commit is contained in:
1 parent
f3dd1ec3b1
commit
a254cbd3e9
59 files changed
+771
-192
No files matched your search
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
define('ABSPATH', __DIR__);
|
||||
|
||||
class WP_Term {
|
||||
public function __construct(
|
||||
public int $term_id,
|
||||
public int $parent,
|
||||
public string $name
|
||||
) {}
|
||||
}
|
||||
|
||||
function absint($value): int { return abs((int) $value); }
|
||||
function esc_attr($value): string { return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); }
|
||||
function esc_html($value): string { return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); }
|
||||
function get_terms(array $args): array {
|
||||
if ($args['taxonomy'] !== 'topics') return [];
|
||||
return [new WP_Term(1, 0, 'Parent'), new WP_Term(2, 1, 'Child'), new WP_Term(3, 1, 'Sibling'), new WP_Term(4, 0, 'Other')];
|
||||
}
|
||||
function get_term_children(int $id, string $taxonomy): array {
|
||||
return $taxonomy === 'topics' && $id === 1 ? [2, 3] : [];
|
||||
}
|
||||
function term_exists(int $id, string $taxonomy): bool {
|
||||
return $taxonomy === 'topics' && in_array($id, [1, 2, 3, 4], true);
|
||||
}
|
||||
|
||||
require dirname(__DIR__, 2) . '/src/Core/SubmitTopics.php';
|
||||
require dirname(__DIR__, 2) . '/templates/parts/submit/term-checks.php';
|
||||
|
||||
$root = ['allow_topics' => true, 'allowed_topic_ids' => [1]];
|
||||
$child = ['allow_topics' => true, 'allowed_topic_ids' => [2]];
|
||||
$disabled = ['allow_topics' => false, 'allowed_topic_ids' => []];
|
||||
$tree = static fn(array $settings): array => array_map(
|
||||
static fn(array $node): array => ['id' => $node['term']->term_id, 'depth' => $node['depth']],
|
||||
\Jio\Core\SubmitTopics::tree($settings)
|
||||
);
|
||||
|
||||
ob_start();
|
||||
jio_submit_render_term_checks([new WP_Term(2, 1, 'Child')], [], 'topics');
|
||||
$orphan_html = ob_get_clean();
|
||||
|
||||
echo json_encode([
|
||||
'root_tree' => $tree($root),
|
||||
'child_tree' => $tree($child),
|
||||
'disabled_tree' => $tree($disabled),
|
||||
'filtered' => \Jio\Core\SubmitTopics::filter_ids([2, 4, 999, 2], $child),
|
||||
'disabled_filtered' => \Jio\Core\SubmitTopics::filter_ids([2], $disabled),
|
||||
'orphan_html' => $orphan_html,
|
||||
], JSON_THROW_ON_ERROR);
|
||||
Reference in new issue
Block a user