wp/wp-admin/includes/class-wp-media-list-table.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-admin/includes/class-wp-media-list-table.php	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-admin/includes/class-wp-media-list-table.php	Mon Oct 14 18:28:13 2019 +0200
@@ -42,25 +42,25 @@
 
 		$this->modes = array(
 			'list' => __( 'List View' ),
-			'grid' => __( 'Grid View' )
+			'grid' => __( 'Grid View' ),
 		);
 
-		parent::__construct( array(
-			'plural' => 'media',
-			'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
-		) );
+		parent::__construct(
+			array(
+				'plural' => 'media',
+				'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
+			)
+		);
 	}
 
 	/**
-	 *
 	 * @return bool
 	 */
 	public function ajax_user_can() {
-		return current_user_can('upload_files');
+		return current_user_can( 'upload_files' );
 	}
 
 	/**
-	 *
 	 * @global WP_Query $wp_query
 	 * @global array    $post_mime_types
 	 * @global array    $avail_post_mime_types
@@ -71,15 +71,17 @@
 
 		list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
 
- 		$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
+		$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
 
- 		$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
+		$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
 
-		$this->set_pagination_args( array(
-			'total_items' => $wp_query->found_posts,
-			'total_pages' => $wp_query->max_num_pages,
-			'per_page' => $wp_query->query_vars['posts_per_page'],
-		) );
+		$this->set_pagination_args(
+			array(
+				'total_items' => $wp_query->found_posts,
+				'total_pages' => $wp_query->max_num_pages,
+				'per_page'    => $wp_query->query_vars['posts_per_page'],
+			)
+		);
 	}
 
 	/**
@@ -112,7 +114,7 @@
 				false
 			);
 
-			$type_links[$mime_type] = sprintf(
+			$type_links[ $mime_type ] = sprintf(
 				'<option value="post_mime_type:%s"%s>%s</option>',
 				esc_attr( $mime_type ),
 				$selected,
@@ -128,7 +130,7 @@
 			_x( 'Mine', 'media items' )
 		);
 
-		if ( $this->is_trash || ( defined( 'MEDIA_TRASH') && MEDIA_TRASH ) ) {
+		if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) {
 			$type_links['trash'] = sprintf(
 				'<option value="trash"%s>%s</option>',
 				selected( 'trash' === $filter, true, false ),
@@ -140,7 +142,6 @@
 	}
 
 	/**
-	 *
 	 * @return array
 	 */
 	protected function get_bulk_actions() {
@@ -148,16 +149,17 @@
 		if ( MEDIA_TRASH ) {
 			if ( $this->is_trash ) {
 				$actions['untrash'] = __( 'Restore' );
-				$actions['delete'] = __( 'Delete Permanently' );
+				$actions['delete']  = __( 'Delete Permanently' );
 			} else {
-				$actions['trash'] = _x( 'Trash', 'verb' );
+				$actions['trash'] = __( 'Move to Trash' );
 			}
 		} else {
 			$actions['delete'] = __( 'Delete Permanently' );
 		}
 
-		if ( $this->detached )
+		if ( $this->detached ) {
 			$actions['attach'] = __( 'Attach' );
+		}
 
 		return $actions;
 	}
@@ -169,9 +171,9 @@
 		if ( 'bar' !== $which ) {
 			return;
 		}
-?>
+		?>
 		<div class="actions">
-<?php
+		<?php
 		if ( ! is_singular() ) {
 			if ( ! $this->is_trash ) {
 				$this->months_dropdown( 'attachment' );
@@ -185,30 +187,32 @@
 
 		if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
 			submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
-		} ?>
+		}
+		?>
 		</div>
-<?php
+		<?php
 	}
 
 	/**
-	 *
 	 * @return string
 	 */
 	public function current_action() {
-		if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
+		if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) {
 			return 'attach';
+		}
 
-		if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) )
+		if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) {
 			return 'detach';
+		}
 
-		if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
+		if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
 			return 'delete_all';
