1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Base\Mixin; |
4
|
|
|
|
5
|
1 |
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Container of all Fetch related methods. |
9
|
|
|
* |
10
|
|
|
* Ideally this should be a Trait. Since Bulk Delete still supports PHP 5.3, this is implemented as a class. |
11
|
|
|
* Once the minimum requirement is increased to PHP 5.3, this will be changed into a Trait. |
12
|
|
|
* |
13
|
|
|
* @since 6.0.0 |
14
|
|
|
*/ |
15
|
|
|
abstract class Fetcher { |
16
|
|
|
/** |
17
|
|
|
* Get the list of public post types registered in WordPress. |
18
|
|
|
* |
19
|
|
|
* @return \WP_Post_Type[] |
20
|
|
|
*/ |
21
|
|
|
protected function get_post_types() { |
22
|
|
|
return bd_get_post_types(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function get_taxonomies() { |
26
|
|
|
return bd_get_taxonomies(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the list of post statuses. |
31
|
|
|
* |
32
|
|
|
* This includes all custom post status, but excludes built-in private posts. |
33
|
|
|
* |
34
|
|
|
* @return array List of post status objects. |
35
|
|
|
*/ |
36
|
|
|
protected function get_post_statuses() { |
37
|
|
|
return bd_get_post_statuses(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the list of post types by post status and count. |
42
|
|
|
* |
43
|
|
|
* @return array Post types by post status. |
44
|
|
|
*/ |
45
|
|
|
protected function get_post_types_by_status() { |
46
|
|
|
$post_types_by_status = array(); |
47
|
|
|
|
48
|
|
|
$post_types = $this->get_post_types(); |
49
|
|
|
$post_statuses = $this->get_post_statuses(); |
50
|
|
|
|
51
|
|
|
foreach ( $post_types as $post_type ) { |
52
|
|
|
$post_type_name = $post_type->name; |
53
|
|
|
$count_posts = wp_count_posts( $post_type_name ); |
54
|
|
|
|
55
|
|
|
foreach ( $post_statuses as $post_status ) { |
56
|
|
|
$post_status_name = $post_status->name; |
57
|
|
|
|
58
|
|
|
if ( ! property_exists( $count_posts, $post_status_name ) ) { |
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ( 0 === $count_posts->{$post_status_name} ) { |
63
|
|
|
continue; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$post_types_by_status[$post_type->labels->singular_name][ "$post_type_name-$post_status_name" ] = $post_status->label . ' (' . $count_posts->{$post_status_name} . ' ' . __( 'Posts', 'bulk-delete' ) . ')'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $post_types_by_status; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the number of users present in a role. |
75
|
|
|
* |
76
|
|
|
* @param string $role Role slug. |
77
|
|
|
* |
78
|
|
|
* @return int Number of users in that role. |
79
|
|
|
*/ |
80
|
|
|
protected function get_user_count_by_role( $role ) { |
81
|
|
|
$users_count = count_users(); |
82
|
|
|
|
83
|
|
|
$roles = $users_count['avail_roles']; |
84
|
|
|
|
85
|
|
|
if ( ! array_key_exists( $role, $roles ) ) { |
86
|
|
|
return 0; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $roles[ $role ]; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|