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: http://core.svn.wordpress.org/trunk@21948 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ffaa2d0330
commit
33af30eb7f
|
@ -3759,7 +3759,7 @@ abbr.required {
|
|||
}
|
||||
|
||||
.upload-php .fixed .column-parent {
|
||||
width: 25%;
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.js .html-uploader #plupload-upload-ui {
|
||||
|
@ -3938,7 +3938,8 @@ borger color while dragging a file over the uploader drop area */
|
|||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.describe .imgedit-wrap table td {
|
||||
.describe .imgedit-wrap table td,
|
||||
.wp_attachment_holder .imgedit-wrap table td {
|
||||
vertical-align: top;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ $messages['page'] = array(
|
|||
9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
|
||||
10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
|
||||
);
|
||||
$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated' ) ); // Hack, for now.
|
||||
|
||||
$messages = apply_filters( 'post_updated_messages', $messages );
|
||||
|
||||
|
@ -77,7 +78,7 @@ if ( isset($_GET['message']) ) {
|
|||
|
||||
$notice = false;
|
||||
$form_extra = '';
|
||||
if ( 'auto-draft' == $post->post_status ) {
|
||||
if ( 'auto-draft' == get_post_status( $post ) ) {
|
||||
if ( 'edit' == $action )
|
||||
$post->post_title = '';
|
||||
$autosave = false;
|
||||
|
@ -106,13 +107,21 @@ $post_type_object = get_post_type_object($post_type);
|
|||
// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
|
||||
require_once('./includes/meta-boxes.php');
|
||||
|
||||
add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core');
|
||||
if ( 'attachment' == $post_type ) {
|
||||
wp_enqueue_script( 'image-edit' );
|
||||
wp_enqueue_style( 'imgareaselect' );
|
||||
add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' );
|
||||
add_meta_box( 'attachmentdata', __('Attachment Page Content'), 'attachment_data_meta_box', null, 'normal', 'core' );
|
||||
add_action( 'edit_form_after_title', 'edit_form_image_editor' );
|
||||
} else {
|
||||
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' );
|
||||
}
|
||||
|
||||
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) )
|
||||
add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' );
|
||||
|
||||
// all taxonomies
|
||||
foreach ( get_object_taxonomies($post_type) as $tax_name ) {
|
||||
foreach ( get_object_taxonomies( $post ) as $tax_name ) {
|
||||
$taxonomy = get_taxonomy($tax_name);
|
||||
if ( ! $taxonomy->show_ui )
|
||||
continue;
|
||||
|
@ -144,10 +153,10 @@ do_action('dbx_post_advanced');
|
|||
if ( post_type_supports($post_type, 'comments') )
|
||||
add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core');
|
||||
|
||||
if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
|
||||
if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') )
|
||||
add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
|
||||
|
||||
if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) )
|
||||
if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )
|
||||
add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
|
||||
|
||||
if ( post_type_supports($post_type, 'author') ) {
|
||||
|
@ -269,7 +278,7 @@ require_once('./admin-header.php');
|
|||
<input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" />
|
||||
<?php
|
||||
}
|
||||
if ( 'draft' != $post->post_status )
|
||||
if ( 'draft' != get_post_status( $post ) )
|
||||
wp_original_referer_field(true, 'previous');
|
||||
|
||||
echo $form_extra;
|
||||
|
@ -296,10 +305,10 @@ $shortlink = wp_get_shortlink($post->ID, 'post');
|
|||
if ( !empty($shortlink) )
|
||||
$sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt('URL:', jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
|
||||
|
||||
if ( $post_type_object->public && ! ( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
|
||||
if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
|
||||
<div id="edit-slug-box">
|
||||
<?php
|
||||
if ( ! empty($post->ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status )
|
||||
if ( $sample_permalink_html && 'auto-draft' != get_post_status( $post ) )
|
||||
echo $sample_permalink_html;
|
||||
?>
|
||||
</div>
|
||||
|
@ -310,10 +319,14 @@ if ( $post_type_object->public && ! ( 'pending' == $post->post_status && !curren
|
|||
<?php
|
||||
wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
|
||||
?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div><!-- /titlediv -->
|
||||
<?php
|
||||
}
|
||||
|
||||
<?php if ( post_type_supports($post_type, 'editor') ) { ?>
|
||||
do_action( 'edit_form_after_title' );
|
||||
|
||||
if ( post_type_supports($post_type, 'editor') ) {
|
||||
?>
|
||||
<div id="postdivrich" class="postarea">
|
||||
|
||||
<?php wp_editor($post->post_content, 'content', array('dfw' => true, 'tabfocus_elements' => 'sample-permalink,post-preview') ); ?>
|
||||
|
@ -323,7 +336,7 @@ wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
|
|||
<td class="autosave-info">
|
||||
<span class="autosave-message"> </span>
|
||||
<?php
|
||||
if ( 'auto-draft' != $post->post_status ) {
|
||||
if ( 'auto-draft' != get_post_status( $post ) ) {
|
||||
echo '<span id="last-edit">';
|
||||
if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
|
||||
$last_user = get_userdata($last_id);
|
||||
|
|
|
@ -26,7 +26,7 @@ $pagenum = $wp_list_table->get_pagenum();
|
|||
$title = $tax->labels->name;
|
||||
|
||||
if ( 'post' != $post_type ) {
|
||||
$parent_file = "edit.php?post_type=$post_type";
|
||||
$parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type";
|
||||
$submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type";
|
||||
} else if ( 'link_category' == $tax->name ) {
|
||||
$parent_file = 'link-manager.php';
|
||||
|
|
|
@ -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' );
|
||||
|
|
|
@ -64,6 +64,13 @@ $menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top menu
|
|||
$submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
|
||||
/* translators: add new file */
|
||||
$submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php');
|
||||
foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) {
|
||||
if ( ! $tax->show_ui )
|
||||
continue;
|
||||
|
||||
$submenu['upload.php'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=attachment' );
|
||||
}
|
||||
unset($tax);
|
||||
|
||||
$menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'none' );
|
||||
$submenu['link-manager.php'][5] = array( _x('All Links', 'admin menu'), 'manage_links', 'link-manager.php' );
|
||||
|
|
|
@ -85,8 +85,12 @@ $sendback = wp_get_referer();
|
|||
if ( ! $sendback ||
|
||||
strpos( $sendback, 'post.php' ) !== false ||
|
||||
strpos( $sendback, 'post-new.php' ) !== false ) {
|
||||
$sendback = admin_url( 'edit.php' );
|
||||
$sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : '';
|
||||
if ( 'attachment' == $post_type ) {
|
||||
$sendback = admin_url( 'upload.php' );
|
||||
} else {
|
||||
$sendback = admin_url( 'edit.php' );
|
||||
$sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : '';
|
||||
}
|
||||
} else {
|
||||
$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
|
||||
}
|
||||
|
@ -148,6 +152,10 @@ case 'edit':
|
|||
$parent_file = "edit.php";
|
||||
$submenu_file = "edit.php";
|
||||
$post_new_file = "post-new.php";
|
||||
} elseif ( 'attachment' == $post_type ) {
|
||||
$parent_file = 'upload.php';
|
||||
$submenu_file = 'upload.php';
|
||||
$post_new_file = 'media-new.php';
|
||||
} else {
|
||||
if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true )
|
||||
$parent_file = $post_type_object->show_in_menu;
|
||||
|
|
|
@ -487,21 +487,19 @@ function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
|
|||
|
||||
$cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
|
||||
|
||||
if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) {
|
||||
if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) )
|
||||
$actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
|
||||
unset( $cpts['post'] );
|
||||
}
|
||||
|
||||
if ( current_user_can( 'upload_files' ) )
|
||||
$actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
|
||||
if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
|
||||
$actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
|
||||
|
||||
if ( current_user_can( 'manage_links' ) )
|
||||
$actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
|
||||
|
||||
if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) {
|
||||
if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) )
|
||||
$actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
|
||||
unset( $cpts['page'] );
|
||||
}
|
||||
|
||||
unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
|
||||
|
||||
// Add any additional custom post types.
|
||||
foreach ( $cpts as $cpt ) {
|
||||
|
|
|
@ -106,7 +106,7 @@ function get_permalink( $id = 0, $leavename = false ) {
|
|||
if ( $post->post_type == 'page' )
|
||||
return get_page_link($post->ID, $leavename, $sample);
|
||||
elseif ( $post->post_type == 'attachment' )
|
||||
return get_attachment_link($post->ID);
|
||||
return get_attachment_link( $post->ID, $leavename );
|
||||
elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
|
||||
return get_post_permalink($post->ID, $leavename, $sample);
|
||||
|
||||
|
@ -292,9 +292,10 @@ function _get_page_link( $post = false, $leavename = false, $sample = false ) {
|
|||
* @since 2.0.0
|
||||
*
|
||||
* @param mixed $post Optional. Post ID or object.
|
||||
* @param bool $leavename Optional. Leave name.
|
||||
* @return string
|
||||
*/
|
||||
function get_attachment_link( $post = null ) {
|
||||
function get_attachment_link( $post = null, $leavename = false ) {
|
||||
global $wp_rewrite;
|
||||
|
||||
$link = false;
|
||||
|
@ -314,7 +315,10 @@ function get_attachment_link( $post = null ) {
|
|||
$name = $post->post_name;
|
||||
|
||||
if ( strpos($parentlink, '?') === false )
|
||||
$link = user_trailingslashit( trailingslashit($parentlink) . $name );
|
||||
$link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' );
|
||||
|
||||
if ( ! $leavename )
|
||||
$link = str_replace( '%postname%', $name, $link );
|
||||
}
|
||||
|
||||
if ( ! $link )
|
||||
|
|
|
@ -985,6 +985,35 @@ function get_attachment_taxonomies($attachment) {
|
|||
return array_unique($taxonomies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the taxonomy names that are registered for attachments.
|
||||
*
|
||||
* Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @see get_attachment_taxonomies()
|
||||
* @uses get_taxonomies()
|
||||
*
|
||||
* @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
|
||||
* @return array The names of all taxonomy of $object_type.
|
||||
*/
|
||||
function get_taxonomies_for_attachments( $output = 'names' ) {
|
||||
$taxonomies = array();
|
||||
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
|
||||
foreach ( $taxonomy->object_type as $object_type ) {
|
||||
if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
|
||||
if ( 'names' == $output )
|
||||
$taxonomies[] = $taxonomy->name;
|
||||
else
|
||||
$taxonomies[ $taxonomy->name ] = $taxonomy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $taxonomies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the installed version of GD supports particular image type
|
||||
*
|
||||
|
|
|
@ -52,13 +52,16 @@ function create_initial_post_types() {
|
|||
|
||||
register_post_type( 'attachment', array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Media' ),
|
||||
'edit_item' => __( 'Edit Media' ),
|
||||
'name' => _x('Media', 'post type general name'),
|
||||
'name_admin_bar' => _x( 'Media', 'add new from admin bar' ),
|
||||
'add_new' => _x( 'Add New', 'add new media' ),
|
||||
'edit_item' => __( 'Edit Media' ),
|
||||
'view_item' => __( 'View Attachment Page' ),
|
||||
),
|
||||
'public' => true,
|
||||
'show_ui' => false,
|
||||
'show_ui' => true,
|
||||
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
||||
'_edit_link' => 'media.php?attachment_id=%d', /* internal use only. don't use this when registering your own post type. */
|
||||
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
|
||||
'capability_type' => 'post',
|
||||
'map_meta_cap' => true,
|
||||
'hierarchical' => false,
|
||||
|
@ -66,7 +69,7 @@ function create_initial_post_types() {
|
|||
'query_var' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'delete_with_user' => true,
|
||||
'supports' => array( 'comments', 'author' ),
|
||||
'supports' => array( 'title', 'author', 'comments' ),
|
||||
) );
|
||||
|
||||
register_post_type( 'revision', array(
|
||||
|
@ -3768,13 +3771,12 @@ function wp_insert_attachment($object, $file = false, $parent = 0) {
|
|||
if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) )
|
||||
$post_status = 'inherit';
|
||||
|
||||
if ( !empty($post_category) )
|
||||
$post_category = array_filter($post_category); // Filter out empty terms
|
||||
|
||||
// Make sure we set a valid category.
|
||||
if ( !isset($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
|
||||
// 'post' requires at least one category.
|
||||
if ( 'post' == $post_type )
|
||||
$post_category = array( get_option('default_category') );
|
||||
else
|
||||
$post_category = array();
|
||||
if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
|
||||
$post_category = array();
|
||||
}
|
||||
|
||||
// Are we updating or creating?
|
||||
|
@ -3859,7 +3861,22 @@ function wp_insert_attachment($object, $file = false, $parent = 0) {
|
|||
$wpdb->update( $wpdb->posts, compact("post_name"), array( 'ID' => $post_ID ) );
|
||||
}
|
||||
|
||||
wp_set_post_categories($post_ID, $post_category);
|
||||
if ( is_object_in_taxonomy($post_type, 'category') )
|
||||
wp_set_post_categories( $post_ID, $post_category );
|
||||
|
||||
if ( isset( $tags_input ) && is_object_in_taxonomy($post_type, 'post_tag') )
|
||||
wp_set_post_tags( $post_ID, $tags_input );
|
||||
|
||||
// support for all custom taxonomies
|
||||
if ( !empty($tax_input) ) {
|
||||
foreach ( $tax_input as $taxonomy => $tags ) {
|
||||
$taxonomy_obj = get_taxonomy($taxonomy);
|
||||
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
|
||||
$tags = array_filter($tags);
|
||||
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
|
||||
wp_set_post_terms( $post_ID, $tags, $taxonomy );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $file )
|
||||
update_attached_file( $post_ID, $file );
|
||||
|
|
Loading…
Reference in New Issue