【问题标题】:include a php file which is part of custom plugin directory包含一个 php 文件,该文件是自定义插件目录的一部分
【发布时间】:2015-05-19 10:07:17
【问题描述】:

I have created a plugin called "add menu to dash board". For that I have created folder addmenu in wordpress's plugin folder. In that folder my main php file of the plugin and the otherentry.php`文件存在。

通过插件,我创建了一个菜单和子菜单、信息和条目、链接。 现在我想在单击 submenu(entry) 时重定向到 entry.php 文件,因为我有一个简单的 html 表单,我想从中插入数据到数据库中。

那么有人可以帮我解决这个问题吗?

我已经读出了 require_once(),require_once() & include_once(), include()。但我不明白。

    function register_my_custom_menu_page() 
    {
        //add_menu_page('custom menu title', 'custom menu', 'add_users', 'custompage', '_custom_menu_page', null, 6); 

        add_menu_page("Info", "Info", 0, "info-slug", "infoPageFunction","", 6);
        add_submenu_page("info-slug", "Entry", "Entry", 0, "entry-slug", "entryPageFunction");
        add_submenu_page("info-slug", "Link", "Link", 0, "link-slug", "linkPageFunction");
    }

add_action('admin_menu', 'register_my_custom_menu_page');

    function entryPageFunction()
    {
      //~ echo '<script>
                //~ window.location="/var/www/html/wordpress/wp-content/plugins/addmenu/entry.php";
            //~ </script>';
            require_once( add_Cmenu__PLUGIN_DIR . 'entry.php' );
    }

上面的代码我试过了

也试过这个:-include( plugin_dir_path( __FILE__ ) . 'add_Cmenu/entry.php');

【问题讨论】:

  • 我不确定问题是什么...您需要帮助插入菜单或如何处理表单数据?
  • 请添加您已经尝试过的代码。
  • 不,我已插入菜单。
  • 现在我只想在单击名为“entry”的子菜单时重定向到 php 文件.....我创建的菜单 id 像 Info(main menu),entry&link(submenu)
  • 请帮帮我......@mjk 我已经插入了我的代码

标签: php wordpress


【解决方案1】:

试试这个。

 function add_menu_info(){

                   add_menu_page('Info', 'Info', 'manage_options', 'Info', 'InfoFun');
                   add_submenu_page('Info', 'Entry', 'Entry', 'manage_options', 'entry', 'entryFun');
            }

        add_action('admin_menu', 'add_menu_info');


    function  entryFun(){

        include(plugin_dir_path( __FILE__ ).'entry.php');
        }

【讨论】:

  • 好吧,亲爱的@sanket,
猜你喜欢
  • 2013-05-03
  • 2019-06-22
  • 2012-06-28
  • 2014-03-17
  • 1970-01-01
  • 1970-01-01
  • 2014-02-05
  • 2011-11-26
  • 2014-07-13
相关资源
最近更新 更多