duanlei2458 2015-09-30 08:55
浏览 32
已采纳

如何通过菜单调用我的插件(wordpress)的服务器端文件?

I have a plugin in wordpress that contain 2 php files. In main file , I added two menus and I want to call second php file when user click on second menu. I have a public method that name list_table_page on second file.

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

2条回答 默认 最新

  • dongshi1868 2015-10-05 08:02
    关注

    As for as it's cited in WP Code Reference, add_menu_page is defined as:

    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
    );
    

    And the example given is:

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

    Which, looking at your code, you're defining the values and parameters wrong. Have a look at below:

    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)
    );
    

    Hope by looking at the comments you'd be able to see where you have gone wrong.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