get_sample_permalink

The timeline below displays how wordpress function get_sample_permalink has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Returns a sample permalink based on the post name.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $post  Post ID or post object.
 * @param string|null $title Optional. Title to override the post's current title
 *                           when generating the post name. Default null.
 * @param string|null $name  Optional. Name to override the post name. Default null.
 * @return array {
 *     Array containing the sample permalink with placeholder for the post name, and the post name.
 *
 *     @type string $0 The permalink with placeholder for the post name.
 *     @type string $1 The post name.
 * }
 */
function get_sample_permalink($post, $title = null, $name = null)
{
    $post = get_post($post);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    $original_filter = $post->filter;
    // Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'), true)) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    /*
     * If the user wants to set a new name -- override the current one.
     * Note: if empty name is supplied -- use the title instead, see #6072.
     */
    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, true);
    // Replace custom post_type token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy.
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($permalink, apply_filters('editable_slug', $post->post_name, $post));
    $post->post_status = $original_status;
    $post->post_date = $original_date;
    $post->post_name = $original_name;
    $post->filter = $original_filter;
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param array   $permalink {
     *     Array containing the sample permalink with placeholder for the post name, and the post name.
     *
     *     @type string $0 The permalink with placeholder for the post name.
     *     @type string $1 The post name.
     * }
     * @param int     $post_id Post ID.
     * @param string  $title   Post title.
     * @param string  $name    Post name (slug).
     * @param WP_Post $post    Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 6.1

/**
 * Returns a sample permalink based on the post name.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $post  Post ID or post object.
 * @param string|null $title Optional. Title to override the post's current title
 *                           when generating the post name. Default null.
 * @param string|null $name  Optional. Name to override the post name. Default null.
 * @return array {
 *     Array containing the sample permalink with placeholder for the post name, and the post name.
 *
 *     @type string $0 The permalink with placeholder for the post name.
 *     @type string $1 The post name.
 * }
 */
function get_sample_permalink($post, $title = null, $name = null)
{
    $post = get_post($post);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    $original_filter = $post->filter;
    // Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'), true)) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one.
    // Note: if empty name is supplied -- use the title instead, see #6072.
    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, true);
    // Replace custom post_type token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy.
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($permalink, apply_filters('editable_slug', $post->post_name, $post));
    $post->post_status = $original_status;
    $post->post_date = $original_date;
    $post->post_name = $original_name;
    $post->filter = $original_filter;
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param array   $permalink {
     *     Array containing the sample permalink with placeholder for the post name, and the post name.
     *
     *     @type string $0 The permalink with placeholder for the post name.
     *     @type string $1 The post name.
     * }
     * @param int     $post_id Post ID.
     * @param string  $title   Post title.
     * @param string  $name    Post name (slug).
     * @param WP_Post $post    Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 5.9

