diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css
index 8d4e20db9c..c62889f5e3 100644
--- a/wp-admin/css/wp-admin.css
+++ b/wp-admin/css/wp-admin.css
@@ -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;
}
diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php
index 7d90db2b38..9e3fa9492d 100644
--- a/wp-admin/edit-form-advanced.php
+++ b/wp-admin/edit-form-advanced.php
@@ -63,6 +63,7 @@ $messages['page'] = array(
9 => sprintf( __('Page scheduled for: %1$s . Preview page '), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Page draft updated. Preview page '), 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');
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 .= '' . __('Get Shortlink') . ' ';
-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 ) ) ) { ?>
ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status )
+ if ( $sample_permalink_html && 'auto-draft' != get_post_status( $post ) )
echo $sample_permalink_html;
?>
@@ -310,10 +319,14 @@ if ( $post_type_object->public && ! ( 'pending' == $post->post_status && !curren
-
-
+
+
+do_action( 'edit_form_after_title' );
+
+if ( post_type_supports($post_type, 'editor') ) {
+?>
post_content, 'content', array('dfw' => true, 'tabfocus_elements' => 'sample-permalink,post-preview') ); ?>
@@ -323,7 +336,7 @@ wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
post_status ) {
+ if ( 'auto-draft' != get_post_status( $post ) ) {
echo '';
if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
$last_user = get_userdata($last_id);
diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php
index 1317e75ee9..bab0bd6570 100644
--- a/wp-admin/edit-tags.php
+++ b/wp-admin/edit-tags.php
@@ -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';
diff --git a/wp-admin/includes/class-wp-media-list-table.php b/wp-admin/includes/class-wp-media-list-table.php
index 465612cbb6..dc5f52c335 100644
--- a/wp-admin/includes/class-wp-media-list-table.php
+++ b/wp-admin/includes/class-wp-media-list-table.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 ) {
- >slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "";
- echo join( ', ', $out );
- } else {
- _e( 'No Tags' );
- }
-?>
-
-
>post_excerpt : ''; ?>
@@ -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 '
';
+ 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( '%s ',
+ 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 ' ';
+ break;
+ }
?>
>
diff --git a/wp-admin/includes/class-wp-terms-list-table.php b/wp-admin/includes/class-wp-terms-list-table.php
index 52e7f9c461..67ac22b56a 100644
--- a/wp-admin/includes/class-wp-terms-list-table.php
+++ b/wp-admin/includes/class-wp-terms-list-table.php
@@ -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 "$count ";
+
return "$count ";
}
diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
index 0531da2a4a..279945516c 100644
--- a/wp-admin/includes/media.php
+++ b/wp-admin/includes/media.php
@@ -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 '' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '
';
}
+/**
+ * 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 = " ";
+
+ $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 .= "{$meta['width']} × {$meta['height']} ";
+ $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 = " ";
+ }
+
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+ post_mime_type; ?>
+ ' . __( 'Dimensions:' ) . ' ' . $media_dims;
+ ?>
+
+
+
+ post_status ) {
-
+
@@ -103,7 +103,7 @@ switch ( $post->post_status ) {
-
+
-
+
post_status, array('publish', 'future', 'private') ) || 0
post_type;
+ $post_type_object = get_post_type_object($post_type);
+ $can_publish = current_user_can($post_type_object->cap->publish_posts);
+?>
+
+
+
+
+
+
+
+
+
+
+
+ %1$s');
+ $date = date_i18n( $datef, strtotime( $post->post_date ) );
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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,
+ );
+?>
+
+
+ post_content, 'attachment_content', $editor_args ); ?>
+
+
+
+
+
+
+
+
+
+
+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');
diff --git a/wp-admin/includes/screen.php b/wp-admin/includes/screen.php
index 9c13fb7e10..94792e03e7 100644
--- a/wp-admin/includes/screen.php
+++ b/wp-admin/includes/screen.php
@@ -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' );
diff --git a/wp-admin/menu.php b/wp-admin/menu.php
index a9f72e357f..26e8eabbc3 100644
--- a/wp-admin/menu.php
+++ b/wp-admin/menu.php
@@ -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' );
diff --git a/wp-admin/post.php b/wp-admin/post.php
index de5080b81d..254972d38f 100644
--- a/wp-admin/post.php
+++ b/wp-admin/post.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;
diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php
index cad7f8ab9e..a4e01a51f7 100644
--- a/wp-includes/admin-bar.php
+++ b/wp-includes/admin-bar.php
@@ -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 ) {
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index 681c53cfad..403e86ab2f 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -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 )
diff --git a/wp-includes/media.php b/wp-includes/media.php
index 19571da935..04d1475733 100644
--- a/wp-includes/media.php
+++ b/wp-includes/media.php
@@ -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
*
diff --git a/wp-includes/post.php b/wp-includes/post.php
index d7dbe1833d..cac125efc7 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -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 );