PluginProbe
AI Engine – The Chatbot, AI Framework & MCP for WordPress / 3.7.6
AI Engine – The Chatbot, AI Framework & MCP for WordPress v3.7.6
3.7.6 3.7.5 3.7.4 3.7.3 3.7.2 3.7.1 3.7.0 3.6.9 3.6.8 3.6.7 3.6.6 3.6.4 3.6.5 3.6.3 3.6.2 3.6.1 3.6.0 3.5.9 3.5.8 3.5.7 3.5.6 3.5.5 3.5.4 3.5.3 3.5.2 All 526 releases
ai-engine / classes / modules / forms-manager.php
forms-manager.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 class Meow_MWAI_Modules_Forms_Manager {
4 private $core = null;
5
6 public function __construct( $core ) {
7 $this->core = $core;
8 add_action( 'init', [ $this, 'register_post_type' ] );
9 add_shortcode( 'mwai_form', [ $this, 'shortcode_render_form' ] );
10 }
11
12 public function register_post_type() {
13 $labels = [
14 'name' => 'AI Forms',
15 'singular_name' => 'AI Form',
16 ];
17
18 register_post_type( 'mwai_form', [
19 'labels' => $labels,
20 'public' => false,
21 'show_ui' => true, // Allow native edit screens, but keep it out of the menu
22 'show_in_menu' => false,
23 'show_in_rest' => true, // Enable Gutenberg data model via REST
24 'supports' => [ 'title', 'editor' ],
25 'capability_type' => 'post',
26 'map_meta_cap' => true,
27 ] );
28 }
29
30 /**
31 * [mwai_form id="123"]
32 * Render a saved form by ID using the block content and built-in shortcodes.
33 */
34 public function shortcode_render_form( $atts ) {
35 $atts = shortcode_atts( [ 'id' => 0 ], $atts );
36 $post_id = intval( $atts['id'] );
37 if ( !$post_id ) {
38 return '';
39 }
40
41 $post = get_post( $post_id );
42 if ( !$post || $post->post_type !== 'mwai_form' ) {
43 return '';
44 }
45
46 // Check post status: only published forms are publicly accessible.
47 // Private/draft forms require the current user to have read permission.
48 if ( $post->post_status !== 'publish' && !current_user_can( 'read_post', $post_id ) ) {
49 return '';
50 }
51
52 // Ensure themes can be enqueued by nested shortcodes if needed
53 // Actual scripts/styles will be handled by the individual form shortcodes
54 $content = $post->post_content;
55
56 // Apply blocks and shortcodes
57 // Let WordPress parse blocks first, then shortcodes within
58 $content = do_blocks( $content );
59 $content = do_shortcode( $content );
60 return $content;
61 }
62 }
63