From a0091922991679bb58fe08e46284c1495ef6354b Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 11 Apr 2022 05:11:02 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-post-type.php | 15 +++++++++++++++ wp-includes/class-wp-taxonomy.php | 16 ++++++++++++++++ wp-includes/post.php | 12 ++++++++++++ wp-includes/taxonomy.php | 13 +++++++++++++ wp-includes/version.php | 2 +- 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-post-type.php b/wp-includes/class-wp-post-type.php index b5e4caa14c..777ef58dce 100644 --- a/wp-includes/class-wp-post-type.php +++ b/wp-includes/class-wp-post-type.php @@ -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. diff --git a/wp-includes/class-wp-taxonomy.php b/wp-includes/class-wp-taxonomy.php index 27b04d952b..72f039adcd 100644 --- a/wp-includes/class-wp-taxonomy.php +++ b/wp-includes/class-wp-taxonomy.php @@ -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' => '', diff --git a/wp-includes/post.php b/wp-includes/post.php index f0d5750494..0793de3760 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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; } diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 2f3298e142..fa6c2c641a 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -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; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 3bc6da94e0..ecfb9b49fd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.