PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.8.0
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.8.0
1.8.0 1.7.1 1.7.0 1.6.0 1.5.2 trunk 0.1 0.2.0 0.2.1 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 1.0 1.1 1.2 1.3.1 1.4.0 1.4.1 1.5.0 All 27 releases
flywp / includes / StaticSite / Engine / Discovery / AuthorSource.php

AuthorSource.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 1.8.0, at includes/StaticSite/Engine/Discovery/AuthorSource.php

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FlyWP\StaticSite\Engine\Discovery;
4
5 /**
6 * Author archives of authors with published posts, with pagination.
7 *
8 * Grouped queries in author ID batches give the authors, their post count and the newest change.
9 *
10 * @since 1.8.0
11 */
12 class AuthorSource implements UrlSource {
13
14 /**
15 * @var WordPressGateway
16 */
17 private $wp;
18
19 /**
20 * @var int
21 */
22 private $batch_size;
23
24 /**
25 * @param WordPressGateway $wp Gateway.
26 * @param int $batch_size Authors in one query.
27 */
28 public function __construct( WordPressGateway $wp, $batch_size = 500 ) {
29 $this->wp = $wp;
30 $this->batch_size = max( 1, (int) $batch_size );
31 }
32
33 /**
34 * {@inheritdoc}
35 */
36 public function urls() {
37 $after_id = 0;
38
39 do {
40 $rows = $this->wp->author_rows( $after_id, $this->batch_size );
41 $full_batch = count( $rows ) === $this->batch_size;
42
43 foreach ( $rows as $row ) {
44 $after_id = $row['id'];
45 $link = $this->wp->author_link( $row['id'] );
46
47 if ( null === $link ) {
48 continue;
49 }
50
51 yield new DiscoveredUrl( $link, 'author', 'user', $row['id'], $row['modified_gmt'] );
52 yield from Pagination::urls( $this->wp, $link, $row['count'] );
53 }
54 } while ( $full_batch );
55 }
56 }
57