Make WordPress Core

Ticket #37376: 37376.diff

File 37376.diff, 4.4 KB (added by jason_the_adams, 7 years ago)
  • src/wp-includes/class-wp-post-type.php

    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 { 
    226226         */
    227227        public $has_archive = false;
    228228
     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
    229239        /**
    230240         * Sets the query_var key for this post type.
    231241         *
    final class WP_Post_Type { 
    398408                        'register_meta_box_cb'  => null,
    399409                        'taxonomies'            => array(),
    400410                        'has_archive'           => false,
     411                        'has_single'            => true,
    401412                        'rewrite'               => true,
    402413                        'query_var'             => true,
    403414                        'can_export'            => true,
    final class WP_Post_Type { 
    537548                }
    538549
    539550                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                                }
    544557                        }
    545558
    546559                        if ( $this->has_archive ) {
  • src/wp-includes/link-template.php

    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 ) { 
    256256 * @param int|WP_Post $id        Optional. Post ID or post object. Default is the global `$post`.
    257257 * @param bool        $leavename Optional, defaults to false. Whether to keep post name. Default false.
    258258 * @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.
    260260 */
    261261function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
    262262        global $wp_rewrite;
    function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { 
    269269
    270270        $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
    271271
    272         $slug = $post->post_name;
    273 
    274272        $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) );
    275273
    276274        $post_type = get_post_type_object( $post->post_type );
    277275
     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
    278282        if ( $post_type->hierarchical ) {
    279283                $slug = get_page_uri( $post );
    280284        }
    function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { 
    37913795        if ( ! empty( $post_id ) ) {
    37923796                $post_type = get_post_type_object( $post->post_type );
    37933797
     3798                if ( false === $post_type->has_single ) {
     3799                        return '';
     3800                }
     3801
    37943802                if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) {
    37953803                        $shortlink = home_url( '/' );
    37963804                } elseif ( $post_type->public ) {
  • src/wp-includes/post.php

    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 ) { 
    18131813                }
    18141814        }
    18151815
    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 );
    18171817}
    18181818
    18191819/**
    function get_page_uri( $page = 0 ) { 
    47974797                return false;
    47984798        }
    47994799
    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;
    48014803
    48024804        foreach ( $page->ancestors as $parent ) {
    48034805                $parent = get_post( $parent );