+		}
 
 		return parent::current_action();
 	}
 
 	/**
-	 *
 	 * @return bool
 	 */
 	public function has_items() {
@@ -232,7 +236,7 @@
 		$views = $this->get_views();
 
 		$this->screen->render_screen_reader_content( 'heading_views' );
-?>
+		?>
 <div class="wp-filter">
 	<div class="filter-items">
 		<?php $this->view_switcher( $mode ); ?>
@@ -248,7 +252,7 @@
 			?>
 		</select>
 
-<?php
+		<?php
 		$this->extra_tablenav( 'bar' );
 
 		/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
@@ -262,25 +266,24 @@
 			}
 			echo '</ul>';
 		}
-?>
+		?>
 	</div>
 
 	<div class="search-form">
 		<label for="media-search-input" class="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label>
-		<input type="search" placeholder="<?php esc_attr_e( 'Search media items...' ) ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div>
+		<input type="search" placeholder="<?php esc_attr_e( 'Search media items...' ); ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div>
 	</div>
-	<?php
+		<?php
 	}
 
 	/**
-	 *
 	 * @return array
 	 */
 	public function get_columns() {
-		$posts_columns = array();
+		$posts_columns       = array();
 		$posts_columns['cb'] = '<input type="checkbox" />';
 		/* translators: column name */
-		$posts_columns['title'] = _x( 'File', 'column name' );
+		$posts_columns['title']  = _x( 'File', 'column name' );
 		$posts_columns['author'] = __( 'Author' );
 
 		$taxonomies = get_taxonomies_for_attachments( 'objects' );
@@ -291,8 +294,8 @@
 		 *
 		 * @since 3.5.0
 		 *
-		 * @param array  $taxonomies An array of registered taxonomies to show for attachments.
-		 * @param string $post_type  The post type. Default 'attachment'.
+		 * @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' );
@@ -309,10 +312,11 @@
 		}
 
 		/* translators: column name */
-		if ( !$this->detached ) {
+		if ( ! $this->detached ) {
 			$posts_columns['parent'] = _x( 'Uploaded to', 'column name' );
-			if ( post_type_supports( 'attachment', 'comments' ) )
+			if ( post_type_supports( 'attachment', 'comments' ) ) {
 				$posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
+			}
 		}
 		/* translators: column name */
 		$posts_columns['date'] = _x( 'Date', 'column name' );
@@ -321,15 +325,14 @@
 		 *
 		 * @since 2.5.0
 		 *
-		 * @param array $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.
+		 * @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() {
@@ -350,12 +353,16 @@
 	 * @param WP_Post $post The current WP_Post object.
 	 */
 	public function column_cb( $post ) {
-		if ( current_user_can( 'edit_post', $post->ID ) ) { ?>
-			<label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>"><?php
-				echo sprintf( __( 'Select %s' ), _draft_or_post_title() );
-			?></label>
+		if ( current_user_can( 'edit_post', $post->ID ) ) {
+			?>
+			<label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>">
+																		<?php
+																		echo sprintf( __( 'Select %s' ), _draft_or_post_title() );
+																		?>
+			</label>
 			<input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" />
-		<?php }
+			<?php
+		}
 	}
 
 	/**
@@ -368,8 +375,8 @@
 	public function column_title( $post ) {
 		list( $mime ) = explode( '/', $post->post_mime_type );
 
-		$title = _draft_or_post_title();
-		$thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
+		$title      = _draft_or_post_title();
+		$thumb      = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
 		$link_start = $link_end = '';
 
 		if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
@@ -387,9 +394,11 @@
 		<strong<?php echo $class; ?>>
 			<?php
 			echo $link_start;
-			if ( $thumb ) : ?>
+			if ( $thumb ) :
+				?>
 				<span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?>"><?php echo $thumb; ?></span>
-			<?php endif;
+				<?php
+			endif;
 			echo $title . $link_end;
 			_media_states( $post );
 			?>
@@ -412,8 +421,9 @@
 	 * @param WP_Post $post The current WP_Post object.
 	 */
 	public function column_author( $post ) {
-		printf( '<a href="%s">%s</a>',
-			esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ),
+		printf(
+			'<a href="%s">%s</a>',
+			esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
 			get_the_author()
 		);
 	}
@@ -441,7 +451,7 @@
 			$h_time = __( 'Unpublished' );
 		} else {
 			$m_time = $post->post_date;
-			$time = get_post_time( 'G', true, $post, false );
+			$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 ) );
@@ -473,26 +483,31 @@
 		}
 
 		if ( $parent ) {
-			$title = _draft_or_post_title( $post->post_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 ) ) {
-?>
+				?>
 				<strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>">
-					<?php echo $title ?></a></strong><?php
+					<?php echo $title; ?></a></strong>
+								<?php
 			} elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) {
-?>
-				<strong><?php echo $title ?></strong><?php
+				?>
+				<strong><?php echo $title; ?></strong>
+									<?php
 			} 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' );
