WordPress.org

Make WordPress Core

Ticket #43746: 43746.diff

File 43746.diff, 4.4 KB (added by soulseekah, 3 years ago)
  • src/wp-includes/class-wp-post-type.php

    diff --git src/wp-includes/class-wp-post-type.php src/wp-includes/class-wp-post-type.php
    index ba37a02..27de268 100644
    final class WP_Post_Type { 
    489489                        if ( ! isset( $args['rewrite']['feeds'] ) || ! $args['has_archive'] ) {
    490490                                $args['rewrite']['feeds'] = (bool) $args['has_archive'];
    491491                        }
     492                        if ( ! isset( $args['rewrite']['single_feed'] ) ) {
     493                                $args['rewrite']['single_feed'] = false;
     494                        }
    492495                        if ( ! isset( $args['rewrite']['ep_mask'] ) ) {
    493496                                if ( isset( $args['permalink_epmask'] ) ) {
    494497                                        $args['rewrite']['ep_mask'] = $args['permalink_epmask'];
    final class WP_Post_Type { 
    562565                                }
    563566                        }
    564567
     568                        // Add comment feed.
     569                        if ( $this->rewrite['single_feed'] ) {
     570                                $slug  = $this->rewrite['slug'];
     571                                $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
     572                                if ( $this->hierarchical ) {
     573                                        $match   = '(.+?)';
     574                                        $rewrite = $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=";
     575                                } else {
     576                                        $match   = '([^/]+)';
     577                                        $rewrite = $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=";
     578                                }
     579                                add_rewrite_rule( "$slug/$match/feed/$feeds/?", $rewrite, 'top' );
     580                                add_rewrite_rule( "$slug/$match/$feeds/?", $rewrite, 'top' );
     581                        }
     582
    565583                        $permastruct_args         = $this->rewrite;
    566584                        $permastruct_args['feed'] = $permastruct_args['feeds'];
    567585                        add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $permastruct_args );
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index cb5025f..80891a0 100644
    function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) 
    11581158 * @since 4.6.0 Post type object returned is now an instance of `WP_Post_Type`.
    11591159 * @since 4.7.0 Introduced `show_in_rest`, `rest_base` and `rest_controller_class`
    11601160 *              arguments to register the post type in REST API.
     1161 * @since 5.0.0 Introduced the `single_feed` rewrite parameter that builds
     1162 *              single feed rewrites for custom post types if needed.
    11611163 *
    11621164 * @global array $wp_post_types List of post types.
    11631165 *
    function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) 
    12451247 *         Defaults to true, using $post_type as slug. To specify rewrite rules, an array can be
    12461248 *         passed with any of these keys:
    12471249 *
    1248  *         @type string $slug       Customize the permastruct slug. Defaults to $post_type key.
    1249  *         @type bool   $with_front Whether the permastruct should be prepended with WP_Rewrite::$front.
    1250  *                                  Default true.
    1251  *         @type bool   $feeds      Whether the feed permastruct should be built for this post type.
    1252  *                                  Default is value of $has_archive.
    1253  *         @type bool   $pages      Whether the permastruct should provide for pagination. Default true.
    1254  *         @type const  $ep_mask    Endpoint mask to assign. If not specified and permalink_epmask is set,
    1255  *                                  inherits from $permalink_epmask. If not specified and permalink_epmask
    1256  *                                  is not set, defaults to EP_PERMALINK.
     1250 *         @type string $slug        Customize the permastruct slug. Defaults to $post_type key.
     1251 *         @type bool   $with_front  Whether the permastruct should be prepended with WP_Rewrite::$front.
     1252 *                                   Default true.
     1253 *         @type bool   $feeds       Whether the feed permastruct should be built for this post type.
     1254 *                                   Default is value of $has_archive.
     1255 *         @type bool   $single_feed Whether a single feed permasturct should be built for this post type.
     1256 *                                   Default false.
     1257 *         @type bool   $pages       Whether the permastruct should provide for pagination. Default true.
     1258 *         @type const  $ep_mask     Endpoint mask to assign. If not specified and permalink_epmask is set,
     1259 *                                   inherits from $permalink_epmask. If not specified and permalink_epmask
     1260 *                                   is not set, defaults to EP_PERMALINK.
    12571261 *     }
    12581262 *     @type string|bool $query_var             Sets the query_var key for this post type. Defaults to $post_type
    12591263 *                                              key. If false, a post type cannot be loaded at