Skip to content

Commit a272a09

Browse files
committed
✨ Feat(chat/admin): filter selectable post types for assistant pages
1 parent fd42b85 commit a272a09

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

library/Chat/ChatFeature.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
declare(strict_types=1);
44

5-
65
namespace Municipio\Chat;
76

87
use AcfService\Contracts\AddOptionsPage;
@@ -36,6 +35,8 @@ public function enable(): void
3635

3736
(new ChatAdminPage($this->wpService, $this->acfService))->addHooks();
3837

38+
$this->wpService->addFilter('acf/fields/post_object/query/name=pages', [$this, 'filterPostObjectField'], 10, 3);
39+
3940
if (!$config->isEnabled()) {
4041
return;
4142
}
@@ -55,4 +56,15 @@ public function enable(): void
5556

5657
(new ChatStatsMetaBox($this->wpService, $bladeRenderer))->addHooks();
5758
}
59+
60+
public function filterPostObjectField($args, $field, $postId)
61+
{
62+
$wpService = $this->wpService;
63+
$args['post_type'] = array_filter($args['post_type'] ?? [], static function ($postType) use ($wpService) {
64+
$postObj = $wpService->getPostTypeObject($postType);
65+
return $postObj && $wpService->isPostTypeHierarchical($postType) && $wpService->isPostTypeViewable($postObj);
66+
});
67+
68+
return $args;
69+
}
5870
}

0 commit comments

Comments
 (0)