is_trash ) {
_e( 'No media files found in Trash.' );
} else {
_e( 'No media files found.' );
}
}
/**
* Override parent views so we can use the filter bar display.
*
* @global string $mode List table view mode.
*/
public function views() {
global $mode;
$views = $this->get_views();
$this->screen->render_screen_reader_content( 'heading_views' );
?>
view_switcher( $mode ); ?>
extra_tablenav( 'bar' );
/** 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 '
';
foreach ( $views as $class => $view ) {
echo "
$view
";
}
echo '
';
}
?>
';
/* translators: Column name. */
$posts_columns['title'] = _x( 'File', 'column name' );
$posts_columns['author'] = __( 'Author' );
$taxonomies = get_taxonomies_for_attachments( 'objects' );
$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
/**
* Filters the taxonomy columns for attachments in the Media list table.
*
* @since 3.5.0
*
* @param string[] $taxonomies An array of registered taxonomy names to show for attachments.
* @param string $post_type The post type. Default 'attachment'.
*/
$taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' );
$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
foreach ( $taxonomies as $taxonomy ) {
if ( 'category' === $taxonomy ) {
$column_key = 'categories';
} elseif ( 'post_tag' === $taxonomy ) {
$column_key = 'tags';
} else {
$column_key = 'taxonomy-' . $taxonomy;
}
$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
}
/* translators: Column name. */
if ( ! $this->detached ) {
$posts_columns['parent'] = _x( 'Uploaded to', 'column name' );
if ( post_type_supports( 'attachment', 'comments' ) ) {
$posts_columns['comments'] = sprintf(
'%2$s',
esc_attr__( 'Comments' ),
__( 'Comments' )
);
}
}
/* translators: Column name. */
$posts_columns['date'] = _x( 'Date', 'column name' );
/**
* Filters the Media list table columns.
*
* @since 2.5.0
*
* @param string[] $posts_columns An array of columns displayed in the Media list table.
* @param bool $detached Whether the list table contains media not attached
* to any posts. Default true.
*/
return apply_filters( 'manage_media_columns', $posts_columns, $this->detached );
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'title' => 'title',
'author' => 'author',
'parent' => 'parent',
'comments' => 'comment_count',
'date' => array( 'date', true ),
);
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
* @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param WP_Post $item The current WP_Post object.
*/
public function column_cb( $item ) {
// Restores the more descriptive, specific name for use within this method.
$post = $item;
if ( current_user_can( 'edit_post', $post->ID ) ) {
?>
post_mime_type );
$attachment_id = $post->ID;
if ( has_post_thumbnail( $post ) ) {
$thumbnail_id = get_post_thumbnail_id( $post );
if ( ! empty( $thumbnail_id ) ) {
$attachment_id = $thumbnail_id;
}
}
$title = _draft_or_post_title();
$thumb = wp_get_attachment_image( $attachment_id, array( 60, 60 ), true, array( 'alt' => '' ) );
$link_start = '';
$link_end = '';
if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
$link_start = sprintf(
'',
get_edit_post_link( $post->ID ),
/* translators: %s: Attachment title. */
esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) )
);
$link_end = '';
}
$class = $thumb ? ' class="has-media-icon"' : '';
?>
>
ID );
echo esc_html( wp_basename( $file ) );
?>
%s',
esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
get_the_author()
);
}
/**
* Handles the description column output.
*
* @since 4.3.0
* @deprecated 6.2.0
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_desc( $post ) {
_deprecated_function( __METHOD__, '6.2.0' );
}
/**
* Handles the date column output.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_date( $post ) {
if ( '0000-00-00 00:00:00' === $post->post_date ) {
$h_time = __( 'Unpublished' );
} else {
$time = get_post_timestamp( $post );
$time_diff = time() - $time;
if ( $time && $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
/* translators: %s: Human-readable time difference. */
$h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
} else {
$h_time = get_the_time( __( 'Y/m/d' ), $post );
}
}
/**
* Filters the published time of an attachment displayed in the Media list table.
*
* @since 6.0.0
*
* @param string $h_time The published time.
* @param WP_Post $post Attachment object.
* @param string $column_name The column name.
*/
echo apply_filters( 'media_date_column_time', $h_time, $post, 'date' );
}
/**
* Handles the parent column output.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_parent( $post ) {
$user_can_edit = current_user_can( 'edit_post', $post->ID );
if ( $post->post_parent > 0 ) {
$parent = get_post( $post->post_parent );
} else {
$parent = false;
}
if ( $parent ) {
$title = _draft_or_post_title( $post->post_parent );
$parent_type = get_post_type_object( $parent->post_type );
if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) {
printf( '%s', get_edit_post_link( $post->post_parent ), $title );
} elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) {
printf( '%s', $title );
} else {
_e( '(Private post)' );
}
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'
);
printf(
' %s',
$detach_url,
/* translators: %s: Title of the post the attachment is attached to. */
esc_attr( sprintf( __( 'Detach from “%s”' ), $title ) ),
__( 'Detach' )
);
endif;
} else {
_e( '(Unattached)' );
?>
post_parent );
printf(
' %s',
$post->ID,
/* translators: %s: Attachment title. */
esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $title ) ),
__( 'Attach' )
);
}
}
}
/**
* Handles the comments column output.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_comments( $post ) {
echo '