<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[17276] trunk/wp-admin: Move edit.
 php bulk actions code to a handler in the list table class.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17276">17276</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2011-01-13 00:34:18 +0000 (Thu, 13 Jan 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move edit.php bulk actions code to a handler in the list table class. see <a href="http://trac.wordpress.org/ticket/16166">#16166</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditphp">trunk/wp-admin/edit.php</a></li>
<li><a href="#trunkwpadminincludesclasswppostslisttablephp">trunk/wp-admin/includes/class-wp-posts-list-table.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit.php (17275 => 17276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit.php        2011-01-13 00:22:53 UTC (rev 17275)
+++ trunk/wp-admin/edit.php        2011-01-13 00:34:18 UTC (rev 17276)
</span><span class="lines">@@ -38,93 +38,7 @@
</span><span class="cx"> $doaction = $wp_list_table-&gt;current_action();
</span><span class="cx"> 
</span><span class="cx"> if ( $doaction ) {
</span><del>-        check_admin_referer('bulk-posts');
-
-        $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
-        $sendback = $wp_list_table-&gt;add_query_args( $sendback );
-        if ( strpos($sendback, 'post.php') !== false )
-                $sendback = admin_url($post_new_file);
-
-        if ( 'delete_all' == $doaction ) {
-                $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
-                if ( get_post_status_object($post_status) ) // Check the post status exists first
-                        $post_ids = $wpdb-&gt;get_col( $wpdb-&gt;prepare( &quot;SELECT ID FROM $wpdb-&gt;posts WHERE post_type=%s AND post_status = %s&quot;, $post_type, $post_status ) );
-                $doaction = 'delete';
-        } elseif ( isset( $_REQUEST['media'] ) ) {
-                $post_ids = $_REQUEST['media'];
-        } elseif ( isset( $_REQUEST['ids'] ) ) {
-                $post_ids = explode( ',', $_REQUEST['ids'] );
-        } elseif ( !empty( $_REQUEST['post'] ) ) {
-                $post_ids = array_map('intval', $_REQUEST['post']);
-        }
-
-        if ( !isset( $post_ids ) ) {
-                wp_redirect( admin_url(&quot;edit.php?post_type=$post_type&quot;) );
-                exit;
-        }
-
-        switch ( $doaction ) {
-                case 'trash':
-                        $trashed = 0;
-                        foreach( (array) $post_ids as $post_id ) {
-                                if ( !current_user_can($post_type_object-&gt;cap-&gt;delete_post, $post_id) )
-                                        wp_die( __('You are not allowed to move this item to the Trash.') );
-
-                                if ( !wp_trash_post($post_id) )
-                                        wp_die( __('Error in moving to Trash.') );
-
-                                $trashed++;
-                        }
-                        $sendback = add_query_arg( array('trashed' =&gt; $trashed, 'ids' =&gt; join(',', $post_ids) ), $sendback );
-                        break;
-                case 'untrash':
-                        $untrashed = 0;
-                        foreach( (array) $post_ids as $post_id ) {
-                                if ( !current_user_can($post_type_object-&gt;cap-&gt;delete_post, $post_id) )
-                                        wp_die( __('You are not allowed to restore this item from the Trash.') );
-
-                                if ( !wp_untrash_post($post_id) )
-                                        wp_die( __('Error in restoring from Trash.') );
-
-                                $untrashed++;
-                        }
-                        $sendback = add_query_arg('untrashed', $untrashed, $sendback);
-                        break;
-                case 'delete':
-                        $deleted = 0;
-                        foreach( (array) $post_ids as $post_id ) {
-                                $post_del = &amp; get_post($post_id);
-
-                                if ( !current_user_can($post_type_object-&gt;cap-&gt;delete_post, $post_id) )
-                                        wp_die( __('You are not allowed to delete this item.') );
-
-                                if ( $post_del-&gt;post_type == 'attachment' ) {
-                                        if ( ! wp_delete_attachment($post_id) )
-                                                wp_die( __('Error in deleting...') );
-                                } else {
-                                        if ( !wp_delete_post($post_id) )
-                                                wp_die( __('Error in deleting...') );
-                                }
-                                $deleted++;
-                        }
-                        $sendback = add_query_arg('deleted', $deleted, $sendback);
-                        break;
-                case 'edit':
-                        $done = bulk_edit_posts($_REQUEST);
-
-                        if ( is_array($done) ) {
-                                $done['updated'] = count( $done['updated'] );
-                                $done['skipped'] = count( $done['skipped'] );
-                                $done['locked'] = count( $done['locked'] );
-                                $sendback = add_query_arg( $done, $sendback );
-                        }
-                        break;
-        }
-
-        $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view'), $sendback );
-
-        wp_redirect($sendback);
-        exit();
</del><ins>+        $wp_list_table-&gt;do_bulk_actions( $doaction );
</ins><span class="cx"> } elseif ( ! empty($_REQUEST['_wp_http_referer']) ) {
</span><span class="cx">          wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
</span><span class="cx">          exit;
</span></span></pre></div>
<a id="trunkwpadminincludesclasswppostslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-posts-list-table.php (17275 => 17276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-posts-list-table.php        2011-01-13 00:22:53 UTC (rev 17275)
+++ trunk/wp-admin/includes/class-wp-posts-list-table.php        2011-01-13 00:34:18 UTC (rev 17276)
</span><span class="lines">@@ -1013,6 +1013,105 @@
</span><span class="cx">                 &lt;/tbody&gt;&lt;/table&gt;&lt;/form&gt;
</span><span class="cx"> &lt;?php
</span><span class="cx">         }
</span><ins>+
+        function do_bulk_actions( $doaction = null ) {
+                if ( null === $doaction )
+                        $doaction = $this-&gt;current_action();
+
+                if ( ! $doaction )
+                        return;
+
+                check_admin_referer('bulk-posts');
+
+                $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
+                if ( strpos($sendback, 'post.php') !== false )
+                        $sendback = admin_url($post_new_file);
+
+                if ( 'delete_all' == $doaction ) {
+                        $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
+                        if ( get_post_status_object($post_status) ) // Check the post status exists first
+                                $post_ids = $wpdb-&gt;get_col( $wpdb-&gt;prepare( &quot;SELECT ID FROM $wpdb-&gt;posts WHERE post_type=%s AND post_status = %s&quot;, $post_type, $post_status ) );
+                        $doaction = 'delete';
+                } elseif ( isset( $_REQUEST['media'] ) ) {
+                        $post_ids = $_REQUEST['media'];
+                } elseif ( isset( $_REQUEST['ids'] ) ) {
+                        $post_ids = explode( ',', $_REQUEST['ids'] );
+                } elseif ( !empty( $_REQUEST['post'] ) ) {
+                        $post_ids = array_map('intval', $_REQUEST['post']);
+                }
+
+                if ( !isset( $post_ids ) ) {
+                        wp_redirect( admin_url(&quot;edit.php?post_type=$post_type&quot;) );
+                        exit;
+                }
+
+                switch ( $doaction ) {
+                        case 'trash':
+                                $trashed = 0;
+                                foreach( (array) $post_ids as $post_id ) {
+                                        if ( !current_user_can($post_type_object-&gt;cap-&gt;delete_post, $post_id) )
+                                                wp_die( __('You are not allowed to move this item to the Trash.') );
+
+                                        if ( !wp_trash_post($post_id) )
+                                                wp_die( __('Error in moving to Trash.') );
+
+                                        $trashed++;
+                                }
+                                $sendback = add_query_arg( array('trashed' =&gt; $trashed, 'ids' =&gt; join(',', $post_ids) ), $sendback );
+                                break;
+                        case 'untrash':
+                                $untrashed = 0;
+                                foreach( (array) $post_ids as $post_id ) {
+                                        if ( !current_user_can($post_type_object-&gt;cap-&gt;delete_post, $post_id) )
+                                                wp_die( __('You are not allowed to restore this item from the Trash.') );
+
+                                        if ( !wp_untrash_post($post_id) )
+                                                wp_die( __('Error in restoring from Trash.') );
+
+                                        $untrashed++;
+                                }
+                                $sendback = add_query_arg('untrashed', $untrashed, $sendback);
+                                break;
+                        case 'delete':
+                                $deleted = 0;
+                                foreach( (array) $post_ids as $post_id ) {
+                                        $post_del = &amp; get_post($post_id);
+
+                                        if ( !current_user_can($post_type_object-&gt;cap-&gt;delete_post, $post_id) )
+                                                wp_die( __('You are not allowed to delete this item.') );
+
+                                        if ( $post_del-&gt;post_type == 'attachment' ) {
+                                                if ( ! wp_delete_attachment($post_id) )
+                                                        wp_die( __('Error in deleting...') );
+                                        } else {
+                                                if ( !wp_delete_post($post_id) )
+                                                        wp_die( __('Error in deleting...') );
+                                        }
+                                        $deleted++;
+                                }
+                                $sendback = add_query_arg('deleted', $deleted, $sendback);
+                                break;
+                        case 'edit':
+                                $done = bulk_edit_posts($_REQUEST);
+
+                                if ( is_array($done) ) {
+                                        $done['updated'] = count( $done['updated'] );
+                                        $done['skipped'] = count( $done['skipped'] );
+                                        $done['locked'] = count( $done['locked'] );
+                                        $sendback = add_query_arg( $done, $sendback );
+                                }
+                                break;
+                        default :
+                                $sendback = apply_filters( &quot;bulk_actions-posts-$doaction&quot;, $sendback, $doaction );
+                                break;
+                }
+
+                $sendback = remove_query_arg( array( 'action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view' ), $sendback );
+                $sendback = $this-&gt;add_query_args( $sendback );
+                wp_redirect( $sendback );
+                exit();
+        }
+
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>