Skip to content

Commit 857b477

Browse files
authored
Add bbPress support (#23)
1 parent f9e3f5b commit 857b477

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

classes/class-init.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ private function _query_for_ids_to_keep(): void {
213213
*/
214214
private function _get_query_args_instances(): array {
215215
$query_args = [
216+
new Query_Args\bbPress(),
216217
new Query_Args\CoAuthors_Plus(),
217218
new Query_Args\Nav_Menu_Item(),
218219
new Query_Args\OEmbed_Cache(),
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Retain recent bbPress replies, along with their topics and forums.
4+
*
5+
* @package pmc-wp-local-data-cli
6+
*/
7+
8+
declare( strict_types = 1 );
9+
10+
namespace PMC\WP_Local_Data_CLI\Query_Args;
11+
12+
use PMC\WP_Local_Data_CLI\Query_Args;
13+
14+
/**
15+
* Class bbPress.
16+
*/
17+
// phpcs:ignore PEAR.NamingConventions.ValidClassName.StartWithCapital, Squiz.Commenting.ClassComment.Missing
18+
final class bbPress extends Query_Args {
19+
/**
20+
* Backfill is not required as we query from replies and use their meta to
21+
* capture the topic and forum.
22+
*
23+
* @var bool
24+
*/
25+
public static bool $skip_backfill = true;
26+
27+
/**
28+
* Build array of `WP_Query` arguments used to retrieve IDs to retain.
29+
*
30+
* @return array
31+
*/
32+
public static function get_query_args(): array {
33+
// Short-circuit this handler when reply post type is unknown.
34+
if ( ! function_exists( 'bbp_get_reply_post_type' ) ) {
35+
return [
36+
'post_type' => 'abcdef0123456789',
37+
'date_query' => [
38+
[
39+
'after' => '+500 years',
40+
],
41+
],
42+
];
43+
}
44+
45+
return [
46+
'post_type' => bbp_get_reply_post_type(),
47+
'date_query' => [
48+
[
49+
'after' => '-1 months',
50+
],
51+
],
52+
];
53+
}
54+
55+
/**
56+
* Gather reply's parent objects.
57+
*
58+
* @param int $id Post ID.
59+
* @param string $post_type Post type of given ID.
60+
* @return array
61+
*/
62+
// Declaration must be compatible with overridden method.
63+
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed, Squiz.Commenting.FunctionComment.Missing, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
64+
public static function get_linked_ids( int $id, string $post_type ): array {
65+
$ids = [];
66+
67+
$ancestors = array_filter(
68+
[
69+
(int) get_post_meta( $id, '_bbp_topic_id', true ),
70+
(int) get_post_meta( $id, '_bbp_forum_id', true ),
71+
]
72+
);
73+
74+
foreach ( $ancestors as $ancestor ) {
75+
$ids[] = [
76+
'ID' => $ancestor,
77+
'post_type' => get_post_type( $ancestor ),
78+
];
79+
}
80+
81+
return $ids;
82+
}
83+
}

0 commit comments

Comments
 (0)