From 5bc5965535d4e58437f6a9da3a445c4db1aa080f Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 3 Feb 2010 18:54:42 +0000 Subject: [PATCH] Allow registering a meta box callback for setting up meta boxes when creating the edit form for a custom post type. see #9674 git-svn-id: https://develop.svn.wordpress.org/trunk@12937 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/edit-form-advanced.php | 3 +++ wp-includes/post.php | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 85a2b0b837..5a3377194e 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -139,6 +139,9 @@ if ( $authors && count( $authors ) > 1 ) if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core'); +do_action('add_meta_boxes', $post_type, $post); +do_action('add_meta_boxes_' . $post_type, $post); + do_action('do_meta_boxes', $post_type, 'normal', $post); do_action('do_meta_boxes', $post_type, 'advanced', $post); do_action('do_meta_boxes', $post_type, 'side', $post); diff --git a/wp-includes/post.php b/wp-includes/post.php index 90d63b14ed..23e6ebd3de 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -708,6 +708,7 @@ function get_post_types( $args = array(), $output = 'names' ) { * delete_cap - The capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post). * hierarchical - Whether the post type is hierarchical. Defaults to false. * supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none. + * register_meta_box_cb - Provide a callback function that will be called when setting up the meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback. * * @package WordPress * @subpackage Post @@ -724,7 +725,7 @@ function register_post_type($post_type, $args = array()) { $wp_post_types = array(); // Args prefixed with an underscore are reserved for internal use. - $defaults = array('label' => false, 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array()); + $defaults = array('label' => false, 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null); $args = wp_parse_args($args, $defaults); $args = (object) $args; @@ -783,6 +784,9 @@ function register_post_type($post_type, $args = array()) { $wp_rewrite->add_permastruct($post_type, "/{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front']); } + if ( $args->register_meta_box_cb ) + add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); + $wp_post_types[$post_type] = $args; return $args;