/** * Shortcode: [form_borrador] */ function fb_formulario_shortcode() { ob_start(); // Procesar el formulario si se envió if ( isset($_POST['fb_submit']) ) { $titulo = sanitize_text_field($_POST['fb_titulo']); $contenido = sanitize_textarea_field($_POST['fb_contenido']); // Crear el borrador $nuevo_post = array( 'post_title' => $titulo, 'post_content' => $contenido, 'post_status' => 'draft', 'post_type' => 'post' ); $post_id = wp_insert_post($nuevo_post); if ($post_id) { echo "<p style='color:green;'><strong>✅ Borrador creado correctamente.</strong></p>"; } else { echo "<p style='color:red;'><strong>❌ Hubo un error al crear el borrador.</strong></p>"; } } // Formulario HTML ?> <form method="post"> <p> <label for="fb_titulo">Título:</label><br> <input type="text" name="fb_titulo" id="fb_titulo" required style="width:100%;"> </p> <p> <label for="fb_contenido">Contenido:</label><br> <textarea name="fb_contenido" id="fb_contenido" rows="6" required style="width:100%;"></textarea> </p> <p> <input type="submit" name="fb_submit" value="Crear borrador"> </p> </form> <?php return ob_get_clean(); } add_shortcode('form_borrador', 'fb_formulario_shortcode');