advisor.php
7 months ago
chatbot.php
4 months ago
discussions.php
5 months ago
files.php
6 months ago
forms-manager.php
10 months ago
gdpr.php
11 months ago
search.php
1 year ago
security.php
1 year ago
tasks-examples.php
6 months ago
tasks.php
5 months ago
wand.php
5 months ago
forms-manager.php
57 lines
| 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 | // Ensure themes can be enqueued by nested shortcodes if needed |
| 47 | // Actual scripts/styles will be handled by the individual form shortcodes |
| 48 | $content = $post->post_content; |
| 49 | |
| 50 | // Apply blocks and shortcodes |
| 51 | // Let WordPress parse blocks first, then shortcodes within |
| 52 | $content = do_blocks( $content ); |
| 53 | $content = do_shortcode( $content ); |
| 54 | return $content; |
| 55 | } |
| 56 | } |
| 57 |