PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.89
WindPress – Tailwind CSS integration for WordPress v3.2.89
3.2.89 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 All 143 releases
windpress / src / Integration / Elementor / Compile.php

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

73 lines 2.6 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 WindPress\WindPress\Core\Scanner\PostQuery;
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 $per_page = apply_filters('f!windpress/integration/elementor/compile:get_contents.post_per_page', PostQuery::batch_size());
38 $scan = new PostQuery([
39 'posts_per_page' => $per_page,
40 'fields' => 'ids',
41 'post_type' => $post_types,
42 'post_status' => get_post_stati(),
43 'no_found_rows' => \true,
44 'update_post_meta_cache' => \false,
45 'update_post_term_cache' => \false,
46 'ignore_sticky_posts' => \true,
47 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- This only run by trigger on specific event
48 'meta_query' => array_merge(['relation' => 'OR'], array_map(static fn($key) => ['key' => $key], $this->post_meta_keys)),
49 ], $metadata);
50 $wpQuery = $scan->query;
51 if ($wpQuery->posts !== []) {
52 update_meta_cache('post', $wpQuery->posts);
53 }
54 foreach ($wpQuery->posts as $post_id) {
55 foreach ($this->get_post_metas($post_id) as $content) {
56 $contents[] = $content;
57 }
58 }
59 return ['metadata' => $scan->metadata(), 'contents' => $contents];
60 }
61 public function get_post_metas($post_id): array
62 {
63 $contents = [];
64 foreach ($this->post_meta_keys as $post_metum_key) {
65 $meta_value = get_post_meta($post_id, $post_metum_key, \true);
66 if ($meta_value) {
67 $contents[] = ['source_id' => 'post:' . $post_id . ':meta:' . $post_metum_key, 'name' => $post_id, 'content' => $meta_value, 'type' => 'json'];
68 }
69 }
70 return $contents;
71 }
72 }
73