PluginProbe
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.3.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.3.0
6.3.0 6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 All 56 releases
kirki / app / Services / PostService.php
PostService.php
35 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }