| @@ -4,11 +4,8 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package WPSEO\XML_Sitemaps |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -use Yoast\WP\SEO\Helpers\Author_Archive_Helper; | |
| 9 | -use Yoast\WP\SEO\Helpers\Wordpress_Helper; | |
| 10 | - | |
| 11 | 8 | /** |
| 12 | 9 | * Sitemap provider for author archives. |
| 13 | 10 | */ |
| 14 | 11 | class WPSEO_Author_Sitemap_Provider implements WPSEO_Sitemap_Provider { |
| @@ -90,53 +87,51 @@ | ||
| 90 | 87 | * @return array |
| 91 | 88 | */ |
| 92 | 89 | protected function get_users( $arguments = [] ) { |
| 93 | 90 | |
| 94 | - global $wpdb; | |
| 95 | - | |
| 96 | 91 | $defaults = [ |
| 97 | - 'capability' => [ 'edit_posts' ], | |
| 98 | 92 | 'meta_key' => '_yoast_wpseo_profile_updated', |
| 99 | 93 | 'orderby' => 'meta_value_num', |
| 100 | 94 | 'order' => 'DESC', |
| 101 | 95 | 'meta_query' => [ |
| 102 | - 'relation' => 'AND', | |
| 96 | + 'relation' => 'OR', | |
| 103 | 97 | [ |
| 104 | - 'key' => $wpdb->get_blog_prefix() . 'user_level', | |
| 105 | - 'value' => '0', | |
| 98 | + 'key' => 'wpseo_noindex_author', | |
| 99 | + 'value' => 'on', | |
| 106 | 100 | 'compare' => '!=', |
| 107 | 101 | ], |
| 108 | 102 | [ |
| 109 | - 'relation' => 'OR', | |
| 110 | - [ | |
| 111 | - 'key' => 'wpseo_noindex_author', | |
| 112 | - 'value' => 'on', | |
| 113 | - 'compare' => '!=', | |
| 114 | - ], | |
| 115 | - [ | |
| 116 | - 'key' => 'wpseo_noindex_author', | |
| 117 | - 'compare' => 'NOT EXISTS', | |
| 118 | - ], | |
| 103 | + 'key' => 'wpseo_noindex_author', | |
| 104 | + 'compare' => 'NOT EXISTS', | |
| 119 | 105 | ], |
| 120 | 106 | ], |
| 121 | 107 | ]; |
| 122 | 108 | |
| 123 | - $wordpress_helper = new Wordpress_Helper(); | |
| 124 | - $wordpress_version = $wordpress_helper->get_wordpress_version(); | |
| 109 | + $defaults = $this->apply_author_eligibility_filter( $defaults ); | |
| 125 | 110 | |
| 126 | - // Capability queries were only introduced in WP 5.9. | |
| 127 | - if ( version_compare( $wordpress_version, '5.8.99', '<' ) ) { | |
| 128 | - $defaults['who'] = 'authors'; | |
| 129 | - unset( $defaults['capability'] ); | |
| 130 | - } | |
| 111 | + return get_users( array_merge( $defaults, $arguments ) ); | |
| 112 | + } | |
| 131 | 113 | |
| 114 | + /** | |
| 115 | + * Applies the author-eligibility clause (capability or has_published_posts) to a get_users() criteria array. | |
| 116 | + * | |
| 117 | + * Centralises the `noindex-author-noposts-wpseo` branching so the sitemap query and its | |
| 118 | + * backfill counterpart always agree on which users are considered eligible. | |
| 119 | + * | |
| 120 | + * @param array<string, array<array<string, string>>> $criteria The get_users() criteria array to extend. | |
| 121 | + * | |
| 122 | + * @return array<string, array<array<string, string>>> The criteria array with the eligibility clause applied. | |
| 123 | + */ | |
| 124 | + protected function apply_author_eligibility_filter( array $criteria ) { | |
| 132 | 125 | if ( WPSEO_Options::get( 'noindex-author-noposts-wpseo', true ) ) { |
| 133 | - unset( $defaults['who'], $defaults['capability'] ); // Otherwise it cancels out next argument. | |
| 134 | - $author_archive = new Author_Archive_Helper(); | |
| 135 | - $defaults['has_published_posts'] = $author_archive->get_author_archive_post_types(); | |
| 126 | + $criteria['has_published_posts'] = YoastSEO()->helpers->author_archive->get_author_archive_post_types(); | |
| 127 | + | |
| 128 | + return $criteria; | |
| 136 | 129 | } |
| 137 | 130 | |
| 138 | - return get_users( array_merge( $defaults, $arguments ) ); | |
| 131 | + $criteria['capability'] = [ 'edit_posts' ]; | |
| 132 | + | |
| 133 | + return $criteria; | |
| 139 | 134 | } |
| 140 | 135 | |
| 141 | 136 | /** |
| 142 | 137 | * Get set of sitemap link data. |
| @@ -217,9 +212,8 @@ | ||
| 217 | 212 | */ |
| 218 | 213 | protected function update_user_meta() { |
| 219 | 214 | |
| 220 | 215 | $user_criteria = [ |
| 221 | - 'capability' => [ 'edit_posts' ], | |
| 222 | 216 | 'meta_query' => [ |
| 223 | 217 | [ |
| 224 | 218 | 'key' => '_yoast_wpseo_profile_updated', |
| 225 | 219 | 'compare' => 'NOT EXISTS', |
| @@ -226,16 +220,9 @@ | ||
| 226 | 220 | ], |
| 227 | 221 | ], |
| 228 | 222 | ]; |
| 229 | 223 | |
| 230 | - $wordpress_helper = new Wordpress_Helper(); | |
| 231 | - $wordpress_version = $wordpress_helper->get_wordpress_version(); | |
| 232 | - | |
| 233 | - // Capability queries were only introduced in WP 5.9. | |
| 234 | - if ( version_compare( $wordpress_version, '5.8.99', '<' ) ) { | |
| 235 | - $user_criteria['who'] = 'authors'; | |
| 236 | - unset( $user_criteria['capability'] ); | |
| 237 | - } | |
| 224 | + $user_criteria = $this->apply_author_eligibility_filter( $user_criteria ); | |
| 238 | 225 | |
| 239 | 226 | $users = get_users( $user_criteria ); |
| 240 | 227 | |
| 241 | 228 | $time = time(); |