Make WordPress Core

Ticket #9674: register_meta_box_cb.diff

File register_meta_box_cb.diff, 2.6 KB (added by ryan, 15 years ago)

Allow registering a meta box callback for setting up meta boxes when creating the edit form for the post type.

  • wp-includes/post.php

     
    708708 * delete_cap - The capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post).
    709709 * hierarchical - Whether the post type is hierarchical. Defaults to false.
    710710 * supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none.
     711 * 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.
    711712 *
    712713 * @package WordPress
    713714 * @subpackage Post
     
    724725                $wp_post_types = array();
    725726
    726727        // Args prefixed with an underscore are reserved for internal use.
    727         $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());
     728        $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);
    728729        $args = wp_parse_args($args, $defaults);
    729730        $args = (object) $args;
    730731
     
    783784                $wp_rewrite->add_permastruct($post_type, "/{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front']);
    784785        }
    785786
     787        if ( $args->register_meta_box_cb )
     788                add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);
     789
    786790        $wp_post_types[$post_type] = $args;
    787791
    788792        return $args;
  • wp-admin/edit-form-advanced.php

     
    139139if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
    140140        add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
    141141
     142do_action('add_meta_boxes', $post_type, $post);
     143do_action('add_meta_boxes_' . $post_type, $post);
     144
    142145do_action('do_meta_boxes', $post_type, 'normal', $post);
    143146do_action('do_meta_boxes', $post_type, 'advanced', $post);
    144147do_action('do_meta_boxes', $post_type, 'side', $post);