Make WordPress Core

Ticket #21391: attachment_editing_scratch.diff

File attachment_editing_scratch.diff, 12.3 KB (added by helenyhou, 13 years ago)

The roughest of all rough patches, so the general direction can be seen. Specifically deals with (much) of the publish metabox.

  • wp-includes/post.php

     
    5353        register_post_type( 'attachment', array(
    5454                'labels' => array(
    5555                        'name' => __( 'Media' ),
     56                        'name' => _x('Media', 'post type general name'),
     57                        'singular_name' => _x( 'Media Item', 'post type singular name' ),
     58                        'add_new' => _x( 'Add New', 'media item'),
     59                        'add_new_item' => __( 'Add New Media' ),
    5660                        'edit_item' => __( 'Edit Media' ),
     61                        'new_item' => __( 'New Media Item' ),
     62                        'view_item' => __( 'View Attachment Page' ),
     63                        'search_items' => __( 'Search Media' ),
     64                        'not_found' => __( 'No media found.' ),
     65                        'not_found_in_trash' => __('No media found in Trash.'),
     66                        'parent_item_colon' => __('Parent:'),
     67                        'all_items' => __( 'All Media' ),
    5768                ),
    5869                'public' => true,
    59                 'show_ui' => false,
     70                'show_ui' => true,
    6071                '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    61                 '_edit_link' => 'media.php?attachment_id=%d', /* internal use only. don't use this when registering your own post type. */
     72                '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
    6273                'capability_type' => 'post',
    6374                'map_meta_cap' => true,
    6475                'hierarchical' => false,
     
    6677                'query_var' => false,
    6778                'show_in_nav_menus' => false,
    6879                'delete_with_user' => true,
    69                 'supports' => array( 'comments', 'author' ),
     80                'supports' => array( 'title', 'editor', 'author', 'excerpt', 'comments' ),
     81                'disables' => array( 'save', 'preview', 'post_status', 'visibility' )
    7082        ) );
    7183
    7284        register_post_type( 'revision', array(
     
    10751087                'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null,
    10761088                '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false,
    10771089                'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true,
    1078                 'supports' => array(), 'register_meta_box_cb' => null,
     1090                'supports' => array(), 'disables' => array(), 'register_meta_box_cb' => null,
    10791091                'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
    10801092                'can_export' => true,
    10811093                'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
     
    11351147                add_post_type_support($post_type, array('title', 'editor'));
    11361148        }
    11371149
     1150        if ( ! empty($args->disables) ) {
     1151                disable_for_post_type($post_type, $args->disables);
     1152                unset($args->disables);
     1153        }
     1154
    11381155        if ( false !== $args->query_var && !empty($wp) ) {
    11391156                if ( true === $args->query_var )
    11401157                        $args->query_var = $post_type;
     
    14921509}
    14931510
    14941511/**
     1512 * Disable long-existing features for a post type
     1513 *
     1514 * Can't later add post type support for certain things
     1515 *
     1516 * @since 3.5.0
     1517 * @param string $post_type The post type for which to remove the feature
     1518 * @param string|array $feature the feature being removed, can be an array of feature strings or a single string
     1519 */
     1520function disable_for_post_type( $post_type, $feature ) {
     1521        global $_wp_post_type_disabled;
     1522
     1523        $features = (array) $feature;
     1524        foreach ($features as $feature) {
     1525                if ( func_num_args() == 2 )
     1526                        $_wp_post_type_disabled[$post_type][$feature] = true;
     1527                else
     1528                        $_wp_post_type_disabled[$post_type][$feature] = array_slice( func_get_args(), 2 );
     1529        }
     1530}
     1531
     1532/**
     1533 * Get all the disabled post type features
     1534 *
     1535 * @since 3.5.0
     1536 * @param string $post_type The post type
     1537 * @return array
     1538 */
     1539
     1540function get_all_disabled_for_post_type( $post_type ) {
     1541        global $_wp_post_type_disabled;
     1542
     1543        if ( isset( $_wp_post_type_disabled[$post_type] ) )
     1544                return $_wp_post_type_disabled[$post_type];
     1545
     1546        return array();
     1547}
     1548
     1549/**
     1550 * Checks whether a post type disables a given feature
     1551 *
     1552 * @since 3.5.0
     1553 * @param string $post_type The post type being checked
     1554 * @param string $feature the feature being checked
     1555 * @return boolean
     1556 */
     1557
     1558function post_type_disables( $post_type, $feature ) {
     1559        global $_wp_post_type_disabled;
     1560
     1561        if ( !isset( $_wp_post_type_disabled[$post_type][$feature] ) )
     1562                return false;
     1563
     1564        // If no args passed then no extra checks need be performed
     1565        if ( func_num_args() <= 2 )
     1566                return true;
     1567
     1568        return true;
     1569}
     1570
     1571/**
    14951572 * Updates the post type for the post ID.
    14961573 *
    14971574 * The page or post cache will be cleaned for the post ID.
  • wp-admin/includes/post.php

     
    10831083
    10841084        list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    10851085
    1086         if ( 'publish' == $post->post_status ) {
     1086        if ( 'publish' == get_post_status( $post ) ) {
    10871087                $ptype = get_post_type_object($post->post_type);
    10881088                $view_post = $ptype->labels->view_item;
    10891089                $title = __('Click to edit this part of the permalink');
  • wp-admin/includes/meta-boxes.php

     
    2626</div>
    2727
    2828<div id="minor-publishing-actions">
     29<?php if ( ! post_type_disables( $post->post_type, 'save' ) ) : ?>
    2930<div id="save-action">
    3031<?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?>
    3132<input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" class="button button-highlighted" />
     
    3435<?php } ?>
    3536<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading" id="draft-ajax-loading" alt="" />
    3637</div>
    37 <?php if ( $post_type_object->public ) : ?>
     38<?php endif; // doesn't disable save button ?>
     39<?php if ( ! post_type_disables( $post->post_type, 'preview' ) && $post_type_object->public ) : ?>
    3840<div id="preview-action">
    3941<?php
    4042if ( 'publish' == $post->post_status ) {
     
    5759
    5860<div id="misc-publishing-actions">
    5961
     62<?php if ( ! post_type_disables( $post->post_type, 'post_status' ) ) : ?>
    6063<div class="misc-pub-section"><label for="post_status"><?php _e('Status:') ?></label>
     64
    6165<span id="post-status-display">
    6266<?php
    6367switch ( $post->post_status ) {
     
    106110
    107111<?php } ?>
    108112</div><?php // /misc-pub-section ?>
     113<?php endif; // doesn't disable post_status ?>
    109114
     115<?php if ( ! post_type_disables( $post->post_type, 'visibility' ) ) : ?>
    110116<div class="misc-pub-section" id="visibility">
    111117<?php _e('Visibility:'); ?> <span id="post-visibility-display"><?php
    112118
     
    151157<?php } ?>
    152158
    153159</div><?php // /misc-pub-section ?>
     160<?php endif; // doesn't disable visibility ?>
    154161
    155162<?php
    156163// translators: Publish box date format, see http://php.net/date
     
    204211<div id="publishing-action">
    205212<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading" id="ajax-loading" alt="" />
    206213<?php
    207 if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) {
     214if ( !in_array( $post->post_status, apply_filters( 'post_stati_published', array('publish', 'future', 'private', 'inherit') ) ) || 0 == $post->ID ) {
    208215        if ( $can_publish ) :
    209216                if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?>
    210217                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" />
  • wp-admin/includes/screen.php

     
    9696        if ( $use_defaults ) {
    9797                $hidden = array();
    9898                if ( 'post' == $screen->base ) {
    99                         if ( 'post' == $screen->post_type || 'page' == $screen->post_type )
     99                        if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type )
    100100                                $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
    101101                        else
    102102                                $hidden = array( 'slugdiv' );
  • wp-admin/post.php

     
    3131if ( $post ) {
    3232        $post_type = $post->post_type;
    3333        $post_type_object = get_post_type_object( $post_type );
     34        $parent_file = 'upload.php';
    3435}
    3536
    3637/**
     
    148149                $parent_file = "edit.php";
    149150                $submenu_file = "edit.php";
    150151                $post_new_file = "post-new.php";
     152        } elseif ( 'attachment' === $post_type ) {
     153                $parent_file = 'upload.php';
     154                $submenu_file = 'upload.php';
     155                $post_new_file = 'media-new.php';
    151156        } else {
    152157                if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true )
    153158                        $parent_file = $post_type_object->show_in_menu;
  • wp-admin/edit-form-advanced.php

     
    7373
    7474$notice = false;
    7575$form_extra = '';
    76 if ( 'auto-draft' == $post->post_status ) {
     76if ( 'auto-draft' == get_post_status( $post ) ) {
    7777        if ( 'edit' == $action )
    7878                $post->post_title = '';
    7979        $autosave = false;
     
    140140if ( post_type_supports($post_type, 'comments') )
    141141        add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core');
    142142
    143 if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
     143if ( ('publish' == get_post_status( $post ) || 'private' == get_post_status( $post )) && post_type_supports($post_type, 'comments') )
    144144        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
    145145
    146 if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) )
     146if ( !( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) )
    147147        add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
    148148
    149149if ( post_type_supports($post_type, 'author') ) {
     
    259259<input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ) ?>" />
    260260<input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
    261261<input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post_type ) ?>" />
    262 <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status) ?>" />
     262<input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ) ?>" />
    263263<input type="hidden" id="referredby" name="referredby" value="<?php echo esc_url(stripslashes(wp_get_referer())); ?>" />
    264264<?php if ( ! empty( $active_post_lock ) ) { ?>
    265265<input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" />
    266266<?php
    267267}
    268 if ( 'draft' != $post->post_status )
     268if ( 'draft' != get_post_status( $post ) )
    269269        wp_original_referer_field(true, 'previous');
    270270
    271271echo $form_extra;
     
    292292if ( !empty($shortlink) )
    293293    $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
    294294
    295 if ( $post_type_object->public && ! ( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
     295if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
    296296        <div id="edit-slug-box">
    297297        <?php
    298                 if ( ! empty($post->ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status )
     298                if ( ! empty($post->ID) && ! empty($sample_permalink_html) && 'auto-draft' != get_post_status( $post ) )
    299299                        echo $sample_permalink_html;
    300300        ?>
    301301        </div>
     
    319319        <td class="autosave-info">
    320320        <span class="autosave-message">&nbsp;</span>
    321321<?php
    322         if ( 'auto-draft' != $post->post_status ) {
     322        if ( 'auto-draft' != get_post_status( $post ) ) {
    323323                echo '<span id="last-edit">';
    324324                if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
    325325                        $last_user = get_userdata($last_id);