From e1034e15f0ca67a828df46e27df13d4263639c18 Mon Sep 17 00:00:00 2001 From: youknowriad Date: Mon, 20 May 2024 09:49:16 +0000 Subject: [PATCH] Posts: Ensure get_sample_permalink returns the right permalink for auto-draft posts. The post editor uses the permalink_template property from the posts REST API to render the post slug input or not. For auto-drafts or newly created posts, this property was not set properly. This PR solves by fixing the get_sample_permalink function used to compute this property. Props youknowriad, mcsf, antonvlasenko, azaozz, peterwilsoncc, andrewserong, hellofromTonya, spacedmonkey. Fixes #59283. Built from https://develop.svn.wordpress.org/trunk@58174 git-svn-id: http://core.svn.wordpress.org/trunk@57637 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/post.php | 2 +- wp-includes/post.php | 6 +++++- wp-includes/version.php | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 72d9803027..6458fb0122 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1463,7 +1463,7 @@ function get_sample_permalink( $post, $title = null, $name = null ) { $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 ) ) { + if ( in_array( $post->post_status, array( 'auto-draft', 'draft', 'pending', 'future' ), true ) ) { $post->post_status = 'publish'; $post->post_name = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID ); } diff --git a/wp-includes/post.php b/wp-includes/post.php index 9946462a0b..15bbfc7ab2 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1219,7 +1219,11 @@ function get_post_mime_type( $post = null ) { * @return string|false Post status on success, false on failure. */ function get_post_status( $post = null ) { - $post = get_post( $post ); + if ( $post instanceof WP_Post && isset( $post->filter ) && 'sample' === $post->filter ) { + // Skip normalization + } else { + $post = get_post( $post ); + } if ( ! is_object( $post ) ) { return false; diff --git a/wp-includes/version.php b/wp-includes/version.php index 2559b03364..dd413a3f98 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58173'; +$wp_version = '6.6-alpha-58174'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.