• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 99ff5821fbe8444b259463501ff00132570d3061

25 Mar 2025 09:23AM UTC coverage: 52.446% (+3.7%) from 48.71%
99ff5821fbe8444b259463501ff00132570d3061

Pull #21958

github

web-flow
Merge d493347a3 into facbdded4
Pull Request #21958: Improve function words list for Farsi

7990 of 14101 branches covered (56.66%)

Branch coverage included in aggregate %.

20 of 20 new or added lines in 1 file covered. (100.0%)

1567 existing lines in 41 files now uncovered.

29816 of 57984 relevant lines covered (51.42%)

41124.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.36
/inc/sitemaps/class-author-sitemap-provider.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\XML_Sitemaps
6
 */
7

8
/**
9
 * Sitemap provider for author archives.
10
 */
11
class WPSEO_Author_Sitemap_Provider implements WPSEO_Sitemap_Provider {
12

13
        /**
14
         * Check if provider supports given item type.
15
         *
16
         * @param string $type Type string to check for.
17
         *
18
         * @return bool
19
         */
20
        public function handles_type( $type ) {
×
21
                // If the author archives have been disabled, we don't do anything.
22
                if ( WPSEO_Options::get( 'disable-author', false ) || WPSEO_Options::get( 'noindex-author-wpseo', false ) ) {
×
23
                        return false;
×
24
                }
25

26
                return $type === 'author';
×
27
        }
28

29
        /**
30
         * Get the links for the sitemap index.
31
         *
32
         * @param int $max_entries Entries per sitemap.
33
         *
34
         * @return array
35
         */
36
        public function get_index_links( $max_entries ) {
×
37

38
                if ( ! $this->handles_type( 'author' ) ) {
×
39
                        return [];
×
40
                }
41

42
                // @todo Consider doing this less often / when necessary. R.
43
                $this->update_user_meta();
×
44

45
                $has_exclude_filter = has_filter( 'wpseo_sitemap_exclude_author' );
×
46

47
                $query_arguments = [];
×
48

49
                if ( ! $has_exclude_filter ) { // We only need full users if legacy filter(s) hooked to exclusion logic. R.
×
50
                        $query_arguments['fields'] = 'ID';
×
51
                }
52

53
                $users = $this->get_users( $query_arguments );
×
54

55
                if ( $has_exclude_filter ) {
×
56
                        $users = $this->exclude_users( $users );
×
57
                        $users = wp_list_pluck( $users, 'ID' );
×
58
                }
59

60
                if ( empty( $users ) ) {
×
61
                        return [];
×
62
                }
63

64
                $index      = [];
×
65
                $user_pages = array_chunk( $users, $max_entries );
×
66

67
                foreach ( $user_pages as $page_counter => $users_page ) {
×
68

69
                        $current_page = ( $page_counter === 0 ) ? '' : ( $page_counter + 1 );
×
70

71
                        $user_id = array_shift( $users_page ); // Time descending, first user on page is most recently updated.
×
72
                        $user    = get_user_by( 'id', $user_id );
×
73
                        $index[] = [
×
74
                                'loc'     => WPSEO_Sitemaps_Router::get_base_url( 'author-sitemap' . $current_page . '.xml' ),
×
75
                                'lastmod' => ( $user->_yoast_wpseo_profile_updated ) ? YoastSEO()->helpers->date->format_timestamp( $user->_yoast_wpseo_profile_updated ) : null,
×
UNCOV
76
                        ];
×
77
                }
78

79
                return $index;
×
80
        }
81

82
        /**
83
         * Retrieve users, taking account of all necessary exclusions.
84
         *
85
         * @param array $arguments Arguments to add.
86
         *
87
         * @return array
88
         */
89
        protected function get_users( $arguments = [] ) {
×
90

91
                global $wpdb;
×
92

UNCOV
93
                $defaults = [
×
94
                        'capability' => [ 'edit_posts' ],
×
95
                        'meta_key'   => '_yoast_wpseo_profile_updated',
×
96
                        'orderby'    => 'meta_value_num',
×
97
                        'order'      => 'DESC',
×
UNCOV
98
                        'meta_query' => [
×
99
                                'relation' => 'AND',
×
UNCOV
100
                                [
×
101
                                        'key'     => $wpdb->get_blog_prefix() . 'user_level',
×
102
                                        'value'   => '0',
×
103
                                        'compare' => '!=',
×
UNCOV
104
                                ],
×
UNCOV
105
                                [
×
UNCOV
106
                                        'relation' => 'OR',
×
UNCOV
107
                                        [
×
UNCOV
108
                                                'key'     => 'wpseo_noindex_author',
×
UNCOV
109
                                                'value'   => 'on',
×
UNCOV
110
                                                'compare' => '!=',
×
UNCOV
111
                                        ],
×
UNCOV
112
                                        [
×
UNCOV
113
                                                'key'     => 'wpseo_noindex_author',
×
UNCOV
114
                                                'compare' => 'NOT EXISTS',
×
UNCOV
115
                                        ],
×
UNCOV
116
                                ],
×
UNCOV
117
                        ],
×
UNCOV
118
                ];
×
119

120
                if ( WPSEO_Options::get( 'noindex-author-noposts-wpseo', true ) ) {
×
121
                        unset( $defaults['capability'] ); // Otherwise it cancels out next argument.
×
122
                        $defaults['has_published_posts'] = YoastSEO()->helpers->author_archive->get_author_archive_post_types();
×
123
                }
124

125
                return get_users( array_merge( $defaults, $arguments ) );
×
126
        }
127

128
        /**
129
         * Get set of sitemap link data.
130
         *
131
         * @param string $type         Sitemap type.
132
         * @param int    $max_entries  Entries per sitemap.
133
         * @param int    $current_page Current page of the sitemap.
134
         *
135
         * @return array
136
         *
137
         * @throws OutOfBoundsException When an invalid page is requested.
138
         */
139
        public function get_sitemap_links( $type, $max_entries, $current_page ) {
12✔
140

141
                $links = [];
12✔
142

143
                if ( ! $this->handles_type( 'author' ) ) {
12✔
144
                        return $links;
×
145
                }
146

147
                $user_criteria = [
12✔
148
                        'offset' => ( ( $current_page - 1 ) * $max_entries ),
12✔
149
                        'number' => $max_entries,
12✔
150
                ];
12✔
151

152
                $users = $this->get_users( $user_criteria );
12✔
153

154
                // Throw an exception when there are no users in the sitemap.
155
                if ( count( $users ) === 0 ) {
12✔
156
                        throw new OutOfBoundsException( 'Invalid sitemap page requested' );
6✔
157
                }
158

159
                $users = $this->exclude_users( $users );
6✔
160
                if ( empty( $users ) ) {
6✔
161
                        $users = [];
×
162
                }
163

164
                $time = time();
6✔
165

166
                foreach ( $users as $user ) {
6✔
167

168
                        $author_link = get_author_posts_url( $user->ID );
6✔
169

170
                        if ( empty( $author_link ) ) {
6✔
171
                                continue;
×
172
                        }
173

174
                        $mod = $time;
6✔
175

176
                        if ( isset( $user->_yoast_wpseo_profile_updated ) ) {
6✔
177
                                $mod = $user->_yoast_wpseo_profile_updated;
6✔
178
                        }
179

180
                        $url = [
6✔
181
                                'loc' => $author_link,
6✔
182
                                'mod' => date( DATE_W3C, $mod ),
6✔
183

184
                                // Deprecated, kept for backwards data compat. R.
185
                                'chf' => 'daily',
6✔
186
                                'pri' => 1,
6✔
187
                        ];
6✔
188

189
                        /** This filter is documented at inc/sitemaps/class-post-type-sitemap-provider.php */
190
                        $url = apply_filters( 'wpseo_sitemap_entry', $url, 'user', $user );
6✔
191

192
                        if ( ! empty( $url ) ) {
6✔
193
                                $links[] = $url;
6✔
194
                        }
195
                }
196

197
                return $links;
6✔
198
        }
199

200
        /**
201
         * Update any users that don't have last profile update timestamp.
202
         *
203
         * @return int Count of users updated.
204
         */
205
        protected function update_user_meta() {
×
206

UNCOV
207
                $user_criteria = [
×
208
                        'capability' => [ 'edit_posts' ],
×
UNCOV
209
                        'meta_query' => [
×
UNCOV
210
                                [
×
UNCOV
211
                                        'key'     => '_yoast_wpseo_profile_updated',
×
UNCOV
212
                                        'compare' => 'NOT EXISTS',
×
UNCOV
213
                                ],
×
UNCOV
214
                        ],
×
UNCOV
215
                ];
×
216

217
                $users = get_users( $user_criteria );
×
218

219
                $time = time();
×
220

221
                foreach ( $users as $user ) {
×
222
                        update_user_meta( $user->ID, '_yoast_wpseo_profile_updated', $time );
×
223
                }
224

225
                return count( $users );
×
226
        }
227

228
        /**
229
         * Wrap legacy filter to deduplicate calls.
230
         *
231
         * @param array $users Array of user objects to filter.
232
         *
233
         * @return array
234
         */
235
        protected function exclude_users( $users ) {
×
236

237
                /**
238
                 * Filter the authors, included in XML sitemap.
239
                 *
240
                 * @param array $users Array of user objects to filter.
241
                 */
242
                return apply_filters( 'wpseo_sitemap_exclude_author', $users );
×
243
        }
244
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc