Make WordPress Core

Ticket #9674: 9674.11.diff

File 9674.11.diff, 4.3 KB (added by ryan, 15 years ago)

Post type capabilities (incomplete and untested)

  • wp-includes/post.php

     
    1919        register_post_type( 'page', array('label' => __('Pages'),'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'page.php?post=%d', 'capability_type' => 'page', 'hierarchical' => true) );
    2020        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) );
    2121        register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?revision=%d', 'capability_type' => 'post', 'hierarchical' => false) );
     22        add_post_type_support('post', array('thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') );
    2223}
    2324add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
    2425
     
    562563}
    563564
    564565/**
     566 * Register support of certain features for a post type.
     567 *
     568 * @since 3.0
     569 * @param string $post_type The post type for which to add the feature
     570 * @param string|array $feature the feature being added, can be an array of feature strings or a single string
     571 */
     572function add_post_type_support( $post_type, $feature ) {
     573        global $_wp_post_type_features;
     574
     575        $features = array($feature);
     576        foreach ($features as $feature) {
     577                if ( func_num_args() == 2 )
     578                        $_wp_post_type_features[$post_type][$feature] = true;
     579                else
     580                        $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
     581        }
     582}
     583
     584/**
     585 * Checks a post type's support for a given feature
     586 *
     587 * @since 3.0
     588 * @param string $post_type The post type being checked
     589 * @param string $feature the feature being checked
     590 * @return boolean
     591 */
     592
     593function post_type_supports( $post_type, $feature ) {
     594        global $_wp_post_type_features;
     595
     596        if ( !isset( $_wp_post_type_features[$post_type][$feature] ) )
     597                return false;
     598
     599        // If no args passed then no extra checks need be performed
     600        if ( func_num_args() <= 2 )
     601                return true;
     602
     603        // @todo Allow pluggable arg checking
     604        //$args = array_slice( func_get_args(), 2 );
     605
     606        return true;
     607}
     608
     609/**
    565610 * Updates the post type for the post ID.
    566611 *
    567612 * The page or post cache will be cleaned for the post ID.
  • wp-admin/edit-form-advanced.php

     
    101101        add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core');
    102102if ( current_theme_supports( 'post-thumbnails', $post_type ) )
    103103        add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
    104 add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
    105 add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
    106 add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
     104if ( post_type_supports($post_type, 'excerpts') )
     105        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
     106if ( post_type_supports($post_type, 'trackbacks') )
     107        add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
     108if ( post_type_supports($post_type, 'custom-fields') )
     109        add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
    107110do_action('dbx_post_advanced');
    108 add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
     111if ( post_type_supports($post_type, 'comments') )
     112        add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
    109113
    110 if ( 'publish' == $post->post_status || 'private' == $post->post_status )
     114if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
    111115        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core');
    112116
    113117if ( !( 'pending' == $post->post_status && !current_user_can( 'publish_posts' ) ) )