Make WordPress Core

Ticket #9674: 9674.12.diff

File 9674.12.diff, 7.9 KB (added by ryan, 15 years ago)

Post type capabilities (tested)

  • 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('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') );
     23        add_post_type_support('page', array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments') );
    2224}
    2325add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
    2426
     
    562564}
    563565
    564566/**
     567 * Register support of certain features for a post type.
     568 *
     569 * @since 3.0
     570 * @param string $post_type The post type for which to add the feature
     571 * @param string|array $feature the feature being added, can be an array of feature strings or a single string
     572 */
     573function add_post_type_support( $post_type, $feature ) {
     574        global $_wp_post_type_features;
     575
     576        $features = (array) $feature;
     577        foreach ($features as $feature) {
     578                if ( func_num_args() == 2 )
     579                        $_wp_post_type_features[$post_type][$feature] = true;
     580                else
     581                        $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
     582        }
     583}
     584
     585/**
     586 * Checks a post type's support for a given feature
     587 *
     588 * @since 3.0
     589 * @param string $post_type The post type being checked
     590 * @param string $feature the feature being checked
     591 * @return boolean
     592 */
     593
     594function post_type_supports( $post_type, $feature ) {
     595        global $_wp_post_type_features;
     596
     597        if ( !isset( $_wp_post_type_features[$post_type][$feature] ) )
     598                return false;
     599
     600        // If no args passed then no extra checks need be performed
     601        if ( func_num_args() <= 2 )
     602                return true;
     603
     604        // @todo Allow pluggable arg checking
     605        //$args = array_slice( func_get_args(), 2 );
     606
     607        return true;
     608}
     609
     610/**
    565611 * Updates the post type for the post ID.
    566612 *
    567613 * The page or post cache will be cleaned for the post ID.
  • wp-admin/edit-page-form.php

     
    7575
    7676require_once('includes/meta-boxes.php');
    7777
     78$post_type = 'page';
     79
    7880add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', 'page', 'side', 'core');
    79 add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', 'page', 'side', 'core');
    80 add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'page', 'normal', 'core');
    81 add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', 'page', 'normal', 'core');
    82 add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', 'page', 'normal', 'core');
    83 if ( current_theme_supports( 'post-thumbnails', 'page' ) )
    84         add_meta_box('postimagediv', __('Page Image'), 'post_thumbnail_meta_box', 'page', 'side', 'low');
    8581
     82if ( post_type_supports($post_type, 'page-attributes') )
     83        add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core');
     84if ( post_type_supports($post_type, 'custom-fields') )
     85        add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
     86if ( post_type_supports($post_type, 'comments') )
     87        add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
     88add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
     89if ( current_theme_supports( 'post-thumbnails', 'page' ) && post_type_supports($post_type, 'post-thumbnails') )
     90        add_meta_box('postimagediv', __('Page Image'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
     91
    8692$authors = get_editable_user_ids( $current_user->id, true, 'page' ); // TODO: ROLE SYSTEM
    8793if ( $post->post_author && !in_array($post->post_author, $authors) )
    8894        $authors[] = $post->post_author;
    8995if ( $authors && count( $authors ) > 1 )
    90         add_meta_box('pageauthordiv', __('Page Author'), 'post_author_meta_box', 'page', 'normal', 'core');
     96        add_meta_box('pageauthordiv', __('Page Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
    9197
    9298if ( 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
    93         add_meta_box('revisionsdiv', __('Page Revisions'), 'post_revisions_meta_box', 'page', 'normal', 'core');
     99        add_meta_box('revisionsdiv', __('Page Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
    94100
    95 do_action('do_meta_boxes', 'page', 'normal', $post);
    96 do_action('do_meta_boxes', 'page', 'advanced', $post);
    97 do_action('do_meta_boxes', 'page', 'side', $post);
     101do_action('do_meta_boxes', $post_type, 'normal', $post);
     102do_action('do_meta_boxes', $post_type, 'advanced', $post);
     103do_action('do_meta_boxes', $post_type, 'side', $post);
    98104
    99105require_once('admin-header.php');
    100106?>
     
    128134<div id="side-info-column" class="inner-sidebar">
    129135<?php
    130136do_action('submitpage_box');
    131 $side_meta_boxes = do_meta_boxes('page', 'side', $post); ?>
     137$side_meta_boxes = do_meta_boxes($post_type, 'side', $post); ?>
    132138</div>
    133139
    134140<div id="post-body">
     
    178184</div>
    179185
    180186<?php
    181 do_meta_boxes('page', 'normal', $post);
     187do_meta_boxes($post_type, 'normal', $post);
    182188do_action('edit_page_form');
    183 do_meta_boxes('page', 'advanced', $post);
     189do_meta_boxes($post_type, 'advanced', $post);
    184190?>
    185191
    186192</div>
  • wp-admin/edit-form-advanced.php

     
    9999
    100100if ( is_object_in_taxonomy($post_type, 'category') )
    101101        add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core');
    102 if ( current_theme_supports( 'post-thumbnails', $post_type ) )
     102if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports($post_type, 'post-thumbnails') )
    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' ) ) )