mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Use the regular post type UI for editing single media items (attachments).
* Attachments now go through post.php, edit_post(), the like, and have show_ui set to true. * Taxonomies attached to the media library now appear in the admin menu (if show_ui). * Editing, cropping, uploading, etc. is still very rough, but mostly functional. API-wise: * New function: get_taxonomies_for_attachments(). Like get_taxonomies(), for taxonomies specifically registered against attachments. * Brings taxonomy support from the posts list table to the media list table. Expect them to converge soon. * wp_insert_attachment() now handles taxonomies like wp_insert_post(). Also expect them to converge soon. * New edit_form_after_title hook. props helenyhou, ocean90. see #21391. git-svn-id: https://develop.svn.wordpress.org/trunk@21948 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -132,7 +132,26 @@ class WP_Media_List_Table extends WP_List_Table {
|
||||
/* translators: column name */
|
||||
$posts_columns['title'] = _x( 'File', 'column name' );
|
||||
$posts_columns['author'] = __( 'Author' );
|
||||
//$posts_columns['tags'] = _x( 'Tags', 'column name' );
|
||||
|
||||
$taxonomies = array();
|
||||
|
||||
$taxonomies = get_taxonomies_for_attachments( 'objects' );
|
||||
$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
|
||||
|
||||
$taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' );
|
||||
$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
|
||||
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
if ( 'category' == $taxonomy )
|
||||
$column_key = 'categories';
|
||||
elseif ( 'post_tag' == $taxonomy )
|
||||
$column_key = 'tags';
|
||||
else
|
||||
$column_key = 'taxonomy-' . $taxonomy;
|
||||
|
||||
$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
|
||||
}
|
||||
|
||||
/* translators: column name */
|
||||
if ( !$this->detached ) {
|
||||
$posts_columns['parent'] = _x( 'Attached to', 'column name' );
|
||||
@@ -251,23 +270,6 @@ foreach ( $columns as $column_name => $column_display_name ) {
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'tags':
|
||||
?>
|
||||
<td <?php echo $attributes ?>><?php
|
||||
$tags = get_the_tags();
|
||||
if ( !empty( $tags ) ) {
|
||||
$out = array();
|
||||
foreach ( $tags as $c )
|
||||
$out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "</a>";
|
||||
echo join( ', ', $out );
|
||||
} else {
|
||||
_e( 'No Tags' );
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'desc':
|
||||
?>
|
||||
<td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
|
||||
@@ -339,6 +341,38 @@ foreach ( $columns as $column_name => $column_display_name ) {
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( 'categories' == $column_name )
|
||||
$taxonomy = 'category';
|
||||
if ( 'tags' == $column_name )
|
||||
$taxonomy = 'post_tag';
|
||||
elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
|
||||
$taxonomy = substr( $column_name, 9 );
|
||||
else
|
||||
$taxonomy = false;
|
||||
|
||||
if ( $taxonomy ) {
|
||||
$taxonomy_object = get_taxonomy( $taxonomy );
|
||||
echo '<td ' . $attributes . '>';
|
||||
if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) {
|
||||
$out = array();
|
||||
foreach ( $terms as $t ) {
|
||||
$posts_in_term_qv = array();
|
||||
$posts_in_term_qv['taxonomy'] = $taxonomy;
|
||||
$posts_in_term_qv['term'] = $t->slug;
|
||||
|
||||
$out[] = sprintf( '<a href="%s">%s</a>',
|
||||
esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
|
||||
esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
|
||||
);
|
||||
}
|
||||
/* translators: used between list items, there is a space after the comma */
|
||||
echo join( __( ', ' ), $out );
|
||||
} else {
|
||||
echo '—';
|
||||
}
|
||||
echo '</td>';
|
||||
break;
|
||||
}
|
||||
?>
|
||||
<td <?php echo $attributes ?>>
|
||||
<?php do_action( 'manage_media_custom_column', $column_name, $id ); ?>
|
||||
|
||||
@@ -299,6 +299,9 @@ class WP_Terms_List_Table extends WP_List_Table {
|
||||
if ( 'post' != $this->screen->post_type )
|
||||
$args['post_type'] = $this->screen->post_type;
|
||||
|
||||
if ( 'attachment' == $this->screen->post_type )
|
||||
return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
|
||||
|
||||
return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
|
||||
}
|
||||
|
||||
|
||||
@@ -857,9 +857,9 @@ function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
|
||||
|
||||
/**
|
||||
* Filters input from media_upload_form_handler() and assigns a default
|
||||
* post_title from the file name if none supplied.
|
||||
* post_title from the file name if none supplied.
|
||||
*
|
||||
* Illustrates the use of the attachment_fields_to_save filter
|
||||
* Illustrates the use of the attachment_fields_to_save filter
|
||||
* which can be used to add default values to any field before saving to DB.
|
||||
*
|
||||
* @since 2.5.0
|
||||
@@ -2095,6 +2095,67 @@ function multisite_over_quota_message() {
|
||||
echo '<p>' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the image and editor in the post editor
|
||||
*
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function edit_form_image_editor() {
|
||||
$post = get_post();
|
||||
|
||||
$thumb_url = false;
|
||||
if ( $attachment_id = intval( $post->ID ) )
|
||||
$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 600 ), true );
|
||||
|
||||
$filename = esc_html( basename( $post->guid ) );
|
||||
$title = esc_attr( $post->post_title );
|
||||
|
||||
$post_mime_types = get_post_mime_types();
|
||||
$keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
|
||||
$type = array_shift( $keys );
|
||||
$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
|
||||
|
||||
$media_dims = '';
|
||||
$meta = wp_get_attachment_metadata( $post->ID );
|
||||
if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
|
||||
$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> ";
|
||||
$media_dims = apply_filters( 'media_meta', $media_dims, $post );
|
||||
|
||||
$att_url = wp_get_attachment_url( $post->ID );
|
||||
|
||||
$image_edit_button = '';
|
||||
if ( gd_edit_image_support( $post->post_mime_type ) ) {
|
||||
$nonce = wp_create_nonce( "image_editor-$post->ID" );
|
||||
$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <img src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' class='imgedit-wait-spin' alt='' />";
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="wp_attachment_holder">
|
||||
<div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
|
||||
|
||||
<div class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>">
|
||||
<p><img class="thumbnail" src="<?php echo $thumb_url[0]; ?>" style="max-width:100%" width="<?php echo $thumb_url[1]; ?>" alt="" /></p>
|
||||
<p><?php echo $image_edit_button; ?></p>
|
||||
</div>
|
||||
<div style="display:none" class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"></div>
|
||||
|
||||
<div class="wp_attachment_details">
|
||||
<p>
|
||||
<label for="attachment_url"><strong><?php _e( 'File URL' ); ?></strong></label><br />
|
||||
<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" /><br />
|
||||
</p>
|
||||
<p><strong><?php _e( 'File name:' ); ?></strong> <?php echo $filename; ?><br />
|
||||
<strong><?php _e( 'File type:' ); ?></strong> <?php echo $post->post_mime_type; ?>
|
||||
<?php
|
||||
if ( $media_dims )
|
||||
echo '<br /><strong>' . __( 'Dimensions:' ) . '</strong> ' . $media_dims;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
|
||||
add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
|
||||
add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
|
||||
|
||||
@@ -51,7 +51,7 @@ if ( 'publish' == $post->post_status ) {
|
||||
</div>
|
||||
<?php endif; // public post type ?>
|
||||
<div class="clear"></div>
|
||||
</div><?php // /minor-publishing-actions ?>
|
||||
</div><!-- #minor-publishing-actions -->
|
||||
|
||||
<div id="misc-publishing-actions">
|
||||
|
||||
@@ -103,7 +103,7 @@ switch ( $post->post_status ) {
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
</div><?php // /misc-pub-section ?>
|
||||
</div><!-- .misc-pub-section -->
|
||||
|
||||
<div class="misc-pub-section" id="visibility">
|
||||
<?php _e('Visibility:'); ?> <span id="post-visibility-display"><?php
|
||||
@@ -148,7 +148,7 @@ echo esc_html( $visibility_trans ); ?></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div><?php // /misc-pub-section ?>
|
||||
</div><!-- .misc-pub-section -->
|
||||
|
||||
<?php
|
||||
// translators: Publish box date format, see http://php.net/date
|
||||
@@ -229,6 +229,106 @@ if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display attachment submit form fields.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @param object $post
|
||||
*/
|
||||
function attachment_submit_meta_box( $post ) {
|
||||
global $action;
|
||||
|
||||
$post_type = $post->post_type;
|
||||
$post_type_object = get_post_type_object($post_type);
|
||||
$can_publish = current_user_can($post_type_object->cap->publish_posts);
|
||||
?>
|
||||
<div class="submitbox" id="submitpost">
|
||||
|
||||
<div id="minor-publishing">
|
||||
|
||||
<?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?>
|
||||
<div style="display:none;">
|
||||
<?php submit_button( __( 'Save' ), 'button', 'save' ); ?>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="misc-publishing-actions">
|
||||
<?php
|
||||
// translators: Publish box date format, see http://php.net/date
|
||||
$datef = __( 'M j, Y @ G:i' );
|
||||
$stamp = __('Uploaded on: <b>%1$s</b>');
|
||||
$date = date_i18n( $datef, strtotime( $post->post_date ) );
|
||||
?>
|
||||
<div class="misc-pub-section curtime">
|
||||
<span id="timestamp"><?php printf($stamp, $date); ?></span>
|
||||
</div><!-- .misc-pub-section -->
|
||||
|
||||
<?php do_action('attachment_submitbox_misc_actions'); ?>
|
||||
</div><!-- #misc-publishing-actions -->
|
||||
<div class="clear"></div>
|
||||
</div><!-- #minor-publishing -->
|
||||
|
||||
<div id="major-publishing-actions">
|
||||
<div id="delete-action">
|
||||
<?php
|
||||
if ( current_user_can( 'delete_post', $post->ID ) )
|
||||
if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
|
||||
echo "<a class='submitdelete deletion' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
|
||||
} else {
|
||||
$delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
|
||||
echo "<a class='submitdelete deletion'$delete_ays href='" . get_delete_post_link( $post->ID, null, true ) . "''>" . __( 'Delete Permanently' ) . "</a>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div id="publishing-action">
|
||||
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading" id="ajax-loading" alt="" />
|
||||
<input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Update') ?>" />
|
||||
<input name="save" type="submit" class="button-primary button-large" id="publish" accesskey="p" value="<?php esc_attr_e('Update') ?>" />
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div><!-- #major-publishing-actions -->
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display attachment/media-specific information
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @param object $post
|
||||
*/
|
||||
function attachment_data_meta_box( $post ) {
|
||||
$alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
|
||||
$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' );
|
||||
$editor_args = array(
|
||||
'textarea_name' => 'content',
|
||||
'textarea_rows' => 5,
|
||||
'media_buttons' => false,
|
||||
'tinymce' => false,
|
||||
'quicktags' => $quicktags_settings,
|
||||
);
|
||||
?>
|
||||
<p>
|
||||
<label class="screen-reader-text" for="content"><strong><?php _e( 'Attachment Page Content' ); ?></strong></label>
|
||||
<?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
|
||||
<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
|
||||
</p>
|
||||
<p>
|
||||
<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
|
||||
<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display post format form elements.
|
||||
*
|
||||
|
||||
@@ -235,6 +235,16 @@ function edit_post( $post_data = null ) {
|
||||
}
|
||||
}
|
||||
|
||||
// Attachment stuff
|
||||
if ( 'attachment' == $post_data['post_type'] && isset( $post_data['_wp_attachment_image_alt'] ) ) {
|
||||
$image_alt = get_post_meta( $post_ID, '_wp_attachment_image_alt', true );
|
||||
if ( $image_alt != stripslashes( $post_data['_wp_attachment_image_alt'] ) ) {
|
||||
$image_alt = wp_strip_all_tags( stripslashes( $post_data['_wp_attachment_image_alt'] ), true );
|
||||
// update_meta expects slashed
|
||||
update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) );
|
||||
}
|
||||
}
|
||||
|
||||
add_meta( $post_ID );
|
||||
|
||||
update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
|
||||
@@ -1064,7 +1074,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
|
||||
|
||||
list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
|
||||
|
||||
if ( 'publish' == $post->post_status ) {
|
||||
if ( 'publish' == get_post_status( $post ) ) {
|
||||
$ptype = get_post_type_object($post->post_type);
|
||||
$view_post = $ptype->labels->view_item;
|
||||
$title = __('Click to edit this part of the permalink');
|
||||
|
||||
@@ -96,7 +96,7 @@ function get_hidden_meta_boxes( $screen ) {
|
||||
if ( $use_defaults ) {
|
||||
$hidden = array();
|
||||
if ( 'post' == $screen->base ) {
|
||||
if ( 'post' == $screen->post_type || 'page' == $screen->post_type )
|
||||
if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type )
|
||||
$hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
|
||||
else
|
||||
$hidden = array( 'slugdiv' );
|
||||
|
||||
Reference in New Issue
Block a user