User.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\ListScreen; |
| 4 | |
| 5 | use AC; |
| 6 | use WP_Users_List_Table; |
| 7 | |
| 8 | class User extends AC\ListScreenWP { |
| 9 | |
| 10 | public function __construct() { |
| 11 | |
| 12 | $this->set_label( __( 'Users' ) ) |
| 13 | ->set_singular_label( __( 'User' ) ) |
| 14 | ->set_meta_type( AC\MetaType::USER ) |
| 15 | ->set_screen_base( 'users' ) |
| 16 | ->set_screen_id( 'users' ) |
| 17 | ->set_key( 'wp-users' ) |
| 18 | ->set_group( 'user' ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @see set_manage_value_callback() |
| 23 | */ |
| 24 | public function set_manage_value_callback() { |
| 25 | add_filter( 'manage_users_custom_column', array( $this, 'manage_value' ), 100, 3 ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @return WP_Users_List_Table |
| 30 | */ |
| 31 | public function get_list_table() { |
| 32 | require_once( ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php' ); |
| 33 | |
| 34 | return new WP_Users_List_Table( array( 'screen' => $this->get_screen_id() ) ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @since 2.4.10 |
| 39 | * |
| 40 | * @param $wp_screen |
| 41 | * |
| 42 | * @return bool |
| 43 | */ |
| 44 | public function is_current_screen( $wp_screen ) { |
| 45 | return parent::is_current_screen( $wp_screen ) && 'delete' !== filter_input( INPUT_GET, 'action' ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @since 2.0.2 |
| 50 | * |
| 51 | * @param string $value |
| 52 | * @param string $column_name |
| 53 | * @param int $user_id |
| 54 | * |
| 55 | * @return string |
| 56 | */ |
| 57 | public function manage_value( $value, $column_name, $user_id ) { |
| 58 | return $this->get_display_value_by_column_name( $column_name, $user_id, $value ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @param int $id |
| 63 | * |
| 64 | * @return \WP_User |
| 65 | */ |
| 66 | protected function get_object( $id ) { |
| 67 | return get_userdata( $id ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @since 3.0 |
| 72 | * |
| 73 | * @param int $id |
| 74 | * |
| 75 | * @return string HTML |
| 76 | */ |
| 77 | public function get_single_row( $id ) { |
| 78 | return $this->get_list_table()->single_row( $this->get_object( $id ) ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @throws \ReflectionException |
| 83 | */ |
| 84 | protected function register_column_types() { |
| 85 | $this->register_column_type( new AC\Column\CustomField ); |
| 86 | $this->register_column_type( new AC\Column\Actions ); |
| 87 | |
| 88 | $this->register_column_types_from_dir( 'AC\Column\User' ); |
| 89 | } |
| 90 | |
| 91 | } |