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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?