AppsService.php
2 weeks ago
CollaborationCommentService.php
1 month ago
CollaborationService.php
6 days ago
CollectionItemService.php
1 month ago
CollectionService.php
6 days ago
ContentManagerTemplateBinder.php
6 days ago
ContentManagerTemplateService.php
6 days ago
EditorService.php
1 month ago
FontService.php
2 weeks ago
FormSubmissionService.php
6 days ago
GlobalDataService.php
2 weeks ago
MediaService.php
1 month ago
PageService.php
6 days ago
PageSettingsService.php
1 month ago
PostService.php
6 days ago
UtilityPageService.php
6 days ago
PostService.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kirki\App\Services; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | use Kirki\App\Constants\PostTypes; |
| 8 | use Kirki\App\Models\Post as PostModel; |
| 9 | |
| 10 | class PostService |
| 11 | { |
| 12 | public function get_all_posts_grouped_by_type(string $search = '') |
| 13 | { |
| 14 | $post_types = get_post_types(); |
| 15 | $post_types[PostTypes::TEMPLATE] = PostTypes::TEMPLATE; |
| 16 | $post_types[PostTypes::UTILITY] = PostTypes::UTILITY; |
| 17 | $post_types[PostTypes::POPUP] = PostTypes::POPUP; |
| 18 | |
| 19 | $discarded_post_types = ['attachment', 'custom_css', 'customize_changeset', 'wp_global_styles', 'revision', 'nav_menu_item', 'oembed_cache', 'user_request', 'wp_block', 'wp_template', 'wp_template_part', 'wp_navigation']; |
| 20 | |
| 21 | $post_types = array_diff_key($post_types, array_flip($discarded_post_types)); |
| 22 | |
| 23 | $posts = PostModel::filter_post_type($post_types) |
| 24 | ->exclude_trash() |
| 25 | ->search($search) |
| 26 | ->get() |
| 27 | ->group_by(function ($page) { |
| 28 | $group_keys = [PostTypes::TEMPLATE, PostTypes::UTILITY, PostTypes::POPUP]; |
| 29 | |
| 30 | return in_array($page->post_type, $group_keys, true) ? PostTypes::WP_PAGE : $page->post_type; |
| 31 | }); |
| 32 | |
| 33 | return $posts; |
| 34 | } |
| 35 | } |