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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度