<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[28788] trunk: Reinstate the changes from [28579] with some adjustments:</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/28788">28788</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-06-20 18:26:17 +0000 (Fri, 20 Jun 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Reinstate the changes from <a href="http://core.trac.wordpress.org/changeset/28579">[28579]</a> with some adjustments:
* Check `! empty( $postarr['file'] )` before calling `update_attached_file()`
* Add a unit test: `test_update_attachment_fields()`
* Run the same logic for empty `guid` for attachments that always ran in `wp_insert_post()`, as per <a href="http://core.trac.wordpress.org/ticket/18310">#18310</a>. This fixes a unit test that would have broken when this ticket was marked closed.
* Updated the unit test in `Tests_Media::test_wp_prepare_attachment_for_js()` to account for `url` no longer being empty
Props kovshenin, wonderboymusic.
See <a href="http://core.trac.wordpress.org/ticket/21963">#21963</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunktestsphpunittestsmediaphp">trunk/tests/phpunit/tests/media.php</a></li>
<li><a href="#trunktestsphpunittestspostattachmentsphp">trunk/tests/phpunit/tests/post/attachments.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/post.php (28787 => 28788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/post.php 2014-06-20 17:28:12 UTC (rev 28787)
+++ trunk/src/wp-includes/post.php 2014-06-20 18:26:17 UTC (rev 28788)
</span><span class="lines">@@ -2927,7 +2927,7 @@
</span><span class="cx"> 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
</span><span class="cx"> 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '',
</span><span class="cx"> 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
</span><del>- 'post_content' => '', 'post_title' => '');
</del><ins>+ 'post_content' => '', 'post_title' => '', 'context' => '');
</ins><span class="cx">
</span><span class="cx"> $postarr = wp_parse_args($postarr, $defaults);
</span><span class="cx">
</span><span class="lines">@@ -2968,8 +2968,11 @@
</span><span class="cx"> $post_name = $postarr['post_name'];
</span><span class="cx"> }
</span><span class="cx">
</span><del>- $maybe_empty = ! $post_content && ! $post_title && ! $post_excerpt && post_type_supports( $post_type, 'editor' )
- && post_type_supports( $post_type, 'title' ) && post_type_supports( $post_type, 'excerpt' );
</del><ins>+ $maybe_empty = 'attachment' !== $post_type
+ && ! $post_content && ! $post_title && ! $post_excerpt
+ && post_type_supports( $post_type, 'editor' )
+ && post_type_supports( $post_type, 'title' )
+ && post_type_supports( $post_type, 'excerpt' );
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Filter whether the post should be considered "empty".
</span><span class="lines">@@ -2996,6 +2999,9 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status'];
</span><ins>+ if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private' ) ) ) {
+ $post_status = 'inherit';
+ }
</ins><span class="cx">
</span><span class="cx"> if ( ! empty( $postarr['post_category'] ) ) {
</span><span class="cx"> $post_category = array_filter( $postarr['post_category'] ); // Filter out empty terms
</span><span class="lines">@@ -3072,16 +3078,18 @@
</span><span class="cx"> $post_modified_gmt = $post_date_gmt;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if ( 'publish' == $post_status ) {
- $now = gmdate('Y-m-d H:i:59');
- if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) {
- $post_status = 'future';
</del><ins>+ if ( 'attachment' !== $post_type ) {
+ if ( 'publish' == $post_status ) {
+ $now = gmdate('Y-m-d H:i:59');
+ if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) {
+ $post_status = 'future';
+ }
+ } elseif( 'future' == $post_status ) {
+ $now = gmdate('Y-m-d H:i:59');
+ if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) {
+ $post_status = 'publish';
+ }
</ins><span class="cx"> }
</span><del>- } elseif( 'future' == $post_status ) {
- $now = gmdate('Y-m-d H:i:59');
- if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) {
- $post_status = 'publish';
- }
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if ( empty( $postarr['comment_status'] ) ) {
</span><span class="lines">@@ -3135,18 +3143,33 @@
</span><span class="cx">
</span><span class="cx"> $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent );
</span><span class="cx">
</span><ins>+ // don't unslash
+ $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : '';
+
</ins><span class="cx"> // expected_slashed (everything!)
</span><del>- $data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' );
</del><ins>+ $data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid' );
</ins><span class="cx">
</span><del>- /**
- * Filter slashed post data just before it is inserted into the database.
- *
- * @since 2.7.0
- *
- * @param array $data Array of slashed post data.
- * @param array $postarr Array of sanitized, but otherwise unmodified post data.
- */
- $data = apply_filters( 'wp_insert_post_data', $data, $postarr );
</del><ins>+ if ( 'attachment' === $post_type ) {
+ /**
+ * Filter attachment post data before it is updated in or added to the database.
+ *
+ * @since 3.9.0
+ *
+ * @param array $data An array of sanitized attachment post data.
+ * @param array $postarr An array of unsanitized attachment post data.
+ */
+ $data = apply_filters( 'wp_insert_attachment_data', $data, $postarr );
+ } else {
+ /**
+ * Filter slashed post data just before it is inserted into the database.
+ *
+ * @since 2.7.0
+ *
+ * @param array $data An array of slashed post data.
+ * @param array $postarr An array of sanitized, but otherwise unmodified post data.
+ */
+ $data = apply_filters( 'wp_insert_post_data', $data, $postarr );
+ }
</ins><span class="cx"> $data = wp_unslash( $data );
</span><span class="cx"> $where = array( 'ID' => $post_ID );
</span><span class="cx">
</span><span class="lines">@@ -3168,9 +3191,6 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> } else {
</span><del>- if ( isset( $postarr['post_mime_type'] ) ) {
- $data['post_mime_type'] = wp_unslash( $postarr['post_mime_type'] ); // This isn't in the update
- }
</del><span class="cx"> // If there is a suggested ID, use it if not already present
</span><span class="cx"> if ( ! empty( $import_id ) ) {
</span><span class="cx"> $import_id = (int) $import_id;
</span><span class="lines">@@ -3191,8 +3211,8 @@
</span><span class="cx"> $where = array( 'ID' => $post_ID );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if ( empty($data['post_name']) && !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
- $data['post_name'] = sanitize_title($data['post_title'], $post_ID);
</del><ins>+ if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
+ $data['post_name'] = sanitize_title( $data['post_title'], $post_ID );
</ins><span class="cx"> $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -3223,6 +3243,17 @@
</span><span class="cx"> if ( ! $update && '' == $current_guid ) {
</span><span class="cx"> $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where );
</span><span class="cx"> }
</span><ins>+
+ if ( 'attachment' === $postarr['post_type'] ) {
+ if ( ! empty( $postarr['file'] ) ) {
+ update_attached_file( $post_ID, $postarr['file'] );
+ }
+
+ if ( ! empty( $postarr['context'] ) ) {
+ add_post_meta( $post_ID, '_wp_attachment_context', $postarr['context'], true );
+ }
+ }
+
</ins><span class="cx"> clean_post_cache( $post_ID );
</span><span class="cx">
</span><span class="cx"> $post = get_post( $post_ID );
</span><span class="lines">@@ -3240,8 +3271,33 @@
</span><span class="cx"> update_post_meta( $post_ID, '_wp_page_template', $postarr['page_template'] );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- wp_transition_post_status($data['post_status'], $previous_status, $post);
</del><ins>+ if ( 'attachment' !== $postarr['post_type'] ) {
+ wp_transition_post_status( $data['post_status'], $previous_status, $post );
+ } else {
+ if ( $update ) {
+ /**
+ * Fires once an existing attachment has been updated.
+ *
+ * @since 2.0.0
+ *
+ * @param int $post_ID Attachment ID.
+ */
+ do_action( 'edit_attachment', $post_ID );
+ } else {
</ins><span class="cx">
</span><ins>+ /**
+ * Fires once an attachment has been added.
+ *
+ * @since 2.0.0
+ *
+ * @param int $post_ID Attachment ID.
+ */
+ do_action( 'add_attachment', $post_ID );
+ }
+
+ return $post_ID;
+ }
+
</ins><span class="cx"> if ( $update ) {
</span><span class="cx"> /**
</span><span class="cx"> * Fires once an existing post has been updated.
</span><span class="lines">@@ -4449,7 +4505,7 @@
</span><span class="cx"> /**
</span><span class="cx"> * Insert an attachment.
</span><span class="cx"> *
</span><del>- * If you set the 'ID' in the $object parameter, it will mean that you are
</del><ins>+ * If you set the 'ID' in the $args parameter, it will mean that you are
</ins><span class="cx"> * updating and attempt to update the attachment. You can also set the
</span><span class="cx"> * attachment name or title by setting the key 'post_name' or 'post_title'.
</span><span class="cx"> *
</span><span class="lines">@@ -4460,260 +4516,25 @@
</span><span class="cx"> * comments are allowed. You can close them manually or keep them open by
</span><span class="cx"> * setting the value for the 'comment_status' key.
</span><span class="cx"> *
</span><del>- * The $object parameter can have the following:
- * 'post_status' - Default is 'draft'. Can not be overridden, set the same as parent post.
- * 'post_type' - Default is 'post', will be set to attachment. Can not override.
- * 'post_author' - Default is current user ID. The ID of the user, who added the attachment.
- * 'ping_status' - Default is the value in default ping status option. Whether the attachment
- * can accept pings.
- * 'post_parent' - Default is 0. Can use $parent parameter or set this for the post it belongs
- * to, if any.
- * 'menu_order' - Default is 0. The order it is displayed.
- * 'to_ping' - Whether to ping.
- * 'pinged' - Default is empty string.
- * 'post_password' - Default is empty string. The password to access the attachment.
- * 'guid' - Global Unique ID for referencing the attachment.
- * 'post_content_filtered' - Attachment post content filtered.
- * 'post_excerpt' - Attachment excerpt.
- *
</del><span class="cx"> * @since 2.0.0
</span><del>- * @uses $wpdb
</del><span class="cx"> *
</span><del>- * @param string|array $object Arguments to override defaults.
- * @param string $file Optional filename.
- * @param int $parent Parent post ID.
</del><ins>+ * @see wp_insert_post()
+ *
+ * @param string|array $args Arguments for inserting an attachment.
+ * @param string $file Optional. Filename.
+ * @param int $parent Optional. Parent post ID.
</ins><span class="cx"> * @return int Attachment ID.
</span><span class="cx"> */
</span><del>-function wp_insert_attachment($object, $file = false, $parent = 0) {
- global $wpdb;
</del><ins>+function wp_insert_attachment( $args, $file = false, $parent = 0 ) {
+ $defaults = array(
+ 'file' => $file,
+ 'post_parent' => $parent
+ );
+ $data = wp_parse_args( $args, $defaults );
</ins><span class="cx">
</span><del>- $user_id = get_current_user_id();
</del><ins>+ $data['post_type'] = 'attachment';
</ins><span class="cx">
</span><del>- $defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_id,
- 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
- 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '',
- 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
- 'post_title' => '', 'post_content' => '', 'context' => '');
-
- $object = wp_parse_args($object, $defaults);
- if ( ! empty( $parent ) ) {
- $object['post_parent'] = $parent;
- }
- unset( $object[ 'filter' ] );
-
- $object = sanitize_post($object, 'db');
-
- $post_ID = 0;
- $update = false;
- $guid = $object['guid'];
-
- // Are we updating or creating?
- if ( ! empty( $object['ID'] ) ) {
- $update = true;
- $post_ID = (int) $object['ID'];
-
- // wp_insert_post() checks for the existence of this post....
- }
-
- $post_type = 'attachment';
-
- $post_title = $object['post_title'];
- $post_content = $object['post_content'];
- $post_excerpt = $object['post_excerpt'];
- if ( isset( $object['post_name'] ) ) {
- $post_name = $object['post_name'];
- }
-
- // wp_insert_post() checks $maybe_empty
-
- $post_status = $object['post_status'];
- if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) ) {
- $post_status = 'inherit';
- }
-
- if ( ! empty( $object['post_category'] ) ) {
- $post_category = array_filter( $object['post_category'] ); // Filter out empty terms
- }
-
- // Make sure we set a valid category.
- if ( empty( $post_category ) || 0 == count( $post_category ) || ! is_array( $post_category ) ) {
- // ironically, the default post_type for this function is 'post'
- // as such, this should be probably have the same checks as wp_insert_post(),
- // since all 'post's require a category. BUT, you can't override the post_type, because the
- // variable is explicitly set.
- $post_category = array();
- }
-
- // Create a valid post name.
- if ( empty( $post_name ) ) {
- $post_name = sanitize_title($post_title);
- } else {
- // missing check from wp_insert_post on update:
- // "On updates, we need to check to see if it's using the old, fixed sanitization context."
- $post_name = sanitize_title( $post_name );
- }
-
- if ( isset( $object['post_parent'] ) ) {
- $post_parent = (int) $object['post_parent'];
- } else {
- $post_parent = 0;
- }
-
- if ( empty( $object['post_date'] ) || '0000-00-00 00:00:00' == $object['post_date'] ) {
- $post_date = current_time( 'mysql' );
- } else {
- $post_date = $object['post_date'];
- }
-
- // wp_insert_post() validates the date here
-
- if ( empty( $object['post_date_gmt'] ) || '0000-00-00 00:00:00' == $object['post_date_gmt'] ) {
- $post_date_gmt = get_gmt_from_date( $post_date );
- } else {
- $post_date_gmt = $object['post_date_gmt'];
- }
-
- if ( $update || '0000-00-00 00:00:00' == $post_date ) {
- $post_modified = current_time( 'mysql' );
- $post_modified_gmt = current_time( 'mysql', 1 );
- } else {
- $post_modified = $post_date;
- $post_modified_gmt = $post_date_gmt;
- }
-
- // wp_insert_post() does "future" checks
-
- if ( empty( $object['comment_status'] ) ) {
- if ( $update ) {
- $comment_status = 'closed';
- } else {
- $comment_status = get_option('default_comment_status');
- }
- } else {
- $comment_status = $object['comment_status'];
- }
-
- // these variables are needed by compact() later
- $post_content_filtered = $object['post_content_filtered'];
- $post_author = empty( $object['post_author'] ) ? $user_id : $object['post_author'];
- $ping_status = empty( $object['ping_status'] ) ? get_option( 'default_ping_status' ) : $object['ping_status'];
- $to_ping = isset( $object['to_ping'] ) ? sanitize_trackback_urls( $object['to_ping'] ) : '';
- $pinged = isset( $object['pinged'] ) ? $object['pinged'] : '';
- $import_id = isset( $object['import_id'] ) ? $object['import_id'] : 0;
-
- if ( isset( $object['menu_order'] ) ) {
- $menu_order = (int) $object['menu_order'];
- } else {
- $menu_order = 0;
- }
-
- $post_password = isset( $object['post_password'] ) ? $object['post_password'] : '';
-
- // skips the 'wp_insert_post_parent' filter, present in wp_insert_post()
-
- // expected_slashed ($post_name)
- $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent );
-
- // don't unslash
- $post_mime_type = isset( $object['post_mime_type'] ) ? $object['post_mime_type'] : '';
-
- // expected_slashed (everything!)
- $data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid' );
-
- /**
- * Filter attachment post data before it is updated in or added
- * to the database.
- *
- * @since 3.9.0
- *
- * @param array $data Array of sanitized attachment post data.
- * @param array $object Array of un-sanitized attachment post data.
- */
- $data = apply_filters( 'wp_insert_attachment_data', $data, $object );
- $data = wp_unslash( $data );
- $where = array( 'ID' => $post_ID );
-
- if ( $update ) {
- // skips 'pre_post_update' action
- $wpdb->update( $wpdb->posts, $data, $where );
- } else {
- // If there is a suggested ID, use it if not already present
- if ( ! empty( $import_id ) ) {
- $import_id = (int) $import_id;
- if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id ) ) ) {
- $data['ID'] = $import_id;
- }
- }
-
- $wpdb->insert( $wpdb->posts, $data );
- $post_ID = (int) $wpdb->insert_id;
- $where = array( 'ID' => $post_ID );
- }
-
- if ( empty( $data['post_name'] ) ) {
- $data['post_name'] = sanitize_title( $data['post_title'], $post_ID );
- $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
- }
-
- if ( is_object_in_taxonomy( $data['post_type'], 'category' ) ) {
- wp_set_post_categories( $post_ID, $post_category );
- }
-
- if ( isset( $object['tags_input'] ) && is_object_in_taxonomy( $data['post_type'], 'post_tag' ) ) {
- wp_set_post_tags( $post_ID, $object['tags_input'] );
- }
-
- // new-style support for all custom taxonomies
- if ( ! empty( $object['tax_input'] ) ) {
- foreach ( $object['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 );
- }
-
- // wp_insert_post() fills in guid if it is empty
-
- clean_post_cache( $post_ID );
-
- if ( ! empty( $object['context'] ) ) {
- add_post_meta( $post_ID, '_wp_attachment_context', $object['context'], true );
- }
-
- // skips wp_transition_post_status
-
- // the actions completely diverge from wp_insert_post()
-
- if ( $update ) {
- /**
- * Fires once an existing attachment has been updated.
- *
- * @since 2.0.0
- *
- * @param int $post_ID Attachment ID.
- */
- do_action( 'edit_attachment', $post_ID );
- } else {
-
- /**
- * Fires once an attachment has been added.
- *
- * @since 2.0.0
- *
- * @param int $post_ID Attachment ID.
- */
- do_action( 'add_attachment', $post_ID );
- }
-
- return $post_ID;
</del><ins>+ return wp_insert_post( $data );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -5799,3 +5620,5 @@
</span><span class="cx"> update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
</span><span class="cx"> }
</span><span class="cx"> }
</span><ins>+
+
</ins></span></pre></div>
<a id="trunktestsphpunittestsmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/phpunit/tests/media.php (28787 => 28788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/phpunit/tests/media.php 2014-06-20 17:28:12 UTC (rev 28787)
+++ trunk/tests/phpunit/tests/media.php 2014-06-20 18:26:17 UTC (rev 28788)
</span><span class="lines">@@ -148,7 +148,8 @@
</span><span class="cx"> $this->assertEquals( '', $prepped['mime'] );
</span><span class="cx"> $this->assertEquals( '', $prepped['type'] );
</span><span class="cx"> $this->assertEquals( '', $prepped['subtype'] );
</span><del>- $this->assertEquals( '', $prepped['url'] );
</del><ins>+ // #21963, there will be a guid always, so there will be a URL
+ $this->assertNotEquals( '', $prepped['url'] );
</ins><span class="cx"> $this->assertEquals( site_url( 'wp-includes/images/media/default.png' ), $prepped['icon'] );
</span><span class="cx">
</span><span class="cx"> // Fake a mime
</span></span></pre></div>
<a id="trunktestsphpunittestspostattachmentsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/phpunit/tests/post/attachments.php (28787 => 28788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/phpunit/tests/post/attachments.php 2014-06-20 17:28:12 UTC (rev 28787)
+++ trunk/tests/phpunit/tests/post/attachments.php 2014-06-20 18:26:17 UTC (rev 28788)
</span><span class="lines">@@ -231,4 +231,30 @@
</span><span class="cx"> $this->assertFalse( empty( $guid ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * @ticket 21963
+ */
+ function test_update_attachment_fields() {
+ $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
+ $contents = file_get_contents($filename);
+
+ $upload = wp_upload_bits( basename( $filename ), null, $contents );
+ $this->assertTrue( empty( $upload['error'] ) );
+
+ $id = $this->_make_attachment( $upload );
+
+ $attached_file = get_post_meta( $id, '_wp_attached_file', true );
+
+ $post = get_post( $id, ARRAY_A );
+
+ $post['post_title'] = 'title';
+ $post['post_excerpt'] = 'caption';
+ $post['post_content'] = 'description';
+
+ wp_update_post( $post );
+
+ // Make sure the update didn't remove the attached file.
+ $this->assertEquals( $attached_file, get_post_meta( $id, '_wp_attached_file', true ) );
+ }
+
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>