<!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>[17999] trunk: Mark import attachments as private.</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, #logmsg > ol { margin-left: 0; 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://trac.wordpress.org/changeset/17999">17999</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2011-05-22 23:25:28 +0000 (Sun, 22 May 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Mark import attachments as private. Schedule job to delete old import attachments. Introduce attachment context.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustombackgroundphp">trunk/wp-admin/custom-background.php</a></li>
<li><a href="#trunkwpadmincustomheaderphp">trunk/wp-admin/custom-header.php</a></li>
<li><a href="#trunkwpadminincludesimportphp">trunk/wp-admin/includes/import.php</a></li>
<li><a href="#trunkwpadminincludespostphp">trunk/wp-admin/includes/post.php</a></li>
<li><a href="#trunkwpincludesdefaultfiltersphp">trunk/wp-includes/default-filters.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustombackgroundphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-background.php (17998 => 17999)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-background.php        2011-05-22 23:23:57 UTC (rev 17998)
+++ trunk/wp-admin/custom-background.php        2011-05-22 23:25:28 UTC (rev 17999)
</span><span class="lines">@@ -338,7 +338,8 @@
</span><span class="cx">                         'post_title' => $filename,
</span><span class="cx">                         'post_content' => $url,
</span><span class="cx">                         'post_mime_type' => $type,
</span><del>-                        'guid' => $url
</del><ins>+                        'guid' => $url,
+                        'context' => 'custom-background'
</ins><span class="cx">                 );
</span><span class="cx">
</span><span class="cx">                 // Save the data
</span></span></pre></div>
<a id="trunkwpadmincustomheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-header.php (17998 => 17999)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-header.php        2011-05-22 23:23:57 UTC (rev 17998)
+++ trunk/wp-admin/custom-header.php        2011-05-22 23:25:28 UTC (rev 17999)
</span><span class="lines">@@ -644,7 +644,8 @@
</span><span class="cx">                 'post_title' => $filename,
</span><span class="cx">                 'post_content' => $url,
</span><span class="cx">                 'post_mime_type' => $type,
</span><del>-                'guid' => $url);
</del><ins>+                'guid' => $url,
+                'context' => 'custom-header');
</ins><span class="cx">
</span><span class="cx">                 // Save the data
</span><span class="cx">                 $id = wp_insert_attachment($object, $file);
</span><span class="lines">@@ -737,7 +738,8 @@
</span><span class="cx">                         'post_title' => basename($cropped),
</span><span class="cx">                         'post_content' => $url,
</span><span class="cx">                         'post_mime_type' => 'image/jpeg',
</span><del>-                        'guid' => $url
</del><ins>+                        'guid' => $url,
+                        'context' => 'custom-header'
</ins><span class="cx">                 );
</span><span class="cx">
</span><span class="cx">                 // Update the attachment
</span></span></pre></div>
<a id="trunkwpadminincludesimportphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/import.php (17998 => 17999)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/import.php        2011-05-22 23:23:57 UTC (rev 17998)
+++ trunk/wp-admin/includes/import.php        2011-05-22 23:25:28 UTC (rev 17999)
</span><span class="lines">@@ -80,12 +80,17 @@
</span><span class="cx">         $object = array( 'post_title' => $filename,
</span><span class="cx">                 'post_content' => $url,
</span><span class="cx">                 'post_mime_type' => $type,
</span><del>-                'guid' => $url
</del><ins>+                'guid' => $url,
+                'context' => 'import',
+                'post_status' => 'private'
</ins><span class="cx">         );
</span><span class="cx">
</span><span class="cx">         // Save the data
</span><span class="cx">         $id = wp_insert_attachment( $object, $file );
</span><span class="cx">
</span><ins>+        // schedule a cleanup for one day from now in case of failed import or missing wp_import_cleanup() call
+        wp_schedule_single_event( time() + 86400, 'importer_scheduled_cleanup', array( $id ) );
+
</ins><span class="cx">         return array( 'file' => $file, 'id' => $id );
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (17998 => 17999)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2011-05-22 23:23:57 UTC (rev 17998)
+++ trunk/wp-admin/includes/post.php        2011-05-22 23:25:28 UTC (rev 17999)
</span><span class="lines">@@ -996,7 +996,12 @@
</span><span class="cx">         $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0;
</span><span class="cx">         $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
</span><span class="cx">         $q['post_type'] = 'attachment';
</span><del>-        $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : 'inherit';
</del><ins>+        $post_type = get_post_type_object( 'attachment' );
+        $states = array( 'inherit' );
+        if ( current_user_can( $post_type->cap->read_private_posts ) )
+                $states[] = 'private';
+
+        $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states;
</ins><span class="cx">         $media_per_page = (int) get_user_option( 'upload_per_page' );
</span><span class="cx">         if ( empty( $media_per_page ) || $media_per_page < 1 )
</span><span class="cx">                 $media_per_page = 20;
</span></span></pre></div>
<a id="trunkwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/default-filters.php (17998 => 17999)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/default-filters.php        2011-05-22 23:23:57 UTC (rev 17998)
+++ trunk/wp-includes/default-filters.php        2011-05-22 23:25:28 UTC (rev 17999)
</span><span class="lines">@@ -257,6 +257,7 @@
</span><span class="cx"> add_action( 'before_wp_tiny_mce', 'wp_print_editor_js' );
</span><span class="cx"> add_action( 'after_wp_tiny_mce', 'wp_preload_dialogs', 10, 1 );
</span><span class="cx"> add_action( 'admin_init', 'send_frame_options_header', 10, 0 );
</span><ins>+add_action( 'importer_scheduled_cleanup', 'wp_delete_attachment' );
</ins><span class="cx">
</span><span class="cx"> // Navigation menu actions
</span><span class="cx"> add_action( 'delete_post', '_wp_delete_post_menu_item' );
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (17998 => 17999)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2011-05-22 23:23:57 UTC (rev 17998)
+++ trunk/wp-includes/post.php        2011-05-22 23:25:28 UTC (rev 17999)
</span><span class="lines">@@ -557,13 +557,19 @@
</span><span class="cx">         if ( !is_object($post) )
</span><span class="cx">                 return false;
</span><span class="cx">
</span><del>-        // Unattached attachments are assumed to be published.
-        if ( ('attachment' == $post->post_type) && ('inherit' == $post->post_status) && ( 0 == $post->post_parent) )
-                return 'publish';
</del><ins>+        if ( 'attachment' == $post->post_type ) {
+                if ( 'private' == $post->post_status )
+                        return 'private';
</ins><span class="cx">
</span><del>-        if ( ('attachment' == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) )
-                return get_post_status($post->post_parent);
</del><ins>+                // Unattached attachments are assumed to be published
+                if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) )
+                        return 'publish';
</ins><span class="cx">
</span><ins>+                // Inherit status from the parent
+                if ( $post->post_parent && ( $post->ID != $post->post_parent ) )
+                        return get_post_status($post->post_parent);
+        }
+
</ins><span class="cx">         return $post->post_status;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -3543,10 +3549,10 @@
</span><span class="cx"> function wp_insert_attachment($object, $file = false, $parent = 0) {
</span><span class="cx">         global $wpdb, $user_ID;
</span><span class="cx">
</span><del>-        $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
</del><ins>+        $defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_ID,
</ins><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><del>-                'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0);
</del><ins>+                'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => '');
</ins><span class="cx">
</span><span class="cx">         $object = wp_parse_args($object, $defaults);
</span><span class="cx">         if ( !empty($parent) )
</span><span class="lines">@@ -3561,8 +3567,10 @@
</span><span class="cx">                 $post_author = $user_ID;
</span><span class="cx">
</span><span class="cx">         $post_type = 'attachment';
</span><del>-        $post_status = 'inherit';
</del><span class="cx">
</span><ins>+        if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) )
+                $post_status = 'inherit';
+
</ins><span class="cx">         // Make sure we set a valid category.
</span><span class="cx">         if ( !isset($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
</span><span class="cx">                 // 'post' requires at least one category.
</span><span class="lines">@@ -3664,6 +3672,9 @@
</span><span class="cx">         if ( isset($post_parent) && $post_parent < 0 )
</span><span class="cx">                 add_post_meta($post_ID, '_wp_attachment_temp_parent', $post_parent, true);
</span><span class="cx">
</span><ins>+        if ( ! empty( $context ) )
+                add_post_meta( $post_ID, '_wp_attachment_context', $context, true );
+
</ins><span class="cx">         if ( $update) {
</span><span class="cx">                 do_action('edit_attachment', $post_ID);
</span><span class="cx">         } else {
</span></span></pre>
</div>
</div>
</body>
</html>