Skip to content

Commit a88ad71

Browse files
author
Smart Cloud Solutions Inc.
committed
Release Flow 1.1.4 with content-root pattern support
1 parent 5ec0e25 commit a88ad71

4 files changed

Lines changed: 135 additions & 28 deletions

File tree

admin/php/admin.php

Lines changed: 115 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct()
4444

4545
$this->settings = FlowAdminSettings::fromMixed($merged);
4646
$this->registerRestRoutes();
47+
add_action('pre_get_posts', array($this, 'filterPatternListQuery'));
4748
}
4849

4950
public function getSettings(): FlowAdminSettings
@@ -145,10 +146,98 @@ public function addMenu(): void
145146
add_filter('parent_file', array($this, 'highlightMenu'));
146147
add_filter('submenu_file', array($this, 'highlightSubmenu'));
147148

148-
add_filter('manage_edit-wp_block_columns', array($this, 'addShortcodeColumn'), 20);
149-
add_action('manage_wp_block_posts_custom_column', array($this, 'renderShortcodeColumn'), 10, 2);
150-
add_action('admin_enqueue_scripts', array($this, 'copyShortcode'));
149+
$post_type = filter_input(INPUT_GET, 'post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
150+
$search = filter_input(INPUT_GET, 's', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
151151

152+
if ($this->isFlowPatternsRequest($post_type, $search)) {
153+
add_filter('manage_edit-wp_block_columns', array($this, 'addShortcodeColumn'), 20);
154+
add_action('manage_wp_block_posts_custom_column', array($this, 'renderShortcodeColumn'), 10, 2);
155+
add_action('admin_enqueue_scripts', array($this, 'copyShortcode'));
156+
}
157+
158+
}
159+
160+
private function isFlowPatternsRequest(?string $post_type = null, ?string $search = null): bool
161+
{
162+
$resolved_post_type = $post_type;
163+
if ($resolved_post_type === null) {
164+
$resolved_post_type = filter_input(INPUT_GET, 'post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
165+
}
166+
167+
$resolved_search = $search;
168+
if ($resolved_search === null) {
169+
$resolved_search = filter_input(INPUT_GET, 's', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
170+
}
171+
172+
return 'wp_block' === $resolved_post_type && 'smartcloud-flow' === $resolved_search;
173+
}
174+
175+
public function filterPatternListQuery($query): void
176+
{
177+
if (
178+
!is_admin()
179+
|| !($query instanceof \WP_Query)
180+
|| !$query->is_main_query()
181+
|| $query->get('flow_pattern_lookup')
182+
|| !$this->isFlowPatternsRequest((string) $query->get('post_type'), (string) $query->get('s'))
183+
) {
184+
return;
185+
}
186+
187+
$pattern_ids = $this->getFlowPatternIds();
188+
189+
$query->set('post__in', !empty($pattern_ids) ? $pattern_ids : array(0));
190+
}
191+
192+
private function getFlowPatternIds(): array
193+
{
194+
$candidate_ids = get_posts(array(
195+
'post_type' => 'wp_block',
196+
'post_status' => 'any',
197+
'posts_per_page' => -1,
198+
'fields' => 'ids',
199+
'orderby' => 'ID',
200+
'order' => 'ASC',
201+
'no_found_rows' => true,
202+
'flow_pattern_lookup' => true,
203+
));
204+
205+
return array_values(array_filter(
206+
array_map('intval', $candidate_ids),
207+
array($this, 'isFlowPatternPost')
208+
));
209+
}
210+
211+
private function getFlowPatternShortcodes(int $post_id): array
212+
{
213+
$post = get_post($post_id);
214+
215+
if (!($post instanceof \WP_Post) || 'wp_block' !== $post->post_type) {
216+
return array();
217+
}
218+
219+
$blocks = parse_blocks((string) $post->post_content);
220+
$shortcodes = array();
221+
222+
foreach ($blocks as $block) {
223+
$block_name = is_array($block) ? ($block['blockName'] ?? '') : '';
224+
225+
if ('smartcloud-flow/form' === $block_name) {
226+
$shortcodes['form'] = sprintf('[smartcloud-flow-form id="%d"]', $post_id);
227+
continue;
228+
}
229+
230+
if ('smartcloud-flow/content-root' === $block_name) {
231+
$shortcodes['content-root'] = sprintf('[smartcloud-flow-content-root id="%d"]', $post_id);
232+
}
233+
}
234+
235+
return array_values($shortcodes);
236+
}
237+
238+
private function isFlowPatternPost(int $post_id): bool
239+
{
240+
return !empty($this->getFlowPatternShortcodes($post_id));
152241
}
153242

154243
public function addShortcodeColumn($columns)
@@ -159,23 +248,30 @@ public function addShortcodeColumn($columns)
159248

160249
public function renderShortcodeColumn($column, $post_id)
161250
{
162-
if ('wpc_shortcode' !== $column || get_query_var('s') !== 'smartcloud-flow') {
251+
if ('wpc_shortcode' !== $column) {
163252
return;
164253
}
165254

166-
$shortcode = sprintf('[smartcloud-flow-form pattern="%d"]', $post_id);
167-
168-
printf(
169-
'<span class="wpc-shortcode" id="wpc-sc-%1$d"><code>%2$s</code></span>
170-
<div class="row-actions">
171-
<span class="copy">
172-
<a href="#" class="wpc-copy" data-target="wpc-sc-%1$d">Copy</a>
173-
</span>
174-
</div>',
175-
(int) $post_id,
176-
esc_html($shortcode),
177-
esc_html__('Copy', 'smartcloud-flow')
178-
);
255+
$shortcodes = $this->getFlowPatternShortcodes((int) $post_id);
256+
if (empty($shortcodes)) {
257+
return;
258+
}
259+
260+
$copy_label = esc_html__('Copy', 'smartcloud-flow');
261+
$rows = array();
262+
263+
foreach ($shortcodes as $index => $shortcode) {
264+
$target_id = sprintf('wpc-sc-%1$d-%2$d', (int) $post_id, (int) $index);
265+
266+
$rows[] = sprintf(
267+
'<div class="wpc-shortcode-row"><span class="wpc-shortcode" id="%1$s"><code>%2$s</code></span><div class="row-actions"><span class="copy"><a href="#" class="wpc-copy" data-target="%1$s">%3$s</a></span></div></div>',
268+
esc_attr($target_id),
269+
esc_html($shortcode),
270+
$copy_label
271+
);
272+
}
273+
274+
echo implode('', $rows);
179275
}
180276

181277
public function copyShortcode($hook)
@@ -245,15 +341,15 @@ function showFail(){
245341
}
246342
public function highlightMenu($parent_file)
247343
{
248-
if (get_query_var('post_type') === 'wp_block' && get_query_var('s') === 'smartcloud-flow') {
344+
if ($this->isFlowPatternsRequest((string) get_query_var('post_type'), (string) get_query_var('s'))) {
249345
return SMARTCLOUD_WPSUITE_SLUG;
250346
}
251347
return $parent_file;
252348
}
253349

254350
public function highlightSubmenu($submenu_file)
255351
{
256-
if (get_query_var('post_type') === 'wp_block' && get_query_var('s') === 'smartcloud-flow') {
352+
if ($this->isFlowPatternsRequest((string) get_query_var('post_type'), (string) get_query_var('s'))) {
257353
return admin_url("edit.php?post_type=wp_block&s=smartcloud-flow");
258354
}
259355
return $submenu_file;

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Free mode supports:
3737
- **Gutenberg form builder** with dedicated layout and field blocks
3838
- **Front-end form rendering** with Mantine-based UI
3939
- **Conditional logic and validation**
40-
- **Shortcode support** via `[smartcloud-flow-form]`
41-
- **Elementor widget support** for embedding forms outside Gutenberg
40+
- **Shortcode support** via `[smartcloud-flow-form]` and `[smartcloud-flow-content-root]`
41+
- **Elementor widget support** for embedding forms or content roots outside Gutenberg
4242
- **Direct browser submission** to the endpoint URL configured for each form
4343

4444
In free mode, WordPress/PHP does **not** have to proxy the request. Forms can post directly from the browser to your own endpoint.

readme.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: forms, workflows, gutenberg, aws, automation
55
Requires at least: 6.2
66
Tested up to: 7.0
77
Requires PHP: 8.1
8-
Stable tag: 1.1.3
8+
Stable tag: 1.1.4
99
License: MIT
1010
License URI: https://mit-license.org/
1111
Text Domain: smartcloud-flow
@@ -49,7 +49,7 @@ This lets Flow use Gatey-aware authenticated API access, while keeping the backe
4949
* **Rich display & content blocks** — Use styled content primitives such as blockquotes, marks, badges, code blocks, spoilers, lists, tables, timelines, and overflow lists alongside inputs.
5050
* **Conditional logic & validation** — Show/hide, enable/disable, require/optional, and other rule-based field behavior.
5151
* **Theme overrides & design tokens** — Theme both interactive controls and display/content blocks inside the Shadow DOM with Mantine variables and stable `--flow-*` CSS tokens.
52-
* **Shortcodes & Elementor support** — Reuse forms via shortcode and Elementor integrations.
52+
* **Shortcodes & Elementor support** — Reuse forms or content roots via shortcode and Elementor integrations.
5353
* **Flexible submission target model** — Submit directly from the browser to a per-form endpoint URL.
5454
* **Pro: backend-aware operation** — Connect Flow to the AWS-hosted Flow backend for durable submissions, admin tooling, templates, workflows, and webhook-driven automation.
5555
* **Pro: backend form sync** — Optionally sync Gutenberg-defined forms into canonical backend form definitions stored in AWS.
@@ -123,7 +123,10 @@ Forms can still work as long as they submit to another valid configured endpoint
123123
Yes. Flow runs in the browser and can submit directly to the configured endpoint, so WordPress/PHP does not need to proxy the request.
124124

125125
= Does this work outside Gutenberg? =
126-
Yes. Use the `[smartcloud-flow-form]` shortcode or the Elementor widget. Developers can also integrate the JavaScript APIs directly.
126+
Yes. Use the `[smartcloud-flow-form]` or `[smartcloud-flow-content-root]` shortcode, or the Elementor Flow Form / Flow Content Root widgets. Developers can also integrate the JavaScript APIs directly.
127+
128+
= Can I reuse a Flow Content Root outside Gutenberg? =
129+
Yes. Use `[smartcloud-flow-content-root id="123"]` with a reusable block / pattern that contains a Flow Content Root block.
127130

128131
== Screenshots ==
129132

@@ -202,6 +205,11 @@ Flow Pro includes additional functionality such as backend-powered submissions m
202205

203206
== Changelog ==
204207

208+
= 1.1.4 =
209+
* Fix: Flow Patterns now includes reusable blocks that contain either a Flow Form or a Flow Content Root block.
210+
* Fix: The shortcode column now shows the matching copy-ready shortcode for each Flow pattern, including content-root entries.
211+
* Docs: Expanded the readme shortcode guidance to cover Flow Content Root reuse outside Gutenberg.
212+
205213
= 1.1.3 =
206214
* Fix: JavaScript-set field defaults are now scoped by `formId`, so prefilled values no longer bleed across multiple forms on the same page.
207215
* Fix: Flow now publishes browser helper methods on `WpSuite.plugins.flow` for setting, clearing, and reading per-form field defaults.
@@ -236,6 +244,9 @@ Flow Pro includes additional functionality such as backend-powered submissions m
236244

237245
== Upgrade Notice ==
238246

247+
= 1.1.4 =
248+
Recommended update if you reuse Flow patterns outside Gutenberg; this release adds content-root patterns to the admin list and exposes the matching copy-ready shortcode targets.
249+
239250
= 1.1.3 =
240251
Recommended update if you prefill Flow forms from JavaScript or render multiple forms on the same page; this release adds form-scoped default-value helpers and applies store defaults by `formId`.
241252

smartcloud-flow.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Requires at least: 6.2
77
* Tested up to: 7.0
88
* Requires PHP: 8.1
9-
* Version: 1.1.3
9+
* Version: 1.1.4
1010
* Author: Smart Cloud Solutions Inc.
1111
* Author URI: https://smart-cloud-solutions.com
1212
* License: MIT
@@ -18,7 +18,7 @@
1818

1919
namespace SmartCloud\WPSuite\Flow;
2020

21-
const VERSION = '1.1.3';
21+
const VERSION = '1.1.4';
2222

2323
if (!defined('ABSPATH')) {
2424
exit;
@@ -243,7 +243,7 @@ private function renderShortcodeBlock(string $block_name, array $block, array $a
243243
}
244244

245245
/**
246-
* Shortcode handler for [smartcloud-flow-form pattern="123" ...]
246+
* Shortcode handler for [smartcloud-flow-form id="123" ...]
247247
*
248248
* @param array $atts
249249
* @param string|null $content
@@ -407,7 +407,7 @@ public function shortcodeFlowForm($atts, $content = null): string
407407
}
408408

409409
/**
410-
* Shortcode handler for [smartcloud-flow-content-root pattern="123" ...]
410+
* Shortcode handler for [smartcloud-flow-content-root id="123" ...]
411411
*
412412
* @param array $atts
413413
* @param string|null $content

0 commit comments

Comments
 (0)