WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/17/2019 07:57:18 PM (2 months ago)
Author:
desrosj
Message:

Posts, Post Types: Allow support arguments to be specified when registering post types.

The add_post_type_support() function accepts an optional third parameter that allows extra arguments to be supplied to configure post type support for a given feature. However, because of how register_post_type() and WP_Post_Type->add_supports() work, it is currently impossible to pass these additional arguments when initially registering a post type with register_post_type().

This change makes it possible to supply additional arguments for a feature using the supports argument of register_post_type().

Props MaximeCulea, seuser, desrosj, johnbillion.
Fixes #40413.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-post-type.php

    r45735 r46160  
    514514    public function add_supports() {
    515515        if ( ! empty( $this->supports ) ) {
    516             add_post_type_support( $this->name, $this->supports );
     516            foreach ( $this->supports as $feature => $args ) {
     517                if ( is_array( $args ) ) {
     518                    add_post_type_support( $this->name, $feature, $args );
     519                } else {
     520                    add_post_type_support( $this->name, $args );
     521                }
     522            }
    517523            unset( $this->supports );
    518524        } elseif ( false !== $this->supports ) {
Note: See TracChangeset for help on using the changeset viewer.