1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Users XML sitemap provider. |
---|
5 | * |
---|
6 | * @since 5.5.0 |
---|
7 | */ |
---|
8 | class LH_Buddpress_sitemap_extender_class extends WP_Sitemaps_Provider { |
---|
9 | |
---|
10 | var $the_args = false; |
---|
11 | var $the_total = false; |
---|
12 | |
---|
13 | |
---|
14 | /** |
---|
15 | * LH_Buddpress_sitemap_extender_class constructor. |
---|
16 | * |
---|
17 | * @since 5.5.0 |
---|
18 | */ |
---|
19 | public function __construct() { |
---|
20 | $this->name = 'groups'; |
---|
21 | $this->object_type = 'group'; |
---|
22 | |
---|
23 | //filter to capture args from bp_has_groups |
---|
24 | add_filter( 'bp_after_has_groups_parse_args', array($this,'extract_args'), PHP_INT_MAX,1); |
---|
25 | bp_has_groups(); |
---|
26 | global $groups_template; |
---|
27 | $this->the_total = $groups_template->total_group_count; |
---|
28 | remove_filter( 'bp_after_has_groups_parse_args', array($this,'extract_args')); |
---|
29 | |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | public function extract_args($args){ |
---|
34 | |
---|
35 | $this->the_args = $args; |
---|
36 | |
---|
37 | return $args; |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * Gets a URL list for a user sitemap. |
---|
42 | * |
---|
43 | * @since 5.5.0 |
---|
44 | * |
---|
45 | * @param int $page_num Page of results. |
---|
46 | * @param string $object_subtype Optional. Not applicable for Users but |
---|
47 | * required for compatibility with the parent |
---|
48 | * provider class. Default empty. |
---|
49 | * @return array Array of URLs for a sitemap. |
---|
50 | */ |
---|
51 | public function get_url_list( $page_num, $object_subtype = '' ) { |
---|
52 | /** |
---|
53 | * Filters the users URL list before it is generated. |
---|
54 | * |
---|
55 | * Passing a non-null value will effectively short-circuit the generation, |
---|
56 | * returning that value instead. |
---|
57 | * |
---|
58 | * @since 5.5.0 |
---|
59 | * |
---|
60 | * @param array $url_list The URL list. Default null. |
---|
61 | * @param int $page_num Page of results. |
---|
62 | */ |
---|
63 | $url_list = apply_filters( |
---|
64 | 'wp_sitemaps_users_pre_url_list', |
---|
65 | null, |
---|
66 | $page_num |
---|
67 | ); |
---|
68 | |
---|
69 | if ( null !== $url_list ) { |
---|
70 | return $url_list; |
---|
71 | } |
---|
72 | |
---|
73 | if (!empty($page_num)){ |
---|
74 | |
---|
75 | $args['paged'] = $page_num; |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | if ( bp_has_groups($args) ){ |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | while ( bp_groups() ) : bp_the_group(); |
---|
88 | |
---|
89 | $sitemap_entry = array( |
---|
90 | 'loc' => bp_get_group_permalink( $group ), |
---|
91 | ); |
---|
92 | |
---|
93 | /** |
---|
94 | * Filters the sitemap entry for an individual user. |
---|
95 | * |
---|
96 | * @since 5.5.0 |
---|
97 | * |
---|
98 | * @param array $sitemap_entry Sitemap entry for the user. |
---|
99 | * @param WP_User $user User object. |
---|
100 | */ |
---|
101 | $sitemap_entry = apply_filters( 'bp_groups_sitemap_entry', $sitemap_entry, $group ); |
---|
102 | $url_list[] = $sitemap_entry; |
---|
103 | endwhile; |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | return $url_list; |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * Gets the max number of pages available for the object type. |
---|
112 | * |
---|
113 | * @since 5.5.0 |
---|
114 | * |
---|
115 | * @see WP_Sitemaps_Provider::max_num_pages |
---|
116 | * |
---|
117 | * @param string $object_subtype Optional. Not applicable for Users but |
---|
118 | * required for compatibility with the parent |
---|
119 | * provider class. Default empty. |
---|
120 | * @return int Total page count. |
---|
121 | */ |
---|
122 | public function get_max_num_pages( $object_subtype = '' ) { |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | return (int) ceil( $this->the_total / $this->the_args['per_page']); |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | ?> |
---|