| 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 |
public function __invoke() : array |
| 23 |
{ |
| 24 |
if (!\defined('ELEMENTOR_VERSION')) { |
| 25 |
return []; |
| 26 |
} |
| 27 |
return $this->get_contents(); |
| 28 |
} |
| 29 |
public function get_contents() : array |
| 30 |
{ |
| 31 |
$contents = []; |
| 32 |
$post_types = \get_option('elementor_cpt_support', Plugin::ELEMENTOR_DEFAULT_POST_TYPES); |
| 33 |
$post_types = \apply_filters('f!windpress/integration/elementor/compile:get_contents.post_types', $post_types); |
| 34 |
$wpQuery = new WP_Query([ |
| 35 |
'posts_per_page' => -1, |
| 36 |
'fields' => 'ids', |
| 37 |
'post_type' => $post_types, |
| 38 |
'post_status' => \get_post_stati(), |
| 39 |
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- This only run by trigger on specific event |
| 40 |
'meta_query' => \array_merge(['relation' => 'OR'], \array_map(static fn($key) => ['key' => $key], $this->post_meta_keys)), |
| 41 |
]); |
| 42 |
foreach ($wpQuery->posts as $post_id) { |
| 43 |
$contents = [...$contents, ...$this->get_post_metas($post_id)]; |
| 44 |
} |
| 45 |
return $contents; |
| 46 |
} |
| 47 |
public function get_post_metas($post_id) : array |
| 48 |
{ |
| 49 |
$contents = []; |
| 50 |
foreach ($this->post_meta_keys as $post_metum_key) { |
| 51 |
$meta_value = \get_post_meta($post_id, $post_metum_key, \true); |
| 52 |
if ($meta_value) { |
| 53 |
$contents[] = ['name' => $post_id, 'content' => $meta_value]; |
| 54 |
} |
| 55 |
} |
| 56 |
return $contents; |
| 57 |
} |
| 58 |
} |
| 59 |
|