Comment.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\ListScreen; |
| 4 | |
| 5 | use AC; |
| 6 | use AC\WpListTableFactory; |
| 7 | use ReflectionException; |
| 8 | use WP_Comment; |
| 9 | use WP_Comments_List_Table; |
| 10 | |
| 11 | class Comment extends AC\ListScreenWP { |
| 12 | |
| 13 | public function __construct() { |
| 14 | |
| 15 | $this->set_label( __( 'Comments' ) ) |
| 16 | ->set_singular_label( __( 'Comment' ) ) |
| 17 | ->set_meta_type( 'comment' ) |
| 18 | ->set_screen_base( 'edit-comments' ) |
| 19 | ->set_key( 'wp-comments' ) |
| 20 | ->set_screen_id( 'edit-comments' ) |
| 21 | ->set_group( 'comment' ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @param int $id |
| 26 | * |
| 27 | * @return WP_Comment |
| 28 | */ |
| 29 | protected function get_object( $id ) { |
| 30 | return get_comment( $id ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @return WP_Comments_List_Table |
| 35 | */ |
| 36 | protected function get_list_table() { |
| 37 | return ( new WpListTableFactory() )->create_comment_table( $this->get_screen_id() ); |
| 38 | } |
| 39 | |
| 40 | public function set_manage_value_callback() { |
| 41 | add_action( 'manage_comments_custom_column', [ $this, 'manage_value' ], 100, 2 ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @since 3.5 |
| 46 | */ |
| 47 | public function get_table_attr_id() { |
| 48 | return '#the-comment-list'; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param string $column_name |
| 53 | * @param int $id |
| 54 | */ |
| 55 | public function manage_value( $column_name, $id ) { |
| 56 | echo $this->get_display_value_by_column_name( $column_name, $id ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Register column types |
| 61 | * @throws ReflectionException |
| 62 | */ |
| 63 | protected function register_column_types() { |
| 64 | $this->register_column_type( new AC\Column\CustomField ); |
| 65 | $this->register_column_type( new AC\Column\Actions ); |
| 66 | $this->register_column_types_from_dir( 'AC\Column\Comment' ); |
| 67 | } |
| 68 | |
| 69 | } |