*/
class WP_Media_List_Table extends WP_List_Table {
+ private $detached;
+
+ private $is_trash;
+
/**
* Constructor.
*
public function __construct( $args = array() ) {
$this->detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] );
+ $this->modes = array(
+ 'list' => __( 'List View' ),
+ 'grid' => __( 'Grid View' )
+ );
+
parent::__construct( array(
'plural' => 'media',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
if ( !empty( $_GET['attachment-filter'] ) && strpos( $_GET['attachment-filter'], 'post_mime_type:' ) === 0 && wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $_GET['attachment-filter'] ) ) )
$selected = ' selected="selected"';
if ( !empty( $num_posts[$mime_type] ) )
- $type_links[$mime_type] = '<option value="post_mime_type:' . urlencode( $mime_type ) . '"' . $selected . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</option>';
+ $type_links[$mime_type] = '<option value="post_mime_type:' . esc_attr( $mime_type ) . '"' . $selected . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</option>';
}
$type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . sprintf( _nx( 'Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</option>';
protected function get_bulk_actions() {
$actions = array();
- $actions['delete'] = __( 'Delete Permanently' );
+ if ( MEDIA_TRASH ) {
+ if ( $this->is_trash ) {
+ $actions['untrash'] = __( 'Restore' );
+ $actions['delete'] = __( 'Delete Permanently' );
+ } else {
+ $actions['trash'] = __( 'Trash' );
+ }
+ } else {
+ $actions['delete'] = __( 'Delete Permanently' );
+ }
+
if ( $this->detached )
$actions['attach'] = __( 'Attach to a post' );
return $actions;
}
+ /**
+ * @param string $which
+ */
protected function extra_tablenav( $which ) {
if ( 'bar' !== $which ) {
return;
if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
return 'attach';
+ if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) )
+ return 'detach';
+
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
return 'delete_all';
_e( 'No media attachments found.' );
}
- protected function pagination( $which ) {
- global $mode;
-
- parent::pagination( $which );
- }
-
- /**
- * Display a view switcher
- *
- * @since 3.1.0
- * @access protected
- */
- protected function view_switcher( $current_mode ) {
- $modes = array(
- 'list' => __( 'List View' ),
- 'grid' => __( 'Grid View' )
- );
-
-?>
- <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
- <div class="view-switch">
-<?php
- foreach ( $modes as $mode => $title ) {
- $classes = array( 'view-' . $mode );
- if ( $current_mode == $mode )
- $classes[] = 'current';
- printf(
- "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
- esc_url( add_query_arg( 'mode', $mode ) ),
- implode( ' ', $classes ),
- $title
- );
- }
- ?>
- </div>
-<?php
- }
-
/**
* Override parent views so we can use the filter bar display.
*/
$views = $this->get_views();
?>
<div class="wp-filter">
- <?php $this->view_switcher( $mode ); ?>
+ <div class="filter-items">
+ <?php $this->view_switcher( $mode ); ?>
- <select class="attachment-filters" name="attachment-filter">
- <?php
- if ( ! empty( $views ) ) {
- foreach ( $views as $class => $view ) {
- echo "\t$view\n";
+ <label for="attachment-filter" class="screen-reader-text"><?php _e( 'Filter by type' ); ?></label>
+ <select class="attachment-filters" name="attachment-filter" id="attachment-filter">
+ <?php
+ if ( ! empty( $views ) ) {
+ foreach ( $views as $class => $view ) {
+ echo "\t$view\n";
+ }
}
- }
- ?>
- </select>
+ ?>
+ </select>
<?php
- $this->extra_tablenav( 'bar' );
+ $this->extra_tablenav( 'bar' );
- /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
- $views = apply_filters( "views_{$this->screen->id}", array() );
+ /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
+ $views = apply_filters( "views_{$this->screen->id}", array() );
- // Back compat for pre-4.0 view links.
- if ( ! empty( $views ) ) {
- echo '<ul class="filter-links">';
- foreach ( $views as $class => $view ) {
- echo "<li class='$class'>$view</li>";
+ // Back compat for pre-4.0 view links.
+ if ( ! empty( $views ) ) {
+ echo '<ul class="filter-links">';
+ foreach ( $views as $class => $view ) {
+ echo "<li class='$class'>$view</li>";
+ }
+ echo '</ul>';
}
- echo '</ul>';
- }
?>
+ </div>
<div class="search-form">
<label for="media-search-input" class="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label>
global $post;
add_filter( 'the_title','esc_html' );
- $alt = '';
while ( have_posts() ) : the_post();
$user_can_edit = current_user_can( 'edit_post', $post->ID );
|| !$this->is_trash && $post->post_status == 'trash' )
continue;
- $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
$post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
$att_title = _draft_or_post_title();
?>
- <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
+ <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
<?php
list( $columns, $hidden ) = $this->get_column_info();
echo $thumb;
} else {
?>
- <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>">
+ <a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>">
<?php echo $thumb; ?>
</a>
<?php if ( $this->is_trash || ! $user_can_edit ) {
echo $att_title;
} else { ?>
- <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>"
+ <a href="<?php echo get_edit_post_link( $post->ID ); ?>"
title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>">
<?php echo $att_title; ?></a>
<?php };
_media_states( $post ); ?></strong>
- <p>
-<?php
- if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
- echo esc_html( strtoupper( $matches[1] ) );
- else
- echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
-?>
- </p>
+ <p class="filename"><?php echo wp_basename( $post->guid ); ?></p>
<?php
echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
?>
} else {
echo $title;
} ?></strong>,
- <?php echo get_the_time( __( 'Y/m/d' ) ); ?>
+ <?php echo get_the_time( __( 'Y/m/d' ) ); ?><br />
+ <?php
+ if ( $user_can_edit ):
+ $detach_url = add_query_arg( array(
+ 'parent_post_id' => $post->post_parent,
+ 'media[]' => $post->ID,
+ '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] )
+ ), 'upload.php' ); ?>
+ <a class="hide-if-no-js detach-from-parent" href="<?php echo $detach_url ?>"><?php _e( 'Detach' ); ?></a>
+ <?php endif; ?>
</td>
<?php
} else {
break;
}
?>
- <td <?php echo $attributes ?>>
- <?php
- /**
- * Fires for each custom column in the Media list table.
- *
- * Custom columns are registered using the 'manage_media_columns' filter.
- *
- * @since 2.5.0
- *
- * @param string $column_name Name of the custom column.
- * @param int $post_id Attachment ID.
- */
- ?>
- <?php do_action( 'manage_media_custom_column', $column_name, $post->ID ); ?>
- </td>
+ <td <?php echo $attributes ?>><?php
+ /**
+ * Fires for each custom column in the Media list table.
+ *
+ * Custom columns are registered using the 'manage_media_columns' filter.
+ *
+ * @since 2.5.0
+ *
+ * @param string $column_name Name of the custom column.
+ * @param int $post_id Attachment ID.
+ */
+ do_action( 'manage_media_custom_column', $column_name, $post->ID );
+ ?></td>
<?php
break;
}
<?php endwhile;
}
+ /**
+ * @param WP_Post $post
+ * @param string $att_title
+ */
private function _get_row_actions( $post, $att_title ) {
$actions = array();
if ( $this->detached ) {
if ( current_user_can( 'edit_post', $post->ID ) )
- $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
+ $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '">' . __( 'Edit' ) . '</a>';
if ( current_user_can( 'delete_post', $post->ID ) )
if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
$actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
}
else {
if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash )
- $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
+ $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '">' . __( 'Edit' ) . '</a>';
if ( current_user_can( 'delete_post', $post->ID ) ) {
if ( $this->is_trash )
$actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";