Make WordPress Core

Ticket #37376: 37376.2.patch

File 37376.2.patch, 7.0 KB (added by bacoords, 6 weeks ago)

Updated patch based on the latest trunk changes

  • src/wp-admin/edit-form-advanced.php

    a b  
    113113
    114114$preview_url = get_preview_post_link( $post );
    115115
    116 $viewable = is_post_type_viewable( $post_type_object );
     116$viewable = is_post_type_viewable( $post_type_object ) && $post_type_object->has_single;
    117117
    118118if ( $viewable ) {
    119119
  • src/wp-admin/includes/class-wp-posts-list-table.php

    a b  
    15801580                        }
    15811581                }
    15821582
    1583                 if ( is_post_type_viewable( $post_type_object ) ) {
     1583                if ( is_post_type_viewable( $post_type_object ) && $post_type_object->has_single ) {
    15841584                        if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ), true ) ) {
    15851585                                if ( $can_edit_post ) {
    15861586                                        $preview_link    = get_preview_post_link( $post );
  • src/wp-admin/includes/meta-boxes.php

    a b  
    6262                </div>
    6363
    6464                <?php
    65                 if ( is_post_type_viewable( $post_type_object ) ) :
     65                if ( is_post_type_viewable( $post_type_object ) && $post_type_object->has_single ) :
    6666                        ?>
    6767                        <div id="preview-action">
    6868                                <?php
  • src/wp-includes/class-wp-post-type.php

    a b  
    247247        public $has_archive = false;
    248248
    249249        /**
     250         * Whether there should be post type singles.
     251         *
     252         * Will generate the proper rewrite rules if $rewrite is enabled. Default true.
     253         *
     254         * @since 6.9.0
     255         * @var bool $has_single
     256         */
     257        public $has_single = true;
     258
     259        /**
    250260         * Sets the query_var key for this post type.
    251261         *
    252262         * Defaults to $post_type key. If false, a post type cannot be loaded at `?{query_var}={post_slug}`.
     
    546556                        'register_meta_box_cb'            => null,
    547557                        'taxonomies'                      => array(),
    548558                        'has_archive'                     => false,
     559                        'has_single'                      => true,
    549560                        'rewrite'                         => true,
    550561                        'query_var'                       => true,
    551562                        'can_export'                      => true,
     
    716727                }
    717728
    718729                if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
    719                         if ( $this->hierarchical ) {
    720                                 add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
    721                         } else {
    722                                 add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
     730                        if ( $this->has_single ) {
     731                                if ( $this->hierarchical ) {
     732                                        add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
     733                                } else {
     734                                        add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
     735                                }
    723736                        }
    724737
    725738                        if ( $this->has_archive ) {
  • src/wp-includes/link-template.php

    a b  
    319319 * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
    320320 * @param bool        $leavename Optional. Whether to keep post name. Default false.
    321321 * @param bool        $sample    Optional. Is it a sample permalink. Default false.
    322  * @return string|false The post permalink URL. False if the post does not exist.
     322 * @return string|false The post permalink URL. False if the post does not exist or has no single.
    323323 */
    324324function get_post_permalink( $post = 0, $leavename = false, $sample = false ) {
    325325        global $wp_rewrite;
     
    332332
    333333        $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
    334334
    335         $slug = $post->post_name;
    336 
    337335        $force_plain_link = wp_force_plain_post_permalink( $post );
    338336
    339337        $post_type = get_post_type_object( $post->post_type );
    340338
     339        if ( ! $post_type->has_single ) {
     340                return false;
     341        }
     342
     343        $slug = $post->post_name;
     344
    341345        if ( $post_type->hierarchical ) {
    342346                $slug = get_page_uri( $post );
    343347        }
     
    14131417        }
    14141418
    14151419        $post_type_object = get_post_type_object( $post->post_type );
    1416         if ( is_post_type_viewable( $post_type_object ) ) {
     1420        if ( is_post_type_viewable( $post_type_object ) && $post_type_object->has_single ) {
    14171421                if ( ! $preview_link ) {
    14181422                        $preview_link = set_url_scheme( get_permalink( $post ) );
    14191423                }
     
    41874191        if ( ! empty( $post_id ) ) {
    41884192                $post_type = get_post_type_object( $post->post_type );
    41894193
     4194                if ( false === $post_type->has_single ) {
     4195                        return '';
     4196                }
     4197
    41904198                if ( 'page' === $post->post_type
    41914199                        && 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID
    41924200                ) {
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    a b  
    669669                $data     = $this->prepare_item_for_response( $post, $request );
    670670                $response = rest_ensure_response( $data );
    671671
    672                 if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
     672                $post_type_object = get_post_type_object( $post->post_type );
     673                if ( is_post_type_viewable( $post_type_object ) && $post_type_object->has_single ) {
    673674                        $response->link_header( 'alternate', get_permalink( $post->ID ), array( 'type' => 'text/html' ) );
    674675                }
    675676
     
    21152116                }
    21162117
    21172118                $post_type_obj = get_post_type_object( $post->post_type );
    2118                 if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) {
     2119                if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public && $post_type_obj->has_single ) {
    21192120                        $permalink_template_requested = rest_is_field_included( 'permalink_template', $fields );
    21202121                        $generated_slug_requested     = rest_is_field_included( 'generated_slug', $fields );
    21212122
     
    25072508                );
    25082509
    25092510                $post_type_obj = get_post_type_object( $this->post_type );
    2510                 if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) {
     2511                if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public && $post_type_obj->has_single ) {
    25112512                        $schema['properties']['permalink_template'] = array(
    25122513                                'description' => __( 'Permalink template for the post.' ),
    25132514                                'type'        => 'string',
  • src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php

    a b  
    3737                $post_types = get_post_types( array( 'public' => true ), 'objects' );
    3838                unset( $post_types['attachment'] );
    3939
    40                 $post_types = array_filter( $post_types, 'is_post_type_viewable' );
     40                $post_types = array_filter(
     41                        $post_types,
     42                        static function ( $post_type ) {
     43                                return is_post_type_viewable( $post_type ) && $post_type->has_single;
     44                        }
     45                );
    4146
    4247                /**
    4348                 * Filters the list of post object sub types available within the sitemap.