diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index 0c76796562..ba40437517 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -310,6 +310,224 @@ class WP_Media_List_Table extends WP_List_Table { ); } + /** + * @since 4.3.0 + * + * @param WP_Post $post + */ + public function column_cb( $post ) { + if ( current_user_can( 'edit_post', $post->ID ) ) { ?> + + + post_mime_type ); + + $user_can_edit = current_user_can( 'edit_post', $post->ID ); + $att_title = _draft_or_post_title(); + ?> +
+ ID, array( 60, 60 ), true ); + if ( $thumb ) { + if ( $this->is_trash || ! $user_can_edit ) { + echo $thumb; + } else { ?> + +
+
+ + is_trash || ! $user_can_edit ) { + echo $att_title; + } else { ?> + + +

guid ); ?>

+
+ %s', + esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ), + get_the_author() + ); + } + + /** + * @since 4.3.0 + * + * @param WP_Post $post + */ + public function column_desc( $post ) { + echo has_excerpt() ? $post->post_excerpt : ''; + } + + /** + * @since 4.3.0 + * + * @param WP_Post $post + */ + public function column_date( $post ) { + if ( '0000-00-00 00:00:00' == $post->post_date ) { + $h_time = __( 'Unpublished' ); + } else { + $m_time = $post->post_date; + $time = get_post_time( 'G', true, $post, false ); + if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) { + if ( $t_diff < 0 ) { + $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) ); + } else { + $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); + } + } else { + $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); + } + } + + echo $h_time; + } + + /** + * @since 4.3.0 + * + * @param WP_Post $post + */ + 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 ); +?> + + show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { ?> + + , +
+ $post->post_parent, + 'media[]' => $post->ID, + '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ) + ), 'upload.php' ); ?> + +
+ + + + '; + + $pending_comments = get_pending_comments_num( $post->ID ); + $this->comments_bubble( $post->ID, $pending_comments ); + + echo ''; + } + + /** + * @since 4.3.0 + * + * @param WP_Post $post + * @param string $column_name + */ + public function column_default( $post, $column_name ) { + if ( 'categories' == $column_name ) { + $taxonomy = 'category'; + } elseif ( 'tags' == $column_name ) { + $taxonomy = 'post_tag'; + } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { + $taxonomy = substr( $column_name, 9 ); + } else { + $taxonomy = false; + } + + if ( $taxonomy ) { + $terms = get_the_terms( $post->ID, $taxonomy ); + if ( is_array( $terms ) ) { + $out = array(); + foreach ( $terms as $t ) { + $posts_in_term_qv = array(); + $posts_in_term_qv['taxonomy'] = $taxonomy; + $posts_in_term_qv['term'] = $t->slug; + + $out[] = sprintf( '%s', + esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ), + esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ) + ); + } + /* translators: used between list items, there is a space after the comma */ + echo join( __( ', ' ), $out ); + } else { + echo '' . get_taxonomy( $taxonomy )->labels->not_found . ''; + } + + return; + } + + /** + * Fires for each custom column in the Media list table. + * + * Custom columns are registered using the {@see '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 ); + } + /** * * @global WP_Post $post @@ -320,213 +538,19 @@ class WP_Media_List_Table extends WP_List_Table { add_filter( 'the_title','esc_html' ); while ( have_posts() ) : the_post(); - $user_can_edit = current_user_can( 'edit_post', $post->ID ); - - if ( $this->is_trash && $post->post_status != 'trash' - || !$this->is_trash && $post->post_status == 'trash' ) + if ( + ( $this->is_trash && $post->post_status != 'trash' ) + || ( ! $this->is_trash && $post->post_status == 'trash' ) + ) { continue; - + } $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other'; - $att_title = _draft_or_post_title(); -?> - -get_column_info(); - -foreach ( $columns as $column_name => $column_display_name ) { - $classes = "$column_name column-$column_name"; - if ( $primary === $column_name ) { - $classes .= ' has-row-actions column-primary'; - } - - if ( in_array( $column_name, $hidden ) ) { - $classes .= ' hidden'; - } - - $attributes = "class='$classes'"; - - if ( 'cb' === $column_name ) { -?> - - - - - - -"; - - switch ( $column_name ) { - case 'title': - list( $mime ) = explode( '/', $post->post_mime_type ); - - echo "
"; - - if ( $thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true ) ) { - if ( $this->is_trash || ! $user_can_edit ) { - echo $thumb; - } else { ?> - - -
'; -?> - - is_trash || ! $user_can_edit ) { - echo $att_title; - } else { ?> - - - -

guid ); ?>

-
-%s', - esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ), - get_the_author() - ); - - break; - - case 'desc': - echo has_excerpt() ? $post->post_excerpt : ''; - break; - - case 'date': - if ( '0000-00-00 00:00:00' == $post->post_date ) { - $h_time = __( 'Unpublished' ); - } else { - $m_time = $post->post_date; - $time = get_post_time( 'G', true, $post, false ); - if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) { - if ( $t_diff < 0 ) - $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) ); - else - $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); - } else { - $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); - } - } - - echo $h_time; - break; - - case 'parent': - 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 ); ?> - - show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { ?> - - , -
- $post->post_parent, - 'media[]' => $post->ID, - '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ) - ), 'upload.php' ); ?> - -
- - - - '; - - $pending_comments = get_pending_comments_num( $post->ID ); - $this->comments_bubble( $post->ID, $pending_comments ); - - echo '
'; - - break; - - default: - if ( 'categories' == $column_name ) - $taxonomy = 'category'; - elseif ( 'tags' == $column_name ) - $taxonomy = 'post_tag'; - elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) - $taxonomy = substr( $column_name, 9 ); - else - $taxonomy = false; - - if ( $taxonomy ) { - $terms = get_the_terms( $post->ID, $taxonomy ); - if ( is_array( $terms ) ) { - $out = array(); - foreach ( $terms as $t ) { - $posts_in_term_qv = array(); - $posts_in_term_qv['taxonomy'] = $taxonomy; - $posts_in_term_qv['term'] = $t->slug; - - $out[] = sprintf( '%s', - esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ), - esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ) - ); - } - /* translators: used between list items, there is a space after the comma */ - echo join( __( ', ' ), $out ); - } else { - echo '' . get_taxonomy( $taxonomy )->labels->not_found . ''; - } - - break; - } - - /** - * Fires for each custom column in the Media list table. - * - * Custom columns are registered using the {@see '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 ); - break; - } - - if( $primary === $column_name ) { - echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) ); - } - - echo ''; - } -} -?> - -ID; ?>" class="post_status ); ?>"> + single_row_columns( $post ); ?> + +