feat: refine dynamic page sections, fix renderers, improve styling controls and editor schema
This commit is contained in:
@@ -38,6 +38,13 @@ class PagesController
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
|
||||
// Proxy section form submission (e.g. Contact Form webhooks) (Must be before generic slug route)
|
||||
register_rest_route($namespace, '/pages/submit-section-form', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [__CLASS__, 'submit_section_form'],
|
||||
'permission_callback' => '__return_true', // Public endpoint
|
||||
]);
|
||||
|
||||
// Get/Save page structure (structural pages)
|
||||
register_rest_route($namespace, '/pages/(?P<slug>[a-zA-Z0-9_-]+)', [
|
||||
[
|
||||
@@ -666,6 +673,80 @@ class PagesController
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy form submission for a specific section (e.g. Contact Form to Webhook)
|
||||
*/
|
||||
public static function submit_section_form(WP_REST_Request $request)
|
||||
{
|
||||
$body = $request->get_json_params();
|
||||
$source_type = sanitize_text_field($body['source_type'] ?? 'page');
|
||||
$source_id = sanitize_text_field($body['source_id'] ?? '');
|
||||
$section_id = sanitize_text_field($body['section_id'] ?? '');
|
||||
$form_data = $body['form_data'] ?? [];
|
||||
|
||||
if (empty($source_id) || empty($section_id)) {
|
||||
return new WP_Error('invalid_params', 'Missing required parameters', ['status' => 400]);
|
||||
}
|
||||
|
||||
$structure = null;
|
||||
|
||||
if ($source_type === 'template') {
|
||||
$template = get_option("wn_template_{$source_id}", null);
|
||||
if ($template) {
|
||||
$structure = $template;
|
||||
}
|
||||
} else {
|
||||
// It's a page
|
||||
$page = get_post($source_id);
|
||||
if ($page) {
|
||||
$structure = get_post_meta($page->ID, '_wn_page_structure', true);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($structure) || empty($structure['sections'])) {
|
||||
return new WP_Error('not_found', 'Structure not found', ['status' => 404]);
|
||||
}
|
||||
|
||||
// Find the section
|
||||
$section = null;
|
||||
foreach ($structure['sections'] as $s) {
|
||||
if ($s['id'] === $section_id) {
|
||||
$section = $s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$section) {
|
||||
return new WP_Error('not_found', 'Section not found', ['status' => 404]);
|
||||
}
|
||||
|
||||
$webhook_url = $section['props']['webhook_url']['value'] ?? null;
|
||||
if (empty($webhook_url)) {
|
||||
return new WP_Error('invalid_config', 'Webhook URL not configured', ['status' => 400]);
|
||||
}
|
||||
|
||||
// Send to webhook
|
||||
$response = wp_remote_post($webhook_url, [
|
||||
'body' => wp_json_encode($form_data),
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'timeout' => 15,
|
||||
'data_format' => 'body'
|
||||
]);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
return new WP_Error('webhook_failed', 'Failed to contact webhook: ' . $response->get_error_message(), ['status' => 502]);
|
||||
}
|
||||
|
||||
$code = wp_remote_retrieve_response_code($response);
|
||||
if ($code >= 400) {
|
||||
return new WP_Error('webhook_error', 'Webhook returned error code: ' . $code, ['status' => 502]);
|
||||
}
|
||||
|
||||
return new WP_REST_Response(['success' => true], 200);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Helper Methods
|
||||
// ========================================
|
||||
|
||||
Reference in New Issue
Block a user