+			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(
 					'<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>',
 					$detach_url,
@@ -502,8 +517,10 @@
 				);
 			endif;
 		} else {
-			_e( '(Unattached)' ); ?>
-			<?php if ( $user_can_edit ) {
+			_e( '(Unattached)' );
+			?>
+			<?php
+			if ( $user_can_edit ) {
 				$title = _draft_or_post_title( $post->post_parent );
 				printf(
 					'<br /><a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>',
@@ -561,11 +578,12 @@
 			if ( is_array( $terms ) ) {
 				$out = array();
 				foreach ( $terms as $t ) {
-					$posts_in_term_qv = array();
+					$posts_in_term_qv             = array();
 					$posts_in_term_qv['taxonomy'] = $taxonomy;
-					$posts_in_term_qv['term'] = $t->slug;
+					$posts_in_term_qv['term']     = $t->slug;
 
-					$out[] = sprintf( '<a href="%s">%s</a>',
+					$out[] = sprintf(
+						'<a href="%s">%s</a>',
 						esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
 						esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
 					);
@@ -593,7 +611,6 @@
 	}
 
 	/**
-	 *
 	 * @global WP_Post $post
 	 */
 	public function display_rows() {
@@ -604,9 +621,10 @@
 
 		$this->comment_pending_count = get_pending_comments_num( $post_ids );
 
-		add_filter( 'the_title','esc_html' );
+		add_filter( 'the_title', 'esc_html' );
 
-		while ( have_posts() ) : the_post();
+		while ( have_posts() ) :
+			the_post();
 			if (
 				( $this->is_trash && $post->post_status != 'trash' )
 				|| ( ! $this->is_trash && $post->post_status === 'trash' )
@@ -614,11 +632,11 @@
 				continue;
 			}
 			$post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
-		?>
+			?>
 			<tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
 				<?php $this->single_row_columns( $post ); ?>
 			</tr>
-		<?php
+			<?php
 		endwhile;
 	}
 
@@ -662,7 +680,7 @@
 						_x( 'Trash', 'verb' )
 					);
 				} else {
-					$delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
+					$delete_ays        = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
 					$actions['delete'] = sprintf(
 						'<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
 						wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
@@ -690,9 +708,8 @@
 					__( 'Attach' )
 				);
 			}
-		}
-		else {
-			if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash ) {
+		} else {
+			if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
 				$actions['edit'] = sprintf(
 					'<a href="%s" aria-label="%s">%s</a>',
 					get_edit_post_link( $post->ID ),
@@ -720,7 +737,7 @@
 					);
 				}
 				if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
-					$delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
+					$delete_ays        = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
 					$actions['delete'] = sprintf(
 						'<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
 						wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
@@ -747,11 +764,11 @@
 		 *
 		 * @since 2.8.0
 		 *
-		 * @param array   $actions  An array of action links for each attachment.
-		 *                          Default 'Edit', 'Delete Permanently', 'View'.
-		 * @param WP_Post $post     WP_Post object for the current attachment.
-		 * @param bool    $detached Whether the list table contains media not attached
-		 *                          to any posts. Default true.
+		 * @param string[] $actions  An array of action links for each attachment.
+		 *                           Default 'Edit', 'Delete Permanently', 'View'.
+		 * @param WP_Post  $post     WP_Post object for the current attachment.
+		 * @param bool     $detached Whether the list table contains media not attached
+		 *                           to any posts. Default true.
 		 */
 		return apply_filters( 'media_row_actions', $actions, $post, $this->detached );
 	}