/**
 * Returns a sample permalink based on the post name.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $id    Post ID or post object.
 * @param string|null $title Optional. Title to override the post's current title
 *                           when generating the post name. Default null.
 * @param string|null $name  Optional. Name to override the post name. Default null.
 * @return array {
 *     Array containing the sample permalink with placeholder for the post name, and the post name.
 *
 *     @type string $0 The permalink with placeholder for the post name.
 *     @type string $1 The post name.
 * }
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'), true)) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one.
    // Note: if empty name is supplied -- use the title instead, see #6072.
    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, true);
    // Replace custom post_type token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy.
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($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);
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param array   $permalink {
     *     Array containing the sample permalink with placeholder for the post name, and the post name.
     *
     *     @type string $0 The permalink with placeholder for the post name.
     *     @type string $1 The post name.
     * }
     * @param int     $post_id Post ID.
     * @param string  $title   Post title.
     * @param string  $name    Post name (slug).
     * @param WP_Post $post    Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 5.7

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $id    Post ID or post object.
 * @param string      $title Optional. Title to override the post's current title when generating the post name. Default null.
 * @param string      $name  Optional. Name to override the post name. Default null.
 * @return array {
 *     Array containing the sample permalink with placeholder for the post name, and the post name.
 *
 *     @type string $0 The permalink with placeholder for the post name.
 *     @type string $1 The post name.
 * }
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'), true)) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one.
    // Note: if empty name is supplied -- use the title instead, see #6072.
    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, true);
    // Replace custom post_type token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy.
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($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);
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param array   $permalink {
     *     Array containing the sample permalink with placeholder for the post name, and the post name.
     *
     *     @type string $0 The permalink with placeholder for the post name.
     *     @type string $1 The post name.
     * }
     * @param int     $post_id   Post ID.
     * @param string  $title     Post title.
     * @param string  $name      Post name (slug).
     * @param WP_Post $post      Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 5.6

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $id    Post ID or post object.
 * @param string      $title Optional. Title to override the post's current title when generating the post name. Default null.
 * @param string      $name  Optional. Name to override the post name. Default null.
 * @return array {
 *     Array containing the sample permalink with placeholder for the post name, and the post name.
 *
 *     @type string $0 The permalink with placeholder for the post name.
 *     @type string $1 The post name.
 * }
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'), true)) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one.
    // Note: if empty name is supplied -- use the title instead, see #6072.
    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, true);
    // Replace custom post_type token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy.
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($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);
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param array   $permalink {
     *     Array containing the sample permalink with placeholder for the post name, and the post name.
     *
     *     @type string $0 The permalink with placeholder for the post name.
     *     @type string $1 The post name.
     * }
     * @param int     $post_id   Post ID.
     * @param string  $title     Post title.
     * @param string  $name      Post name (slug).
     * @param WP_Post $post      Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 5.5

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int    $id    Post ID or post object.
 * @param string $title Optional. Title to override the post's current title when generating the post name. Default null.
 * @param string $name  Optional. Name to override the post name. Default null.
 * @return array {
 *     Array containing the sample permalink with placeholder for the post name, and the post name.
 *
 *     @type string $0 The permalink with placeholder for the post name.
 *     @type string $1 The post name.
 * }
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'), true)) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one.
    // Note: if empty name is supplied -- use the title instead, see #6072.
    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, true);
    // Replace custom post_type token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy.
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($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);
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param array   $permalink {
     *     Array containing the sample permalink with placeholder for the post name, and the post name.
     *
     *     @type string $0 The permalink with placeholder for the post name.
     *     @type string $1 The post name.
     * }
     * @param int     $post_id   Post ID.
     * @param string  $title     Post title.
     * @param string  $name      Post name (slug).
     * @param WP_Post $post      Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 5.4

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int    $id    Post ID or post object.
 * @param string $title Optional. Title to override the post's current title when generating the post name. Default null.
 * @param string $name  Optional. Name to override the post name. Default null.
 * @return array {
 *     Array containing the sample permalink with placeholder for the post name, and the post name.
 *
 *     @type string $0 The permalink with placeholder for the post name.
 *     @type string $1 The post name.
 * }
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'))) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one.
    // Note: if empty name is supplied -- use the title instead, see #6072.
    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, true);
    // Replace custom post_type token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy.
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($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);
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param array   $permalink {
     *     Array containing the sample permalink with placeholder for the post name, and the post name.
     *
     *     @type string $0 The permalink with placeholder for the post name.
     *     @type string $1 The post name.
     * }
     * @param int     $post_id   Post ID.
     * @param string  $title     Post title.
     * @param string  $name      Post name (slug).
     * @param WP_Post $post      Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 4.7

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int    $id    Post ID or post object.
 * @param string $title Optional. Title to override the post's current title when generating the post name. Default null.
 * @param string $name  Optional. Name to override the post name. Default null.
 * @return array Array containing the sample permalink with placeholder for the post name, and the post name.
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'))) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one
    // Note: if empty name is supplied -- use the title instead, see #6072
    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, true);
    // Replace custom post_type Token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($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);
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param array   $permalink Array containing the sample permalink with placeholder for the post name, and the post name.
     * @param int     $post_id   Post ID.
     * @param string  $title     Post title.
     * @param string  $name      Post name (slug).
     * @param WP_Post $post      Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 4.6

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int    $id    Post ID or post object.
 * @param string $title Optional. Title. Default null.
 * @param string $name  Optional. Name. Default null.
 * @return array Array with two entries of type string.
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'))) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one
    // Note: if empty name is supplied -- use the title instead, see #6072
    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, true);
    // Replace custom post_type Token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($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);
    /**
     * Filters the sample permalink.
     *
     * @since 4.4.0
     *
     * @param string  $permalink Sample permalink.
     * @param int     $post_id   Post ID.
     * @param string  $title     Post title.
     * @param string  $name      Post name (slug).
     * @param WP_Post $post      Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 4.4

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int    $id    Post ID or post object.
 * @param string $title Optional. Title. Default null.
 * @param string $name  Optional. Name. Default null.
 * @return array Array with two entries of type string.
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'))) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one
    // Note: if empty name is supplied -- use the title instead, see #6072
    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, true);
    // Replace custom post_type Token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri, $post);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($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);
    /**
     * Filter the sample permalink.
     *
     * @since 4.4.0
     *
     * @param string  $permalink Sample permalink.
     * @param int     $post_id   Post ID.
     * @param string  $title     Post title.
     * @param string  $name      Post name (slug).
     * @param WP_Post $post      Post object.
     */
    return apply_filters('get_sample_permalink', $permalink, $post->ID, $title, $name, $post);
}

