<?php

defined('ABSPATH') || exit;
function get_rocket_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return ['', ''];
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    if (in_array($post->post_status, ['draft', 'pending'], true)) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    if (!is_null($name)) {
        $post->post_name = sanitize_title($name ? $name : $title, $post->ID);
    }
    $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
    $post->filter = 'sample';
    $permalink = get_permalink($post, false);
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        $uri = untrailingslashit($uri);
        $uri = strrev(stristr(strrev($uri), '/'));
        $uri = untrailingslashit($uri);
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    $permalink = [$permalink, apply_filters('editable_slug', $post->post_name, $post)];
    $post->post_status = $original_status;
    $post->post_date = $original_date;
    $post->post_name = $original_name;
    unset($post->filter);
    return $permalink;
}