Permalink
Browse files

Enhance translation group tool toad trash and delete post actions, fi…

…lter by status, sort by post_type within each group
  • Loading branch information...
1 parent e855d9c commit a7011032fb2d78719e0dff41f147c0415e58d3e3 Simon Wheatley committed Jan 19, 2012
Showing with 54 additions and 7 deletions.
  1. +23 −5 templates-admin/translation-groups.php
  2. +14 −0 translation-group-tool-sorter.php
  3. +17 −2 translation-group-tool.php
@@ -2,6 +2,20 @@
<?php screen_icon(); ?>
<h2>Translation Groups</h2>
+ <div>
+ <form action="" method="get">
+ <input type="hidden" name="page" value="btgt" />
+ <p><?php _e( 'Show only the following statuses:', 'bbl' ); ?></p>
+ <p><?php
+ $stati = get_post_stati( null, 'objects' );
+ $selected_stati = ( isset( $_GET[ 'bbl_stati' ] ) ) ? $_GET[ 'bbl_stati' ] : array( 'publish', 'private', 'draft', 'private', 'future', 'pending' );
+ foreach ( $stati as $status => $status_obj ) : ?>
+ <label for="status-<?php echo esc_attr( $status ); ?>"><input type="checkbox" name="bbl_stati[]" value="<?php echo esc_attr( $status ); ?>" id="status-<?php echo esc_attr( $status ); ?>" <?php checked( in_array( $status, $selected_stati ) ); ?> /> <?php echo esc_html( $status_obj->label ); ?> (<?php echo $status_obj->public ? __( 'public', 'bbl' ) : __( 'hidden', 'bbl' ); ?>)</label><br />
+ <?php endforeach; ?></p>
+ <?php submit_button( __( 'Filter', 'bbl' ) ); ?>
+ </form>
+ </div>
+
<?php
$terms = get_terms( 'post_translation' );
@@ -25,15 +39,19 @@
</tr>
</tfoot>
<?php endif; foreach ( $terms as $term ) : ?>
- <tbody>
+ <tbody id="tg-<?php echo esc_attr( $term->term_id ); ?>">
<tr>
<th colspan="4"><h3>Translation Group: <?php echo $term->term_id; ?></h3></th>
</tr>
<?php
$post_ids = get_objects_in_term( $term->term_id, 'post_translation' );
- if ( $post_ids ) :
+ $posts = array();
+ foreach ( $post_ids as $post_id )
+ $posts[] = get_post( $post_id );
+ usort( $posts, array( 'SortPosts', 'post_type_descending' ) );
+ if ( $posts ) :
?>
- <?php foreach ( $post_ids as $post_id ) : $post = get_post( $post_id ); ?>
+ <?php foreach ( $posts as $post ) : if ( ! in_array( $post->post_status, $selected_stati ) ) continue; ?>
<tr>
<?php if ( ! $post ) : ?>
<th colspan="4">
@@ -44,8 +62,8 @@
<th scope="row" class="manage-column column-id">
<?php echo $post->ID ?><br />
<a href="<?php echo add_query_arg( array( 'lang' => bbl_get_post_lang_code( $post->ID ) ), get_edit_post_link( $post->ID ) ); ?>">edit</a> |
- <a href="<?php echo $this->get_action_link( $post->ID, 'delete_post' ); ?>">delete</a> |
- <a href="<?php echo $this->get_action_link( $post->ID, 'trash_post' ); ?>">trash</a>
+ <a href="<?php echo $this->get_action_link( $post->ID, 'delete_post', "tg-$term->term_id" ); ?>">delete</a> |
+ <a href="<?php echo $this->get_action_link( $post->ID, 'trash_post', "tg-$term->term_id" ); ?>">trash</a>
</th>
<td class="manage-column column-type"><?php echo $post->post_type ?></td>
<td class="manage-column column-status"><?php echo $post->post_status ?></td>
@@ -0,0 +1,14 @@
+<?php
+
+// From: http://seancode.blogspot.com/2008/01/php-usort-sort-array-of-objects.html
+
+class SortPosts {
GaryJones
GaryJones Oct 10, 2013 Contributor

That's a very generic name for a class...no prefix?

+ function post_type_descending( $m, $n ) {
+ if ( $m->post_type == $n->post_type )
+ return 0;
+
+ return ( $m->post_type < $n->post_type ) ? -1 : 1;
+ }
+}
+
+?>
View
@@ -83,11 +83,24 @@ public function load_tools_page() {
}
wp_delete_object_term_relationships( $obj_id, 'post_translation' );
$this->set_admin_notice( "Deleted term relationships for $obj_id" );
+ break;
case 'delete_post':
wp_delete_object_term_relationships( $obj_id, 'post_translation' );
+ wp_delete_post( $obj_id, true );
+ break;
case 'trash_post':
wp_delete_object_term_relationships( $obj_id, 'post_translation' );
+ wp_trash_post( $obj_id );
+ break;
}
+ $args = array(
+ 'page' => 'btgt',
+ 'lang' => bbl_get_default_lang_code(),
+ );
+ $url = add_query_arg( $args, admin_url( 'tools.php' ) );
+ $url .= '#' . $_GET[ 'anchor' ];
+ error_log( "SW: Redirect to $url" );
+ wp_redirect( $url );
}
// CALLBACKS
@@ -99,6 +112,7 @@ public function load_tools_page() {
* @return void
**/
public function tools_page() {
+ require_once( 'translation-group-tool-sorter.php' );
$vars = array();
$this->render_admin( 'translation-groups.php', $vars );
}
@@ -113,17 +127,18 @@ public function tools_page() {
* @param string $action The action for this link
* @return string A Nonced action URL
**/
- protected function get_action_link( $obj_id, $action ) {
+ protected function get_action_link( $obj_id, $action, $anchor = null ) {
$args = array(
'btgt_action' => $action,
'obj_id' => $obj_id,
'lang' => bbl_get_default_lang_code(),
);
+ if ( ! is_null( $anchor ) )
+ $args[ 'anchor' ] = $anchor;
return wp_nonce_url( add_query_arg( $args ), "btgt_{$action}_$obj_id" );
}
-
} // END BabbleTranslationGroupTool class
$bbl_translation_group_tool = new BabbleTranslationGroupTool();

0 comments on commit a701103

Please sign in to comment.