diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index d84af43857..fae04faa5f 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -99,15 +99,19 @@ foreach ( get_object_taxonomies($post_type) as $tax_name ) { if ( is_object_in_taxonomy($post_type, 'category') ) add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core'); -if ( current_theme_supports( 'post-thumbnails', $post_type ) ) +if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports($post_type, 'post-thumbnails') ) add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', $post_type, 'side', 'low'); -add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core'); -add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core'); -add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core'); +if ( post_type_supports($post_type, 'excerpts') ) + add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core'); +if ( post_type_supports($post_type, 'trackbacks') ) + add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core'); +if ( post_type_supports($post_type, 'custom-fields') ) + add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core'); do_action('dbx_post_advanced'); -add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core'); +if ( post_type_supports($post_type, 'comments') ) + add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core'); -if ( 'publish' == $post->post_status || 'private' == $post->post_status ) +if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') ) add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core'); if ( !( 'pending' == $post->post_status && !current_user_can( 'publish_posts' ) ) ) diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php index 99408e6af3..fb62af48e3 100644 --- a/wp-admin/edit-page-form.php +++ b/wp-admin/edit-page-form.php @@ -75,26 +75,32 @@ $user_ID = (int) $user_ID; require_once('includes/meta-boxes.php'); +$post_type = 'page'; + add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', 'page', 'side', 'core'); -add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', 'page', 'side', 'core'); -add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'page', 'normal', 'core'); -add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', 'page', 'normal', 'core'); -add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', 'page', 'normal', 'core'); -if ( current_theme_supports( 'post-thumbnails', 'page' ) ) - add_meta_box('postimagediv', __('Page Image'), 'post_thumbnail_meta_box', 'page', 'side', 'low'); + +if ( post_type_supports($post_type, 'page-attributes') ) + add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core'); +if ( post_type_supports($post_type, 'custom-fields') ) + add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core'); +if ( post_type_supports($post_type, 'comments') ) + add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core'); +add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core'); +if ( current_theme_supports( 'post-thumbnails', 'page' ) && post_type_supports($post_type, 'post-thumbnails') ) + add_meta_box('postimagediv', __('Page Image'), 'post_thumbnail_meta_box', $post_type, 'side', 'low'); $authors = get_editable_user_ids( $current_user->id, true, 'page' ); // TODO: ROLE SYSTEM if ( $post->post_author && !in_array($post->post_author, $authors) ) $authors[] = $post->post_author; if ( $authors && count( $authors ) > 1 ) - add_meta_box('pageauthordiv', __('Page Author'), 'post_author_meta_box', 'page', 'normal', 'core'); + add_meta_box('pageauthordiv', __('Page Author'), 'post_author_meta_box', $post_type, 'normal', 'core'); if ( 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) - add_meta_box('revisionsdiv', __('Page Revisions'), 'post_revisions_meta_box', 'page', 'normal', 'core'); + add_meta_box('revisionsdiv', __('Page Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core'); -do_action('do_meta_boxes', 'page', 'normal', $post); -do_action('do_meta_boxes', 'page', 'advanced', $post); -do_action('do_meta_boxes', 'page', 'side', $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); require_once('admin-header.php'); ?> @@ -128,7 +134,7 @@ require_once('admin-header.php');
+$side_meta_boxes = do_meta_boxes($post_type, 'side', $post); ?>
@@ -178,9 +184,9 @@ wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
diff --git a/wp-includes/post.php b/wp-includes/post.php index d4367d29e2..7c917bf476 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -19,6 +19,8 @@ function create_initial_post_types() { register_post_type( 'page', array('label' => __('Pages'),'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'page.php?post=%d', 'capability_type' => 'page', 'hierarchical' => true) ); register_post_type( 'attachment', array('label' => __('Media'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'media.php?attachment_id=%d', 'capability_type' => 'post', 'hierarchical' => false) ); register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?revision=%d', 'capability_type' => 'post', 'hierarchical' => false) ); + add_post_type_support('post', array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') ); + add_post_type_support('page', array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments') ); } add_action( 'init', 'create_initial_post_types', 0 ); // highest priority @@ -561,6 +563,50 @@ function register_post_type($post_type, $args = array()) { return $args; } +/** + * Register support of certain features for a post type. + * + * @since 3.0 + * @param string $post_type The post type for which to add the feature + * @param string|array $feature the feature being added, can be an array of feature strings or a single string + */ +function add_post_type_support( $post_type, $feature ) { + global $_wp_post_type_features; + + $features = (array) $feature; + foreach ($features as $feature) { + if ( func_num_args() == 2 ) + $_wp_post_type_features[$post_type][$feature] = true; + else + $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 ); + } +} + +/** + * Checks a post type's support for a given feature + * + * @since 3.0 + * @param string $post_type The post type being checked + * @param string $feature the feature being checked + * @return boolean + */ + +function post_type_supports( $post_type, $feature ) { + global $_wp_post_type_features; + + if ( !isset( $_wp_post_type_features[$post_type][$feature] ) ) + return false; + + // If no args passed then no extra checks need be performed + if ( func_num_args() <= 2 ) + return true; + + // @todo Allow pluggable arg checking + //$args = array_slice( func_get_args(), 2 ); + + return true; +} + /** * Updates the post type for the post ID. *