User.php
1.25 KB
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
<?php
namespace ACP\Export\Strategy;
use AC;
use ACP\Export\Strategy;
use WP_User_Query;
/**
* Exportability class for users list screen
* @property AC\ListScreen\User $list_screen
*/
class User extends Strategy {
public function __construct( AC\ListScreen\User $list_screen ) {
parent::__construct( $list_screen );
}
protected function ajax_export(): void {
add_filter( 'users_list_table_query_args', [ $this, 'catch_users_query' ], PHP_INT_MAX - 100 );
}
/**
* Modify the users query to use the correct pagination arguments, and epxort the resulting
* items. This should be attached to the users_list_table_query_args hook when an AJAX request
* is sent
*
* @param $args
*
* @see filter:users_list_table_query_args
* @since 1.0
*/
public function catch_users_query( $args ): void {
$per_page = $this->get_num_items_per_iteration();
$args['offset'] = $this->get_export_counter() * $per_page;
$args['number'] = $per_page;
$args['fields'] = 'ids';
$ids = $this->get_requested_ids();
if ( $ids ) {
$args['include'] = isset( $args['include'] ) && is_array( $args['include'] )
? array_merge( $ids, $args['include'] )
: $ids;
}
$query = new WP_User_Query( $args );
$this->export( $query->get_results() );
}
}