<?php
|
namespace JVBase\registrar\helpers;
|
|
use JVBase\meta\Meta;
|
use JVBase\registrar\Registrar;
|
use WP_Post;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
class MakeTimelineType {
|
protected string $slug;
|
protected string $postType;
|
protected Registrar $registrar;
|
public function __construct(string $slug, Registrar $registrar) {
|
$this->slug = $slug;
|
$this->postType = jvbCheckBase($slug);
|
$this->registrar = $registrar;
|
|
add_action('template_redirect', [$this, 'redirectChildToParent']);
|
}
|
|
/**
|
* Set $this->is_timeline
|
* @return void
|
*/
|
public function redirectChildToParent(): void
|
{
|
if (!is_singular($this->postType)) {
|
return;
|
}
|
|
global $post;
|
|
// If this post has a parent, redirect to parent
|
if ($post->post_parent) {
|
$parent_url = get_permalink($post->post_parent);
|
|
// Add anchor or query param to indicate which child was accessed
|
$redirect_url = add_query_arg('update', $post->ID, $parent_url);
|
|
wp_redirect($redirect_url, 301);
|
exit;
|
}
|
}
|
}
|