-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathPrimaryColumn.php
67 lines (51 loc) · 2.01 KB
/
PrimaryColumn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace AC\Table;
use AC\ListScreen;
use WP_Post;
class PrimaryColumn {
private $list_screen;
public function __construct( ListScreen $list_screen ) {
$this->list_screen = $list_screen;
}
public function set_primary_column( string $default ): string {
if ( ! $this->list_screen->get_column_by_name( $default ) ) {
$default = (string) key( $this->list_screen->get_columns() );
}
// If actions column is present, set it as primary
foreach ( $this->list_screen->get_columns() as $column ) {
if ( 'column-actions' === $column->get_type() ) {
$default = $column->get_name();
if ( $this->list_screen instanceof ListScreen\Media ) {
// Add download button to the actions column
add_filter( 'media_row_actions', [ $this, 'set_media_download_row_action' ], 10, 2 );
}
}
}
// Set inline edit data if the default column (title) is not present
if ( $this->list_screen instanceof ListScreen\Post && 'title' !== $default ) {
add_filter( 'page_row_actions', [ $this, 'set_inline_edit_data' ], 20, 2 );
add_filter( 'post_row_actions', [ $this, 'set_inline_edit_data' ], 20, 2 );
}
// Remove inline edit action if the default column (author) is not present
if ( $this->list_screen instanceof ListScreen\Comment && 'comment' !== $default ) {
add_filter( 'comment_row_actions', [ $this, 'remove_quick_edit_from_actions' ], 20, 2 );
}
return $default;
}
public function set_media_download_row_action( array $actions, WP_Post $post ): array {
$link_attributes = [
'download' => '',
'title' => __( 'Download', 'codepress-admin-columns' ),
];
$actions['download'] = ac_helper()->html->link( wp_get_attachment_url( $post->ID ), __( 'Download', 'codepress-admin-columns' ), $link_attributes );
return $actions;
}
public function set_inline_edit_data( array $actions, WP_Post $post ) {
get_inline_data( $post );
return $actions;
}
public function remove_quick_edit_from_actions( array $actions ): array {
unset( $actions['quickedit'] );
return $actions;
}
}