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.
Built from https://develop.svn.wordpress.org/trunk@46160


git-svn-id: http://core.svn.wordpress.org/trunk@45972 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2019-09-17 19:58:56 +00:00
parent d4928fb9cd
commit a969ce8edf
2 changed files with 8 additions and 2 deletions

View File

@ -513,7 +513,13 @@ final class WP_Post_Type {
*/ */
public function add_supports() { public function add_supports() {
if ( ! empty( $this->supports ) ) { if ( ! empty( $this->supports ) ) {
add_post_type_support( $this->name, $this->supports ); foreach ( $this->supports as $feature => $args ) {
if ( is_array( $args ) ) {
add_post_type_support( $this->name, $feature, $args );
} else {
add_post_type_support( $this->name, $args );
}
}
unset( $this->supports ); unset( $this->supports );
} elseif ( false !== $this->supports ) { } elseif ( false !== $this->supports ) {
// Add default features. // Add default features.

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.3-alpha-46159'; $wp_version = '5.3-alpha-46160';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.