Make WordPress Core

Changeset 12682


Ignore:
Timestamp:
01/10/2010 01:23:14 AM (17 years ago)
Author:
ryan
Message:

Post type caps. see #9674

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r12651 r12682  
    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');
    109 
    110 if ( 'publish' == $post->post_status || 'private' == $post->post_status )
     111if ( post_type_supports($post_type, 'comments') )
     112        add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
     113
     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
  • trunk/wp-admin/edit-page-form.php

    r12651 r12682  
    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');
     81
     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');
    8591
    8692$authors = get_editable_user_ids( $current_user->id, true, 'page' ); // TODO: ROLE SYSTEM
    … …  
    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');
    94 
    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);
     99        add_meta_box('revisionsdiv', __('Page Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
     100
     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');
    … …  
    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
    … …  
    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
  • trunk/wp-includes/post.php

    r12679 r12682  
    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
    … …  
    560562
    561563        return $args;
     564}
     565
     566/**
     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;
    562608}
    563609
Note: See TracChangeset for help on using the changeset viewer.