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 / Incremental / PostLists.php

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

77 lines 2.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\Incremental;
4
5 use FlyWP\StaticSite\Engine\Discovery\HomeSource;
6 use FlyWP\StaticSite\Engine\Discovery\WordPressGateway;
7
8 /**
9 * The list pages that show a post: term archives, and the posts page, author and date archives (type "post")
10 * or the post type archive (other types).
11 *
12 * The change log records these lists before a hard delete. The builder uses the same lists for a post that
13 * still exists. Thus a hard-deleted post and a trashed post rebuild the same lists.
14 *
15 * @since 1.8.0
16 */
17 class PostLists {
18
19 /**
20 * @param WordPressGateway $wp Gateway.
21 * @param array{id:int, post_type:string, author:int, date:string} $post Post.
22 *
23 * @return array<int, array{type:string, id:int|null, url:string|null}>
24 * type: term (id = term ID), blog, user (id = user ID), date (id = year or year * 100 + month), archive.
25 */
26 public static function for_post( WordPressGateway $wp, array $post ) {
27 $lists = [];
28
29 foreach ( $wp->post_terms( $post['id'] ) as $term ) {
30 $lists[] = [
31 'type' => 'term',
32 'id' => $term['id'],
33 'url' => $wp->term_link( $term['id'], $term['taxonomy'] ),
34 ];
35 }
36
37 if ( 'post' !== $post['post_type'] ) {
38 $lists[] = [
39 'type' => 'archive',
40 'id' => null,
41 'url' => $wp->post_type_archive_link( $post['post_type'] ),
42 ];
43
44 return $lists;
45 }
46
47 $lists[] = [
48 'type' => 'blog',
49 'id' => null,
50 'url' => HomeSource::blog_url( $wp ),
51 ];
52 $lists[] = [
53 'type' => 'user',
54 'id' => (int) $post['author'],
55 'url' => $wp->author_link( $post['author'] ),
56 ];
57
58 if ( preg_match( '/^(\d{4})-(\d{2})/', (string) $post['date'], $date ) ) {
59 $year = (int) $date[1];
60 $month = (int) $date[2];
61
62 $lists[] = [
63 'type' => 'date',
64 'id' => $year,
65 'url' => $wp->year_link( $year ),
66 ];
67 $lists[] = [
68 'type' => 'date',
69 'id' => $year * 100 + $month,
70 'url' => $wp->month_link( $year, $month ),
71 ];
72 }
73
74 return $lists;
75 }
76 }
77