创建处理和提交表单的wordpress插件


Create wordpress plugin that processes and submit form

我正在研究如何为wordpress制作插件,我可以制作一个插件,添加短代码放置在我的页面上并生成表单。

function mf_container($atts, $content = null) {
    $content = do_shortcode($content);
    $content = str_replace("<br />","",$content);
    $content = str_replace("<p>","",$content);
    $content = str_replace("</p>","",$content);
    return 
        "<form action='".plugin_dir_url( __FILE__ )."mult-form-submit.php' method='POST'>" . $content . "</form>";
}
add_shortcode('mult_form','mf_container');

现在,使此表单保存在与登录用户相关的银行中。

当我单击提交时,上面的代码会将我重定向到"多表单提交.php"页面的方式。但是,当我进入该页面时,我中有以下代码:

<?php if ( ! defined( 'ABSPATH' ) ) die("Not permited");
global $wpdb, $current_user;
$current_user = wp_get_current_user();

然而,自从这以后,她就没有回来过,在Worpress的背景下,谁能做到?

我设法找到了一个有光的参考,经过多次尝试,我找到了如何做。那是参考:链接

我正在使用由 WORDPRESS 插件样板生成器生成的插件结构

在其中,您应该将公共视图中开始的内容放在函数中:define_public_hooks() 。在这个角色中,我选中了一个扩展,启用了使用我的插件的选项:

/** Set build form by shorcodes*/
if($this->get_option('mult_form')){
   $this->loader->add_action('init', $plugin_public, 'mult_form');
}

本节将我重定向到控制我所有公共操作的类的函数:

public function mult_form(){
    if(isset ( $_REQUEST['action']) and $_REQUEST['action'] == 'mult_form_submited'){
        $this->mult_form_submit();
    }
    $this->mult_form_shortcode();
}

称它为两个私人函数,在哪里进行一些不会显示代码的处理,如果一切顺利,则进行include_once('partials / my_file.php');,当然,将火焰转换为不同的文件,首先是所有处理以生成短代码的地方,第二个是我将放置所有处理提交表单的地方。