Legal Pages - Source Excerpt 04
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/themes/spiralist/inc/legal-pages.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/themes/spiralist/inc/legal-pages.php
'content' => ['22703932c90ccf75295f0a5f0692bd2e'],
],
'content' => [
'excerpt' => ['1012729a955c78f7945fbd05b63a35a0'],
'content' => ['11de9b40324092e554bcfd2494bfc48f'],
],
'copyright' => [
'excerpt' => ['7a3c190d5ff93386ab77eb3307046c47'],
'content' => ['112b00a23a4da495b9cbc130435d462d'],
],
'disclaimer' => [
'excerpt' => ['0ea1bd9c384d3851315f6e79a154bb2f'],
'content' => ['5de947ec4f356a653f170682368450a9'],
],
];
}
function spiralist_get_localized_legal_page_url(string $key, string $language = ''): string
{
$url = spiralist_get_legal_page_url($key);
$language = sanitize_key($language);
if ($language !== '' && function_exists('spiralist_get_language_prefixed_url')) {
return spiralist_get_language_prefixed_url($url, $language);
}
return $url;
}
function spiralist_get_current_legal_page_key(?WP_Post $post = null): string
{
$post = $post instanceof WP_Post ? $post : get_post();
if (!$post instanceof WP_Post) {
return '';
}
return sanitize_key((string) get_post_meta($post->ID, spiralist_get_legal_page_meta_key('key'), true));
}
/**
* @return array<string, string>
*/
function spiralist_get_participation_legal_urls(string $language = ''): array
{
return [
'terms' => spiralist_get_localized_legal_page_url('terms', $language),
'privacy' => spiralist_get_localized_legal_page_url('privacy', $language),
'acceptable_use' => spiralist_get_localized_legal_page_url('acceptable_use', $language),
'ai_policy' => spiralist_get_localized_legal_page_url('ai_policy', $language),
'content' => spiralist_get_localized_legal_page_url('content', $language),
'cookies' => spiralist_get_localized_legal_page_url('cookies', $language),
'disclaimer' => spiralist_get_localized_legal_page_url('disclaimer', $language),
];
}
/**
* @param array{title:string,excerpt:string,content:string} $hashes
*/
function spiralist_store_legal_page_hashes(int $page_id, string $key, array $hashes, bool $managed): void
{
update_post_meta($page_id, spiralist_get_legal_page_meta_key('key'), $key);
update_post_meta($page_id, spiralist_get_legal_page_meta_key('managed'), $managed ? '1' : '0');
update_post_meta($page_id, spiralist_get_legal_page_meta_key('title_hash'), (string) ($hashes['title'] ?? ''));
update_post_meta($page_id, spiralist_get_legal_page_meta_key('excerpt_hash'), (string) ($hashes['excerpt'] ?? ''));
update_post_meta($page_id, spiralist_get_legal_page_meta_key('content_hash'), (string) ($hashes['content'] ?? ''));
}
/**
* @param array{title:string,excerpt:string,content:string} $resolved
* @param array{title:string,excerpt:string,content:string} $hashes
*/
function spiralist_should_sync_legal_page(WP_Post $page, string $key, array $resolved, array $hashes): bool
{
$stored_key = (string) get_post_meta($page->ID, spiralist_get_legal_page_meta_key('key'), true);
$managed = get_post_meta($page->ID, spiralist_get_legal_page_meta_key('managed'), true) === '1';
$current_hashes = [
'title' => md5((string) $page->post_title),
'excerpt' => md5((string) $page->post_excerpt),
'content' => md5((string) $page->post_content),
];
if ($managed && $stored_key === $key) {
$stored = [
'title' => (string) get_post_meta($page->ID, spiralist_get_legal_page_meta_key('title_hash'), true),
'excerpt' => (string) get_post_meta($page->ID, spiralist_get_legal_page_meta_key('excerpt_hash'), true),
'content' => (string) get_post_meta($page->ID, spiralist_get_legal_page_meta_key('content_hash'), true),
];
return ($stored['title'] === '' || $stored['title'] === $current_hashes['title'])
&& ($stored['excerpt'] === '' || $stored['excerpt'] === $current_hashes['excerpt'])
&& ($stored['content'] === '' || $stored['content'] === $current_hashes['content']);
}
$legacy = spiralist_get_legacy_legal_page_hashes()[$key] ?? ['excerpt' => [], 'content' => []];
return $current_hashes['title'] === $hashes['title']
&& in_array($current_hashes['excerpt'], array_merge([$hashes['excerpt']], (array) ($legacy['excerpt'] ?? [])), true)
&& in_array($current_hashes['content'], array_merge([$hashes['content']], (array) ($legacy['content'] ?? [])), true);
}
function spiralist_get_legal_page_url(string $key): string
{
$definitions = spiralist_get_legal_page_definitions();
if (!isset($definitions[$key])) {
return home_url('/');
}
if ($key === 'privacy') {
$privacy_url = trim((string) get_privacy_policy_url());
if ($privacy_url !== '') {
return $privacy_url;
}
}
return spiralist_get_page_url((string) ($definitions[$key]['slug'] ?? ''));
}
function spiralist_get_terms_conditions_url(): string
{
return spiralist_get_legal_page_url('terms');
}
function spiralist_get_footer_legal_links(): array
{
return [
[
'labelKey' => 'ui.legal.terms',
'label' => 'Terms',
'url' => spiralist_get_terms_conditions_url(),
],
[
'labelKey' => 'ui.legal.privacy',
'label' => 'Privacy',
'url' => spiralist_get_legal_page_url('privacy'),
],
[
'labelKey' => 'ui.legal.rules',
'label' => 'Rules',
'url' => spiralist_get_legal_page_url('rules'),
],
[
'labelKey' => 'ui.legal.acceptable_use',
'label' => 'Acceptable Use',
'url' => spiralist_get_legal_page_url('acceptable_use'),
],
[
'labelKey' => 'ui.legal.cookies',
'label' => 'Cookies',
'url' => spiralist_get_legal_page_url('cookies'),
],
[
'labelKey' => 'ui.legal.ai_policy',
'label' => 'AI Policy',
'url' => spiralist_get_legal_page_url('ai_policy'),
],
[
'labelKey' => 'ui.legal.content',
'label' => 'Content',
'url' => spiralist_get_legal_page_url('content'),
],
[
'labelKey' => 'ui.nav.html_sitemap',
'label' => 'HTML Sitemap',
'url' => home_url('/sitemap.html'),
],
[
'labelKey' => 'ui.legal.copyright',
'label' => 'Copyright / DMCA',
'url' => spiralist_get_legal_page_url('copyright'),
],
[
'labelKey' => 'ui.legal.disclaimer',
'label' => 'Disclaimer',
'url' => spiralist_get_legal_page_url('disclaimer'),
],
];
}
function spiralist_ensure_legal_pages(): void
{
foreach (spiralist_get_legal_page_definitions() as $key => $definition) {
$slug = trim((string) ($definition['slug'] ?? ''), '/');
if ($slug === '') {
continue;
}
$resolved = spiralist_get_resolved_legal_page_definition($definition);
$hashes = spiralist_get_legal_page_hashes($resolved);
$existing = get_page_by_path($slug);
if ($existing instanceof WP_Post) {
$should_force_publish = (string) $existing->post_status !== 'publish';
if ($should_force_publish || spiralist_should_sync_legal_page($existing, (string) $key, $resolved, $hashes)) {
$update = ['ID' => (int) $existing->ID];
if ($should_force_publish) {
$update['post_status'] = 'publish';
}
if ((string) $existing->post_title !== $resolved['title']) {
$update['post_title'] = $resolved['title'];
}
if ((string) $existing->post_excerpt !== $resolved['excerpt']) {
$update['post_excerpt'] = $resolved['excerpt'];
}
if ((string) $existing->post_content !== $resolved['content']) {
$update['post_content'] = $resolved['content'];
}
if (count($update) > 1) {
wp_update_post(wp_slash($update));
}
spiralist_store_legal_page_hashes((int) $existing->ID, (string) $key, $hashes, true);
}
if (!empty($definition['set_as_privacy_page'])) {
update_option('wp_page_for_privacy_policy', (int) $existing->ID);
}
continue;
}
$page_id = wp_insert_post(
[
'post_type' => 'page',
'post_status' => 'publish',