diff --git a/src/wp-includes/class-wp-post-type.php b/src/wp-includes/class-wp-post-type.php
index ba37a02fb5..094be7c9ad 100644
a
|
b
|
final class WP_Post_Type { |
226 | 226 | */ |
227 | 227 | public $has_archive = false; |
228 | 228 | |
| 229 | /** |
| 230 | * Whether there should be post type singles, or if a string, the single slug to use. |
| 231 | * |
| 232 | * Will generate the proper rewrite rules if $rewrite is enabled. Default true. |
| 233 | * |
| 234 | * @since 5.0.0 |
| 235 | * @var bool|string $has_string |
| 236 | */ |
| 237 | public $has_single = true; |
| 238 | |
229 | 239 | /** |
230 | 240 | * Sets the query_var key for this post type. |
231 | 241 | * |
… |
… |
final class WP_Post_Type { |
398 | 408 | 'register_meta_box_cb' => null, |
399 | 409 | 'taxonomies' => array(), |
400 | 410 | 'has_archive' => false, |
| 411 | 'has_single' => true, |
401 | 412 | 'rewrite' => true, |
402 | 413 | 'query_var' => true, |
403 | 414 | 'can_export' => true, |
… |
… |
final class WP_Post_Type { |
537 | 548 | } |
538 | 549 | |
539 | 550 | if ( false !== $this->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { |
540 | | if ( $this->hierarchical ) { |
541 | | add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" ); |
542 | | } else { |
543 | | add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" ); |
| 551 | if ( $this->has_single ) { |
| 552 | if ( $this->hierarchical ) { |
| 553 | add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" ); |
| 554 | } else { |
| 555 | add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" ); |
| 556 | } |
544 | 557 | } |
545 | 558 | |
546 | 559 | if ( $this->has_archive ) { |
diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php
index 365b14b317..0f8f300d74 100644
a
|
b
|
function get_permalink( $post = 0, $leavename = false ) { |
256 | 256 | * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
257 | 257 | * @param bool $leavename Optional, defaults to false. Whether to keep post name. Default false. |
258 | 258 | * @param bool $sample Optional, defaults to false. Is it a sample permalink. Default false. |
259 | | * @return string|WP_Error The post permalink. |
| 259 | * @return string|false|WP_Error The post permalink. |
260 | 260 | */ |
261 | 261 | function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { |
262 | 262 | global $wp_rewrite; |
… |
… |
function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { |
269 | 269 | |
270 | 270 | $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); |
271 | 271 | |
272 | | $slug = $post->post_name; |
273 | | |
274 | 272 | $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) ); |
275 | 273 | |
276 | 274 | $post_type = get_post_type_object( $post->post_type ); |
277 | 275 | |
| 276 | if ( !$post_type->has_single ) { |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | $slug = is_string($post_type->has_single) ? $post_type->has_single : $post->post_name; |
| 281 | |
278 | 282 | if ( $post_type->hierarchical ) { |
279 | 283 | $slug = get_page_uri( $post ); |
280 | 284 | } |
… |
… |
function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { |
3791 | 3795 | if ( ! empty( $post_id ) ) { |
3792 | 3796 | $post_type = get_post_type_object( $post->post_type ); |
3793 | 3797 | |
| 3798 | if ( false === $post_type->has_single ) { |
| 3799 | return ''; |
| 3800 | } |
| 3801 | |
3794 | 3802 | if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) { |
3795 | 3803 | $shortlink = home_url( '/' ); |
3796 | 3804 | } elseif ( $post_type->public ) { |
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index cb5025f607..0a3d365dc6 100644
a
|
b
|
function is_post_type_viewable( $post_type ) { |
1813 | 1813 | } |
1814 | 1814 | } |
1815 | 1815 | |
1816 | | return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); |
| 1816 | return $post_type->publicly_queryable || ( $post_type->has_single && $post_type->_builtin && $post_type->public ); |
1817 | 1817 | } |
1818 | 1818 | |
1819 | 1819 | /** |
… |
… |
function get_page_uri( $page = 0 ) { |
4797 | 4797 | return false; |
4798 | 4798 | } |
4799 | 4799 | |
4800 | | $uri = $page->post_name; |
| 4800 | $post_type = get_post_type_object( $page->post_type ); |
| 4801 | |
| 4802 | $uri = 'page' !== $page->post_type && is_string( $post_type->has_single ) ? $post_type->has_single : $page->post_name; |
4801 | 4803 | |
4802 | 4804 | foreach ( $page->ancestors as $parent ) { |
4803 | 4805 | $parent = get_post( $parent ); |