Posts, Post Types/Taxonomies: Add object type specific registration filters.

Add post type and taxonomy specific registration argument hooks. 

Introduces the filters `register_{$post_type}_post_type_args` and `register_{$taxonomy}_taxonomy_args`. Introduces the actions `registered_post_type_{$post_type}` and `registered_taxonomy_{$taxonomy}`.

Props pbiron, dlh, davidbaumwald, hellofromTonya, milana_cap.
Fixes #53212.


Built from https://develop.svn.wordpress.org/trunk@53126


git-svn-id: http://core.svn.wordpress.org/trunk@52715 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-04-11 05:11:02 +00:00
parent b90d225de1
commit a009192299
5 changed files with 57 additions and 1 deletions

View File

@ -440,6 +440,21 @@ final class WP_Post_Type {
*/
$args = apply_filters( 'register_post_type_args', $args, $this->name );
$post_type = $this->name;
/**
* Filters the arguments for registering a specific post type.
*
* The dynamic portion of the filter name, `$this->name`, refers to the post type key.
*
* @since 6.0.0
*
* @param array $args Array of arguments for registering a post type.
* See the register_post_type() function for accepted arguments.
* @param string $post_type Post type key.
*/
$args = apply_filters( "register_{$post_type}_post_type_args", $args, $this->name );
$has_edit_link = ! empty( $args['_edit_link'] );
// Args prefixed with an underscore are reserved for internal use.

View File

@ -315,6 +315,22 @@ final class WP_Taxonomy {
*/
$args = apply_filters( 'register_taxonomy_args', $args, $this->name, (array) $object_type );
$taxonomy = $this->name;
/**
* Filters the arguments for registering a specific taxonomy.
*
* The dynamic portion of the filter name, `$this->name`, refers to the taxonomy key.
*
* @since 6.0.0
*
* @param array $args Array of arguments for registering a taxonomy.
* See the register_taxonomy() function for accepted arguments.
* @param string $taxonomy Taxonomy key.
* @param string[] $object_type Array of names of object types for the taxonomy.
*/
$args = apply_filters( "register_{$taxonomy}_taxonomy_args", $args, $this->name, (array) $object_type );
$defaults = array(
'labels' => array(),
'description' => '',

View File

@ -1709,6 +1709,18 @@ function register_post_type( $post_type, $args = array() ) {
*/
do_action( 'registered_post_type', $post_type, $post_type_object );
/**
* Fires after a specific post type is registered.
*
* The dynamic portion of the filter name, `$post_type`, refers to the post type key.
*
* @since 6.0.0
*
* @param string $post_type Post type.
* @param WP_Post_Type $post_type_object Arguments used to register the post type.
*/
do_action( "registered_post_type_{$post_type}", $post_type, $post_type_object );
return $post_type_object;
}

View File

@ -529,6 +529,19 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
*/
do_action( 'registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object );
/**
* Fires after a specific taxonomy is registered.
*
* The dynamic portion of the filter name, `$taxonomy`, refers to the taxonomy key.
*
* @since 6.0.0
*
* @param string $taxonomy Taxonomy slug.
* @param array|string $object_type Object type or array of object types.
* @param array $args Array of taxonomy registration arguments.
*/
do_action( "registered_taxonomy_{$taxonomy}", $taxonomy, $object_type, (array) $taxonomy_object );
return $taxonomy_object;
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-53125';
$wp_version = '6.0-alpha-53126';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.