dpjuppr1361 2015-10-27 23:23
浏览 62
已采纳

自定义表单处理wordpress

I have seen this mentioned before however the other questions don't answer mine.

I have a plugin which will save information to a custom table setup through wordpress.

this plugin is only accessible through the admin panel.

rather then using the register_option alternative I need to use custom tables because there is relational data

I am able to reach my form-handler.php however it does not have access to the wordpress functions

<form method="post" action="<?php echo $this->plugin_uri.'includes/form-handler.php';?>">
    <input type="submit"/>
</form>

rather I was wondering if there is a method other then registering options that would allow the functionality like so

register_form('some form', array($this, 'sanitize_form'));

and in the form call another function to identify it

<form action="options.php" method="post">
    <?php form_details('some form');
    <input type="submit"/>
</form>

kinda like how the settings api works is there any proper way to do this or am I going to have to hack the settings api a bit to get it to work that way...

  • 写回答

1条回答 默认 最新

  • douchunsui2395 2015-10-28 02:38
    关注

    If you call the form-handler.php file directly, it is obvious that no Wordpress code is loaded at any time. Its just your code. One thing you could do is to add the following lines at the beginning of the form handler file:

    define('WP_USE_THEMES', false); // prevents Wordpress from running its usual init stuff
    require_once($pathToWordpress . '/wp-blog-header.php'); // loads Wordpress
    

    after that you can use all the core functionality WP comes with

    Regards,

    Stefan

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大