PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.84
WindPress – Tailwind CSS integration for WordPress v3.2.84
3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 All 142 releases
windpress / src / Integration / Elementor / Compile.php

Compile.php in WindPress – Tailwind CSS integration for WordPress 3.2.84, at src/Integration/Elementor/Compile.php

76 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the WindPress package.
5 *
6 * (c) Joshua Gugun Siagian <suabahasa@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 declare (strict_types=1);
12 namespace WindPress\WindPress\Integration\Elementor;
13
14 use Elementor\Plugin;
15 use WP_Query;
16 /**
17 * @author Joshua Gugun Siagian <suabahasa@gmail.com>
18 */
19 class Compile
20 {
21 private array $post_meta_keys = ['_elementor_data'];
22 /**
23 * @param array $metadata
24 */
25 public function __invoke($metadata): array
26 {
27 if (!defined('ELEMENTOR_VERSION')) {
28 return [];
29 }
30 return $this->get_contents($metadata);
31 }
32 public function get_contents($metadata): array
33 {
34 $contents = [];
35 $post_types = get_option('elementor_cpt_support', Plugin::ELEMENTOR_DEFAULT_POST_TYPES);
36 $post_types = apply_filters('f!windpress/integration/elementor/compile:get_contents.post_types', $post_types);
37 $next_batch = $metadata['next_batch'] !== \false ? $metadata['next_batch'] : 1;
38 $per_page = apply_filters('f!windpress/integration/elementor/compile:get_contents.post_per_page', (int) get_option('posts_per_page', 20));
39 $wpQuery = new WP_Query([
40 'posts_per_page' => $per_page,
41 'paged' => $next_batch,
42 'fields' => 'ids',
43 'post_type' => $post_types,
44 'post_status' => get_post_stati(),
45 'no_found_rows' => \true,
46 'update_post_meta_cache' => \false,
47 'update_post_term_cache' => \false,
48 'ignore_sticky_posts' => \true,
49 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- This only run by trigger on specific event
50 'meta_query' => array_merge(['relation' => 'OR'], array_map(static fn($key) => ['key' => $key], $this->post_meta_keys)),
51 ]);
52 if ($wpQuery->posts !== []) {
53 update_meta_cache('post', $wpQuery->posts);
54 }
55 foreach ($wpQuery->posts as $post_id) {
56 foreach ($this->get_post_metas($post_id) as $content) {
57 $contents[] = $content;
58 }
59 }
60 $post_count = count($wpQuery->posts);
61 $has_more = $per_page > 0 && $post_count === $per_page;
62 return ['metadata' => ['next_batch' => $has_more ? $next_batch + 1 : \false, 'total_batches' => \false], 'contents' => $contents];
63 }
64 public function get_post_metas($post_id): array
65 {
66 $contents = [];
67 foreach ($this->post_meta_keys as $post_metum_key) {
68 $meta_value = get_post_meta($post_id, $post_metum_key, \true);
69 if ($meta_value) {
70 $contents[] = ['name' => $post_id, 'content' => $meta_value, 'type' => 'json'];
71 }
72 }
73 return $contents;
74 }
75 }
76