我怎么能调用服务器端文件我的插件(wordpress)与菜单


How can I call server side file of my plugin (wordpress) with menu?

我有一个包含2个php文件的wordpress插件。在主文件中,我添加了两个菜单,当用户单击第二个菜单时,我想调用第二个php文件。我有一个公共方法命名list_table_page在第二个文件。

add_menu_page( 'tm-plug', 'test.php', 'manage_options', plugins_url( 'tm_plug/test.php' ), 'list_table_page' );

在《WP Code Reference》中,add_menu_page被定义为:

add_menu_page ( string $page_title, //required 
string $menu_title, //required
string $capability, /required
string $menu_slug, //required
callback $function = '', //optional
string $icon_url = '', //option
int $position = null //option
);

给出的例子是:

add_menu_page(
        __( 'Custom Menu Title', 'textdomain' ),
        'custom menu',
        'manage_options',
        'myplugin/myplugin-admin.php',
        '',
        plugins_url( 'myplugin/images/icon.png' ),
        6
    );

看看你的代码,你定义的值和参数是错误的。请看下面:

add_menu_page ( 'tm-plug', //string $page_title
'tm-plug', //string $menu_title
'manage_options', //string $capability
'list_table_page', //string $menu_slug
'tm_plug/test.php', //callback $function = ''
'', //string $icon_url = '' (you haven't defined any)
1 //int $position = null(you haven't defined any)
);

希望通过查看评论你能看到你错在哪里。

使用require_once包含文件

,然后在第二个菜单函数的定义中调用该文件(第二个文件)的函数。

如果你需要更多的帮助,请告诉我