author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* List Table API: WP_Media_List_Table class |
0 | 4 |
* |
5 |
* @package WordPress |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @subpackage Administration |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
* Core class used to implement displaying media items in a list table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* |
0 | 13 |
* @since 3.1.0 |
14 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* @see WP_List_Table |
0 | 17 |
*/ |
18 |
class WP_Media_List_Table extends WP_List_Table { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* Holds the number of pending comments for each post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @var array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
protected $comment_pending_count = array(); |
0 | 26 |
|
5 | 27 |
private $detached; |
28 |
||
29 |
private $is_trash; |
|
30 |
||
31 |
/** |
|
32 |
* Constructor. |
|
33 |
* |
|
34 |
* @since 3.1.0 |
|
35 |
* |
|
36 |
* @see WP_List_Table::__construct() for more information on default arguments. |
|
37 |
* |
|
38 |
* @param array $args An associative array of arguments. |
|
39 |
*/ |
|
40 |
public function __construct( $args = array() ) { |
|
41 |
$this->detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] ); |
|
42 |
||
43 |
$this->modes = array( |
|
16 | 44 |
'list' => __( 'List view' ), |
45 |
'grid' => __( 'Grid view' ), |
|
5 | 46 |
); |
0 | 47 |
|
9 | 48 |
parent::__construct( |
49 |
array( |
|
50 |
'plural' => 'media', |
|
51 |
'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
|
52 |
) |
|
53 |
); |
|
0 | 54 |
} |
55 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
*/ |
5 | 59 |
public function ajax_user_can() { |
9 | 60 |
return current_user_can( 'upload_files' ); |
0 | 61 |
} |
62 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
/** |
16 | 64 |
* @global string $mode List table view mode. |
65 |
* @global WP_Query $wp_query WordPress Query object. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
* @global array $post_mime_types |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
* @global array $avail_post_mime_types |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
*/ |
5 | 69 |
public function prepare_items() { |
16 | 70 |
global $mode, $wp_query, $post_mime_types, $avail_post_mime_types; |
71 |
||
72 |
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; |
|
73 |
||
18 | 74 |
/* |
75 |
* Exclude attachments scheduled for deletion in the next two hours |
|
76 |
* if they are for zip packages for interrupted or failed updates. |
|
77 |
* See File_Upload_Upgrader class. |
|
78 |
*/ |
|
16 | 79 |
$not_in = array(); |
80 |
||
19 | 81 |
$crons = _get_cron_array(); |
16 | 82 |
|
19 | 83 |
if ( is_array( $crons ) ) { |
84 |
foreach ( $crons as $cron ) { |
|
85 |
if ( isset( $cron['upgrader_scheduled_cleanup'] ) ) { |
|
86 |
$details = reset( $cron['upgrader_scheduled_cleanup'] ); |
|
87 |
||
88 |
if ( ! empty( $details['args'][0] ) ) { |
|
89 |
$not_in[] = (int) $details['args'][0]; |
|
90 |
} |
|
16 | 91 |
} |
92 |
} |
|
93 |
} |
|
94 |
||
95 |
if ( ! empty( $_REQUEST['post__not_in'] ) && is_array( $_REQUEST['post__not_in'] ) ) { |
|
96 |
$not_in = array_merge( array_values( $_REQUEST['post__not_in'] ), $not_in ); |
|
97 |
} |
|
98 |
||
99 |
if ( ! empty( $not_in ) ) { |
|
100 |
$_REQUEST['post__not_in'] = $not_in; |
|
101 |
} |
|
0 | 102 |
|
5 | 103 |
list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST ); |
0 | 104 |
|
9 | 105 |
$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter']; |
0 | 106 |
|
9 | 107 |
$this->set_pagination_args( |
108 |
array( |
|
109 |
'total_items' => $wp_query->found_posts, |
|
110 |
'total_pages' => $wp_query->max_num_pages, |
|
111 |
'per_page' => $wp_query->query_vars['posts_per_page'], |
|
112 |
) |
|
113 |
); |
|
0 | 114 |
} |
115 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
* @global array $post_mime_types |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* @global array $avail_post_mime_types |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
*/ |
5 | 121 |
protected function get_views() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
global $post_mime_types, $avail_post_mime_types; |
0 | 123 |
|
124 |
$type_links = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
$filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter']; |
0 | 127 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
$type_links['all'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
'<option value=""%s>%s</option>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
selected( $filter, true, false ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
__( 'All media items' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
|
0 | 134 |
foreach ( $post_mime_types as $mime_type => $label ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) { |
0 | 136 |
continue; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
$selected = selected( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
$filter && 0 === strpos( $filter, 'post_mime_type:' ) && |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
false |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
); |
0 | 145 |
|
9 | 146 |
$type_links[ $mime_type ] = sprintf( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
'<option value="post_mime_type:%s"%s>%s</option>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
esc_attr( $mime_type ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
$selected, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
$label[0] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
); |
0 | 152 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
|
19 | 154 |
$type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . _x( 'Unattached', 'media items' ) . '</option>'; |
0 | 155 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
$type_links['mine'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
'<option value="mine"%s>%s</option>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
selected( 'mine' === $filter, true, false ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
_x( 'Mine', 'media items' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
|
9 | 162 |
if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
$type_links['trash'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
'<option value="trash"%s>%s</option>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
selected( 'trash' === $filter, true, false ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
_x( 'Trash', 'attachment filter' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
} |
0 | 169 |
|
170 |
return $type_links; |
|
171 |
} |
|
172 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
*/ |
5 | 176 |
protected function get_bulk_actions() { |
0 | 177 |
$actions = array(); |
18 | 178 |
|
5 | 179 |
if ( MEDIA_TRASH ) { |
180 |
if ( $this->is_trash ) { |
|
181 |
$actions['untrash'] = __( 'Restore' ); |
|
16 | 182 |
$actions['delete'] = __( 'Delete permanently' ); |
5 | 183 |
} else { |
9 | 184 |
$actions['trash'] = __( 'Move to Trash' ); |
5 | 185 |
} |
186 |
} else { |
|
16 | 187 |
$actions['delete'] = __( 'Delete permanently' ); |
5 | 188 |
} |
189 |
||
9 | 190 |
if ( $this->detached ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
$actions['attach'] = __( 'Attach' ); |
9 | 192 |
} |
0 | 193 |
|
194 |
return $actions; |
|
195 |
} |
|
196 |
||
5 | 197 |
/** |
198 |
* @param string $which |
|
199 |
*/ |
|
200 |
protected function extra_tablenav( $which ) { |
|
201 |
if ( 'bar' !== $which ) { |
|
202 |
return; |
|
203 |
} |
|
9 | 204 |
?> |
5 | 205 |
<div class="actions"> |
18 | 206 |
<?php |
207 |
if ( ! $this->is_trash ) { |
|
208 |
$this->months_dropdown( 'attachment' ); |
|
209 |
} |
|
210 |
||
211 |
/** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */ |
|
212 |
do_action( 'restrict_manage_posts', $this->screen->post_type, $which ); |
|
0 | 213 |
|
18 | 214 |
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
0 | 215 |
|
18 | 216 |
if ( $this->is_trash && $this->has_items() |
217 |
&& current_user_can( 'edit_others_posts' ) |
|
218 |
) { |
|
219 |
submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); |
|
220 |
} |
|
221 |
?> |
|
0 | 222 |
</div> |
9 | 223 |
<?php |
0 | 224 |
} |
225 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
* @return string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
*/ |
5 | 229 |
public function current_action() { |
9 | 230 |
if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) { |
0 | 231 |
return 'attach'; |
9 | 232 |
} |
0 | 233 |
|
9 | 234 |
if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) { |
5 | 235 |
return 'detach'; |
9 | 236 |
} |
5 | 237 |
|
9 | 238 |
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { |
0 | 239 |
return 'delete_all'; |
9 | 240 |
} |
0 | 241 |
|
242 |
return parent::current_action(); |
|
243 |
} |
|
244 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
*/ |
5 | 248 |
public function has_items() { |
0 | 249 |
return have_posts(); |
250 |
} |
|
251 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
*/ |
5 | 254 |
public function no_items() { |
16 | 255 |
if ( $this->is_trash ) { |
256 |
_e( 'No media files found in Trash.' ); |
|
257 |
} else { |
|
258 |
_e( 'No media files found.' ); |
|
259 |
} |
|
0 | 260 |
} |
261 |
||
5 | 262 |
/** |
263 |
* Override parent views so we can use the filter bar display. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
* @global string $mode List table view mode. |
5 | 266 |
*/ |
267 |
public function views() { |
|
268 |
global $mode; |
|
269 |
||
270 |
$views = $this->get_views(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
$this->screen->render_screen_reader_content( 'heading_views' ); |
9 | 273 |
?> |
18 | 274 |
<div class="wp-filter"> |
275 |
<div class="filter-items"> |
|
276 |
<?php $this->view_switcher( $mode ); ?> |
|
5 | 277 |
|
18 | 278 |
<label for="attachment-filter" class="screen-reader-text"><?php _e( 'Filter by type' ); ?></label> |
279 |
<select class="attachment-filters" name="attachment-filter" id="attachment-filter"> |
|
280 |
<?php |
|
281 |
if ( ! empty( $views ) ) { |
|
282 |
foreach ( $views as $class => $view ) { |
|
283 |
echo "\t$view\n"; |
|
284 |
} |
|
285 |
} |
|
286 |
?> |
|
287 |
</select> |
|
5 | 288 |
|
18 | 289 |
<?php |
290 |
$this->extra_tablenav( 'bar' ); |
|
5 | 291 |
|
18 | 292 |
/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */ |
293 |
$views = apply_filters( "views_{$this->screen->id}", array() ); |
|
5 | 294 |
|
18 | 295 |
// Back compat for pre-4.0 view links. |
296 |
if ( ! empty( $views ) ) { |
|
297 |
echo '<ul class="filter-links">'; |
|
298 |
foreach ( $views as $class => $view ) { |
|
299 |
echo "<li class='$class'>$view</li>"; |
|
300 |
} |
|
301 |
echo '</ul>'; |
|
302 |
} |
|
303 |
?> |
|
304 |
</div> |
|
5 | 305 |
|
18 | 306 |
<div class="search-form"> |
307 |
<label for="media-search-input" class="media-search-input-label"><?php esc_html_e( 'Search' ); ?></label> |
|
308 |
<input type="search" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"> |
|
309 |
</div> |
|
310 |
</div> |
|
9 | 311 |
<?php |
5 | 312 |
} |
313 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
*/ |
5 | 317 |
public function get_columns() { |
9 | 318 |
$posts_columns = array(); |
0 | 319 |
$posts_columns['cb'] = '<input type="checkbox" />'; |
16 | 320 |
/* translators: Column name. */ |
9 | 321 |
$posts_columns['title'] = _x( 'File', 'column name' ); |
0 | 322 |
$posts_columns['author'] = __( 'Author' ); |
323 |
||
324 |
$taxonomies = get_taxonomies_for_attachments( 'objects' ); |
|
325 |
$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); |
|
326 |
||
5 | 327 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* Filters the taxonomy columns for attachments in the Media list table. |
5 | 329 |
* |
330 |
* @since 3.5.0 |
|
331 |
* |
|
9 | 332 |
* @param string[] $taxonomies An array of registered taxonomy names to show for attachments. |
333 |
* @param string $post_type The post type. Default 'attachment'. |
|
5 | 334 |
*/ |
0 | 335 |
$taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' ); |
336 |
$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' ); |
|
337 |
||
338 |
foreach ( $taxonomies as $taxonomy ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
if ( 'category' === $taxonomy ) { |
0 | 340 |
$column_key = 'categories'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
} elseif ( 'post_tag' === $taxonomy ) { |
0 | 342 |
$column_key = 'tags'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
} else { |
0 | 344 |
$column_key = 'taxonomy-' . $taxonomy; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
} |
18 | 346 |
|
0 | 347 |
$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name; |
348 |
} |
|
349 |
||
16 | 350 |
/* translators: Column name. */ |
9 | 351 |
if ( ! $this->detached ) { |
0 | 352 |
$posts_columns['parent'] = _x( 'Uploaded to', 'column name' ); |
9 | 353 |
if ( post_type_supports( 'attachment', 'comments' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
$posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>'; |
9 | 355 |
} |
0 | 356 |
} |
18 | 357 |
|
16 | 358 |
/* translators: Column name. */ |
0 | 359 |
$posts_columns['date'] = _x( 'Date', 'column name' ); |
18 | 360 |
|
5 | 361 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
* Filters the Media list table columns. |
5 | 363 |
* |
364 |
* @since 2.5.0 |
|
365 |
* |
|
9 | 366 |
* @param string[] $posts_columns An array of columns displayed in the Media list table. |
367 |
* @param bool $detached Whether the list table contains media not attached |
|
368 |
* to any posts. Default true. |
|
5 | 369 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
return apply_filters( 'manage_media_columns', $posts_columns, $this->detached ); |
0 | 371 |
} |
372 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
*/ |
5 | 376 |
protected function get_sortable_columns() { |
0 | 377 |
return array( |
378 |
'title' => 'title', |
|
379 |
'author' => 'author', |
|
380 |
'parent' => 'parent', |
|
381 |
'comments' => 'comment_count', |
|
382 |
'date' => array( 'date', true ), |
|
383 |
); |
|
384 |
} |
|
385 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* Handles the checkbox column output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* @since 4.3.0 |
19 | 390 |
* @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* |
19 | 392 |
* @param WP_Post $item The current WP_Post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
*/ |
19 | 394 |
public function column_cb( $item ) { |
395 |
// Restores the more descriptive, specific name for use within this method. |
|
396 |
$post = $item; |
|
397 |
||
9 | 398 |
if ( current_user_can( 'edit_post', $post->ID ) ) { |
399 |
?> |
|
400 |
<label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>"> |
|
16 | 401 |
<?php |
402 |
/* translators: %s: Attachment title. */ |
|
403 |
printf( __( 'Select %s' ), _draft_or_post_title() ); |
|
404 |
?> |
|
9 | 405 |
</label> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
<input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" /> |
9 | 407 |
<?php |
408 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
} |
0 | 410 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
* Handles the title column output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
* @param WP_Post $post The current WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
public function column_title( $post ) { |
5 | 419 |
list( $mime ) = explode( '/', $post->post_mime_type ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
|
9 | 421 |
$title = _draft_or_post_title(); |
422 |
$thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) ); |
|
16 | 423 |
$link_start = ''; |
424 |
$link_end = ''; |
|
0 | 425 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
$link_start = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
'<a href="%s" aria-label="%s">', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
get_edit_post_link( $post->ID ), |
16 | 430 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
$link_end = '</a>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
} |
0 | 435 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
$class = $thumb ? ' class="has-media-icon"' : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
<strong<?php echo $class; ?>> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
echo $link_start; |
18 | 441 |
|
9 | 442 |
if ( $thumb ) : |
443 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
<span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?>"><?php echo $thumb; ?></span> |
9 | 445 |
<?php |
446 |
endif; |
|
18 | 447 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
echo $title . $link_end; |
18 | 449 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
_media_states( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
</strong> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
<p class="filename"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
<span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
$file = get_attached_file( $post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
echo esc_html( wp_basename( $file ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
</p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
} |
0 | 462 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
* Handles the author column output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
* @param WP_Post $post The current WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
public function column_author( $post ) { |
9 | 471 |
printf( |
472 |
'<a href="%s">%s</a>', |
|
473 |
esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
get_the_author() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
} |
0 | 477 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
* Handles the description column output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
* @param WP_Post $post The current WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
public function column_desc( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
echo has_excerpt() ? $post->post_excerpt : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
} |
0 | 488 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
* Handles the date column output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
* @param WP_Post $post The current WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
public function column_date( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
if ( '0000-00-00 00:00:00' === $post->post_date ) { |
0 | 498 |
$h_time = __( 'Unpublished' ); |
499 |
} else { |
|
16 | 500 |
$time = get_post_timestamp( $post ); |
501 |
$time_diff = time() - $time; |
|
502 |
||
503 |
if ( $time && $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) { |
|
504 |
/* translators: %s: Human-readable time difference. */ |
|
505 |
$h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); |
|
0 | 506 |
} else { |
16 | 507 |
$h_time = get_the_time( __( 'Y/m/d' ), $post ); |
0 | 508 |
} |
509 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
|
19 | 511 |
/** |
512 |
* Filters the published time of an attachment displayed in the Media list table. |
|
513 |
* |
|
514 |
* @since 6.0.0 |
|
515 |
* |
|
516 |
* @param string $h_time The published time. |
|
517 |
* @param WP_Post $post Attachment object. |
|
518 |
* @param string $column_name The column name. |
|
519 |
*/ |
|
520 |
echo apply_filters( 'media_date_column_time', $h_time, $post, 'date' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
} |
0 | 522 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
* Handles the parent column output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* @param WP_Post $post The current WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
public function column_parent( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
$user_can_edit = current_user_can( 'edit_post', $post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
if ( $post->post_parent > 0 ) { |
0 | 534 |
$parent = get_post( $post->post_parent ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
} else { |
0 | 536 |
$parent = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
} |
0 | 538 |
|
539 |
if ( $parent ) { |
|
9 | 540 |
$title = _draft_or_post_title( $post->post_parent ); |
0 | 541 |
$parent_type = get_post_type_object( $parent->post_type ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { |
18 | 544 |
printf( '<strong><a href="%s">%s</a></strong>', get_edit_post_link( $post->post_parent ), $title ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
} elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) { |
18 | 546 |
printf( '<strong>%s</strong>', $title ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
_e( '(Private post)' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
|
9 | 551 |
if ( $user_can_edit ) : |
552 |
$detach_url = add_query_arg( |
|
553 |
array( |
|
554 |
'parent_post_id' => $post->post_parent, |
|
555 |
'media[]' => $post->ID, |
|
556 |
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ), |
|
557 |
), |
|
558 |
'upload.php' |
|
559 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
printf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
'<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
$detach_url, |
16 | 563 |
/* translators: %s: Title of the post the attachment is attached to. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
esc_attr( sprintf( __( 'Detach from “%s”' ), $title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
__( 'Detach' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
endif; |
0 | 568 |
} else { |
9 | 569 |
_e( '(Unattached)' ); |
570 |
?> |
|
571 |
<?php |
|
572 |
if ( $user_can_edit ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
$title = _draft_or_post_title( $post->post_parent ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
printf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
'<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>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
$post->ID, |
16 | 577 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
__( 'Attach' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
} |
0 | 582 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
} |
0 | 584 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
* Handles the comments column output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
* @param WP_Post $post The current WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
public function column_comments( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
echo '<div class="post-com-count-wrapper">'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
if ( isset( $this->comment_pending_count[ $post->ID ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
$pending_comments = $this->comment_pending_count[ $post->ID ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
$pending_comments = get_pending_comments_num( $post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
} |
0 | 600 |
|
601 |
$this->comments_bubble( $post->ID, $pending_comments ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
echo '</div>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
} |
0 | 605 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* Handles output for the default column. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
* @since 4.3.0 |
19 | 610 |
* @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
* |
19 | 612 |
* @param WP_Post $item The current WP_Post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
* @param string $column_name Current column name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
*/ |
19 | 615 |
public function column_default( $item, $column_name ) { |
616 |
// Restores the more descriptive, specific name for use within this method. |
|
617 |
$post = $item; |
|
618 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
if ( 'categories' === $column_name ) { |
0 | 620 |
$taxonomy = 'category'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
} elseif ( 'tags' === $column_name ) { |
0 | 622 |
$taxonomy = 'post_tag'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
} elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { |
0 | 624 |
$taxonomy = substr( $column_name, 9 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
} else { |
0 | 626 |
$taxonomy = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
} |
0 | 628 |
|
629 |
if ( $taxonomy ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
$terms = get_the_terms( $post->ID, $taxonomy ); |
18 | 631 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
if ( is_array( $terms ) ) { |
0 | 633 |
$out = array(); |
634 |
foreach ( $terms as $t ) { |
|
9 | 635 |
$posts_in_term_qv = array(); |
0 | 636 |
$posts_in_term_qv['taxonomy'] = $taxonomy; |
9 | 637 |
$posts_in_term_qv['term'] = $t->slug; |
0 | 638 |
|
9 | 639 |
$out[] = sprintf( |
640 |
'<a href="%s">%s</a>', |
|
0 | 641 |
esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ), |
642 |
esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ) |
|
643 |
); |
|
644 |
} |
|
19 | 645 |
echo implode( wp_get_list_item_separator(), $out ); |
0 | 646 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>'; |
0 | 648 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
return; |
0 | 651 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* Fires for each custom column in the Media list table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
655 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
* Custom columns are registered using the {@see 'manage_media_columns'} filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
* @param string $column_name Name of the custom column. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
* @param int $post_id Attachment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
do_action( 'manage_media_custom_column', $column_name, $post->ID ); |
0 | 664 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
/** |
16 | 667 |
* @global WP_Post $post Global post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
public function display_rows() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
global $post, $wp_query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
$post_ids = wp_list_pluck( $wp_query->posts, 'ID' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
reset( $wp_query->posts ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
$this->comment_pending_count = get_pending_comments_num( $post_ids ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
|
9 | 677 |
add_filter( 'the_title', 'esc_html' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
|
9 | 679 |
while ( have_posts() ) : |
680 |
the_post(); |
|
18 | 681 |
|
682 |
if ( $this->is_trash && 'trash' !== $post->post_status |
|
683 |
|| ! $this->is_trash && 'trash' === $post->post_status |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
} |
18 | 687 |
|
688 |
$post_owner = ( get_current_user_id() === (int) $post->post_author ) ? 'self' : 'other'; |
|
9 | 689 |
?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
<tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
<?php $this->single_row_columns( $post ); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
</tr> |
9 | 693 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
endwhile; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
* Gets the name of the default primary column. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
* @return string Name of the default primary column, in this case, 'title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
protected function get_default_primary_column_name() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
return 'title'; |
0 | 706 |
} |
707 |
||
5 | 708 |
/** |
709 |
* @param WP_Post $post |
|
710 |
* @param string $att_title |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
* @return array |
5 | 712 |
*/ |
713 |
private function _get_row_actions( $post, $att_title ) { |
|
0 | 714 |
$actions = array(); |
715 |
||
716 |
if ( $this->detached ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
if ( current_user_can( 'edit_post', $post->ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
$actions['edit'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
'<a href="%s" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
720 |
get_edit_post_link( $post->ID ), |
16 | 721 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
__( 'Edit' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
} |
18 | 726 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
if ( current_user_can( 'delete_post', $post->ID ) ) { |
0 | 728 |
if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
$actions['trash'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ), |
16 | 732 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
_x( 'Trash', 'verb' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
); |
0 | 736 |
} else { |
9 | 737 |
$delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
$actions['delete'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
'<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
$delete_ays, |
16 | 742 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
esc_attr( sprintf( __( 'Delete “%s” permanently' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
__( 'Delete Permanently' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
); |
0 | 746 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
} |
18 | 748 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
$actions['view'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
750 |
'<a href="%s" aria-label="%s" rel="bookmark">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
751 |
get_permalink( $post->ID ), |
16 | 752 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
__( 'View' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
if ( current_user_can( 'edit_post', $post->ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
$actions['attach'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
'<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>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
$post->ID, |
16 | 761 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
__( 'Attach' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
} |
9 | 766 |
} else { |
767 |
if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
$actions['edit'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
'<a href="%s" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
get_edit_post_link( $post->ID ), |
16 | 771 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
__( 'Edit' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
775 |
} |
18 | 776 |
|
0 | 777 |
if ( current_user_can( 'delete_post', $post->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
if ( $this->is_trash ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
$actions['untrash'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-post_' . $post->ID ), |
16 | 782 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
784 |
__( 'Restore' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
} elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
$actions['trash'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ), |
16 | 790 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
_x( 'Trash', 'verb' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
} |
18 | 795 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) { |
9 | 797 |
$delete_ays = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
$actions['delete'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
'<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
$delete_ays, |
16 | 802 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
esc_attr( sprintf( __( 'Delete “%s” permanently' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
__( 'Delete Permanently' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
); |
0 | 806 |
} |
807 |
} |
|
18 | 808 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
if ( ! $this->is_trash ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
810 |
$actions['view'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
'<a href="%s" aria-label="%s" rel="bookmark">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
812 |
get_permalink( $post->ID ), |
16 | 813 |
/* translators: %s: Attachment title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
814 |
esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
__( 'View' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
); |
19 | 817 |
|
818 |
$actions['copy'] = sprintf( |
|
819 |
'<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>', |
|
820 |
esc_url( wp_get_attachment_url( $post->ID ) ), |
|
821 |
/* translators: %s: Attachment title. */ |
|
822 |
esc_attr( sprintf( __( 'Copy “%s” URL to clipboard' ), $att_title ) ), |
|
823 |
__( 'Copy URL to clipboard' ), |
|
824 |
__( 'Copied!' ) |
|
825 |
); |
|
0 | 826 |
} |
827 |
} |
|
828 |
||
5 | 829 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
* Filters the action links for each attachment in the Media list table. |
5 | 831 |
* |
832 |
* @since 2.8.0 |
|
833 |
* |
|
9 | 834 |
* @param string[] $actions An array of action links for each attachment. |
835 |
* Default 'Edit', 'Delete Permanently', 'View'. |
|
836 |
* @param WP_Post $post WP_Post object for the current attachment. |
|
837 |
* @param bool $detached Whether the list table contains media not attached |
|
838 |
* to any posts. Default true. |
|
5 | 839 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
return apply_filters( 'media_row_actions', $actions, $post, $this->detached ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
} |
0 | 842 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
* Generates and displays row action links. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
* @since 4.3.0 |
19 | 847 |
* @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
* |
19 | 849 |
* @param WP_Post $item Attachment being acted upon. |
18 | 850 |
* @param string $column_name Current column name. |
851 |
* @param string $primary Primary column name. |
|
16 | 852 |
* @return string Row actions output for media attachments, or an empty string |
853 |
* if the current column is not the primary column. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
*/ |
19 | 855 |
protected function handle_row_actions( $item, $column_name, $primary ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
if ( $primary !== $column_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
$att_title = _draft_or_post_title(); |
19 | 861 |
$actions = $this->_get_row_actions( |
862 |
$item, // WP_Post object for an attachment. |
|
863 |
$att_title |
|
864 |
); |
|
16 | 865 |
|
19 | 866 |
return $this->row_actions( $actions ); |
0 | 867 |
} |
868 |
} |