| 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\Kadence; |
| 13 |
|
| 14 |
use WindPress\WindPress\Core\Scanner\PostQuery; |
| 15 |
use WindPress\WindPress\Core\Scanner\PostRenderer; |
| 16 |
/** |
| 17 |
* @author Joshua Gugun Siagian <suabahasa@gmail.com> |
| 18 |
*/ |
| 19 |
class Compile |
| 20 |
{ |
| 21 |
/** |
| 22 |
* @param array $metadata |
| 23 |
*/ |
| 24 |
public function __invoke($metadata): array |
| 25 |
{ |
| 26 |
if (!defined('KADENCE_VERSION') && !defined('KADENCE_BLOCKS_VERSION')) { |
| 27 |
return []; |
| 28 |
} |
| 29 |
return $this->get_contents($metadata); |
| 30 |
} |
| 31 |
public function get_contents($metadata): array |
| 32 |
{ |
| 33 |
$contents = []; |
| 34 |
$post_types = apply_filters('f!windpress/integration/kadence/compile:get_contents.post_types', ['kadence_form', 'kadence_element']); |
| 35 |
$per_page = apply_filters('f!windpress/integration/kadence/compile:get_contents.post_per_page', PostQuery::batch_size()); |
| 36 |
$scan = new PostQuery(['posts_per_page' => $per_page, 'post_type' => $post_types, 'no_found_rows' => \true, 'update_post_meta_cache' => \false, 'update_post_term_cache' => \false, 'ignore_sticky_posts' => \true], $metadata); |
| 37 |
$wpQuery = $scan->query; |
| 38 |
foreach ($wpQuery->posts as $post) { |
| 39 |
$post_content = $post->post_content; |
| 40 |
$post_content_trimmed = trim($post_content); |
| 41 |
if ($post_content_trimmed === '' || $post_content_trimmed === '0') { |
| 42 |
continue; |
| 43 |
} |
| 44 |
if (apply_filters('f!windpress/integration/kadence/compile:get_contents.render', \false, $post)) { |
| 45 |
$fn_renders = apply_filters('f!windpress/integration/kadence/compile:get_contents.render_fn', [], $post); |
| 46 |
$post_content = PostRenderer::render($post, $fn_renders, 'Kadence', $wpQuery); |
| 47 |
} |
| 48 |
$post_content = apply_filters('f!windpress/integration/kadence/compile:get_contents.post_content', $post_content, $post); |
| 49 |
$contents[] = ['source_id' => 'post:' . $post->ID, 'id' => $post->ID, 'title' => sprintf('#%s: %s', $post->ID, $post->post_title), 'content' => $post_content]; |
| 50 |
} |
| 51 |
return ['metadata' => $scan->metadata(), 'contents' => $contents]; |
| 52 |
} |
| 53 |
} |
| 54 |
|