WordPress Version: 4.2

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int    $id    Post ID or post object.
 * @param string $title Optional. Title. Default null.
 * @param string $name  Optional. Name. Default null.
 * @return array Array with two entries of type string.
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending', 'future'))) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one
    // Note: if empty name is supplied -- use the title instead, see #6072
    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, true);
    // Replace custom post_type Token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        if ($uri) {
            $uri = untrailingslashit($uri);
            $uri = strrev(stristr(strrev($uri), '/'));
            $uri = untrailingslashit($uri);
        }
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($permalink, apply_filters('editable_slug', $post->post_name));
    $post->post_status = $original_status;
    $post->post_date = $original_date;
    $post->post_name = $original_name;
    unset($post->filter);
    return $permalink;
}

WordPress Version: 4.1

/**
 * Get a sample permalink based off of the post name.
 *
 * @since 2.5.0
 *
 * @param int    $id    Post ID or post object.
 * @param string $title Optional. Title. Default null.
 * @param string $name  Optional. Name. Default null.
 * @return array Array with two entries of type string.
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending'))) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one
    // Note: if empty name is supplied -- use the title instead, see #6072
    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, true);
    // Replace custom post_type Token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        $uri = untrailingslashit($uri);
        $uri = strrev(stristr(strrev($uri), '/'));
        $uri = untrailingslashit($uri);
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($permalink, apply_filters('editable_slug', $post->post_name));
    $post->post_status = $original_status;
    $post->post_date = $original_date;
    $post->post_name = $original_name;
    unset($post->filter);
    return $permalink;
}

WordPress Version: 3.9

/**
 * {@internal Missing Short Description}}
 *
 * @since 2.5.0
 *
 * @param int|object $id    Post ID or post object.
 * @param string $title (optional) Title
 * @param string $name (optional) Name
 * @return array With two entries of type string
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending'))) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one
    // Note: if empty name is supplied -- use the title instead, see #6072
    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, true);
    // Replace custom post_type Token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy
    if ($ptype->hierarchical) {
        $uri = get_page_uri($post);
        $uri = untrailingslashit($uri);
        $uri = strrev(stristr(strrev($uri), '/'));
        $uri = untrailingslashit($uri);
        /** This filter is documented in wp-admin/edit-tag-form.php */
        $uri = apply_filters('editable_slug', $uri);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    /** This filter is documented in wp-admin/edit-tag-form.php */
    $permalink = array($permalink, apply_filters('editable_slug', $post->post_name));
    $post->post_status = $original_status;
    $post->post_date = $original_date;
    $post->post_name = $original_name;
    unset($post->filter);
    return $permalink;
}

WordPress Version: 3.7

/**
 * {@internal Missing Short Description}}
 *
 * @since 2.5.0
 *
 * @param int|object $id    Post ID or post object.
 * @param string $title (optional) Title
 * @param string $name (optional) Name
 * @return array With two entries of type string
 */
function get_sample_permalink($id, $title = null, $name = null)
{
    $post = get_post($id);
    if (!$post) {
        return array('', '');
    }
    $ptype = get_post_type_object($post->post_type);
    $original_status = $post->post_status;
    $original_date = $post->post_date;
    $original_name = $post->post_name;
    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    if (in_array($post->post_status, array('draft', 'pending'))) {
        $post->post_status = 'publish';
        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
    }
    // If the user wants to set a new name -- override the current one
    // Note: if empty name is supplied -- use the title instead, see #6072
    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, true);
    // Replace custom post_type Token with generic pagename token for ease of use.
    $permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
    // Handle page hierarchy
    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);
        if (!empty($uri)) {
            $uri .= '/';
        }
        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    }
    $permalink = array($permalink, apply_filters('editable_slug', $post->post_name));
    $post->post_status = $original_status;
    $post->post_date = $original_date;
    $post->post_name = $original_name;
    unset($post->filter);
    return $permalink;
}