PluginProbe
MarqueeX – Smooth Marquee Slider, News Ticker & Post Marquee for Block Editor & Elementor / 0.6.0
MarqueeX – Smooth Marquee Slider, News Ticker & Post Marquee for Block Editor & Elementor v0.6.0
0.6.0 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.0 0.3.3 0.3.2 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.1.0 0.1.1 0.1.2 0.2.0 0.2.1 0.2.2 0.2.3 0.3.0 0.3.1
marqueex / includes / Integrations / Gutenberg / Render / PostSource.php

PostSource.php in MarqueeX – Smooth Marquee Slider, News Ticker & Post Marquee for Block Editor & Elementor 0.6.0, at includes/Integrations/Gutenberg/Render/PostSource.php

63 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Wpxero\Marqueex\Integrations\Gutenberg\Render;
4
5 use Wpxero\Marqueex\Traits\MarqueeSource;
6 use Wpxero\Marqueex\Traits\Singleton;
7
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 /**
13 * Post-source helper for dynamic MarqueeX Gutenberg blocks.
14 *
15 * Wraps the shared {@see MarqueeSource} trait (the same query/duplication/url
16 * logic the Elementor widgets use) and exposes a small, Elementor-free surface
17 * the block `render.php` files can call. Keeping this in the Gutenberg namespace
18 * means the dynamic blocks never depend on Elementor being installed.
19 */
20 class PostSource {
21 use Singleton;
22 use MarqueeSource;
23
24 /**
25 * Run the marquee post query for a block's `query` attribute and return a
26 * list padded to the minimum needed for a seamless loop.
27 *
28 * @param array $query Block `query` attribute (postType, postsPerPage, orderby, order, categoryIds).
29 * @return \WP_Post[]
30 */
31 public function get_posts(array $query) {
32 $args = $this->get_query_args([
33 'post_type' => $query['postType'] ?? 'post',
34 'posts_per_page' => $query['postsPerPage'] ?? 6,
35 'orderby' => $query['orderby'] ?? 'date',
36 'order' => $query['order'] ?? 'desc',
37 'category_ids' => $query['categoryIds'] ?? [],
38 ]);
39
40 return $this->ensure_minimum_posts(get_posts($args));
41 }
42
43 /**
44 * Pad a custom item list to the minimum needed for a seamless loop.
45 *
46 * @param array $items
47 * @return array
48 */
49 public function pad_items(array $items) {
50 return $this->ensure_minimum_posts($items);
51 }
52
53 /**
54 * Resolve the public URL for a post, honoring custom URLs.
55 *
56 * @param \WP_Post $post
57 * @return string
58 */
59 public function url($post) {
60 return $this->get_post_url($post);
61 }
62 }
63