1 | <?php |
---|
2 | |
---|
3 | namespace AC\ListScreen; |
---|
4 | |
---|
5 | use AC; |
---|
6 | use ReflectionException; |
---|
7 | use WP_Media_List_Table; |
---|
8 | |
---|
9 | class Media extends AC\ListScreenPost { |
---|
10 | |
---|
11 | public function __construct() { |
---|
12 | parent::__construct( 'attachment' ); |
---|
13 | |
---|
14 | $this->set_screen_id( 'upload' ) |
---|
15 | ->set_screen_base( 'upload' ) |
---|
16 | ->set_key( 'wp-media' ) |
---|
17 | ->set_group( 'media' ) |
---|
18 | ->set_label( __( 'Media' ) ); |
---|
19 | } |
---|
20 | |
---|
21 | public function set_manage_value_callback() { |
---|
22 | add_action( 'manage_media_custom_column', [ $this, 'manage_value' ], 100, 2 ); |
---|
23 | } |
---|
24 | |
---|
25 | /** |
---|
26 | * @return WP_Media_List_Table |
---|
27 | */ |
---|
28 | public function get_list_table() { |
---|
29 | require_once( ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php' ); |
---|
30 | |
---|
31 | return new WP_Media_List_Table( [ 'screen' => $this->get_screen_id() ] ); |
---|
32 | } |
---|
33 | |
---|
34 | public function get_screen_link() { |
---|
35 | return add_query_arg( 'mode', 'list', parent::get_screen_link() ); |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * @param int $id |
---|
40 | * |
---|
41 | * @return string |
---|
42 | */ |
---|
43 | public function get_single_row( $id ) { |
---|
44 | // Author column depends on this global to be set. |
---|
45 | global $authordata; |
---|
46 | |
---|
47 | $authordata = get_userdata( get_post_field( 'post_author', $id ) ); |
---|
48 | |
---|
49 | return parent::get_single_row( $id ); |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * @param $column_name |
---|
54 | * @param $id |
---|
55 | * |
---|
56 | * @since 2.4.7 |
---|
57 | */ |
---|
58 | public function manage_value( $column_name, $id ) { |
---|
59 | echo $this->get_display_value_by_column_name( $column_name, $id ); |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * @throws ReflectionException |
---|
64 | */ |
---|
65 | protected function register_column_types() { |
---|
66 | parent::register_column_types(); |
---|
67 | |
---|
68 | $this->register_column_types_from_dir( 'AC\Column\Media' ); |
---|
69 | } |
---|
70 | |
---|
71 | } |
---|