get_sample_permalink example

$post_type_obj = get_post_type_object( $post->post_type );
        if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) {
            $permalink_template_requested = rest_is_field_included( 'permalink_template', $fields );
            $generated_slug_requested     = rest_is_field_included( 'generated_slug', $fields );

            if ( $permalink_template_requested || $generated_slug_requested ) {
                if ( ! function_exists( 'get_sample_permalink' ) ) {
                    require_once ABSPATH . 'wp-admin/includes/post.php';
                }

                $sample_permalink = get_sample_permalink( $post->ID, $post->post_title, '' );

                if ( $permalink_template_requested ) {
                    $data['permalink_template'] = $sample_permalink[0];
                }

                if ( $generated_slug_requested ) {
                    $data['generated_slug'] = $sample_permalink[1];
                }
            }
        }

        

function get_sample_permalink_html( $post$new_title = null, $new_slug = null ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return '';
    }

    list($permalink$post_name) = get_sample_permalink( $post->ID, $new_title$new_slug );

    $view_link      = false;
    $preview_target = '';

    if ( current_user_can( 'read_post', $post->ID ) ) {
        if ( 'draft' === $post->post_status || empty( $post->post_name ) ) {
            $view_link      = get_preview_post_link( $post );
            $preview_target = " target='wp-preview-{$post->ID}'";
        } else {
            if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
                $view_link = get_permalink( $post );
            }
Home | Imprint | This part of the site doesn't use cookies.