猿问

Wordpress 中如何创建子菜单?

我是 php / Wordpress 编程新手,我对 add_submenu_page 函数有问题,它不起作用。


这是我使用的代码。


<?php


defined('ABSPATH') or die("Bye bye");

define('LSC_RUTA',plugin_dir_path(__FILE__));


function insert_menu(){

    

    //Variables menú

    $nombre_pagina = 'LifeMiles Soap Client';

    $nombre_menu = 'Lifemiles Soap Client';

    $permisos = 'manage_options';

    $menu_slug = LSC_RUTA . "admin/configuracion.php";

    $function = '';

    $icon = 'dashicons-plugins-checked';

    

    add_menu_page($nombre_pagina, $nombre_menu, $permisos, $menu_slug, $function, $icon, 31);

}


function insert_submenu(){

    

    add_submenu_page(LSC_RUTA . "conectividad.php", 

        'Ajustes', 

        'Ajustes', 

        'manage_options', 

        LSC_RUTA . "admin/configuracion.php");

}


register_activation_hook( __FILE__, 'create_plugin_database_table' );


add_action( 'admin_menu', 'insert_menu' );

add_action( 'admin_menu', 'insert_submenu' );


?>

有谁能够帮助我?


海绵宝宝撒
浏览 111回答 1
1回答

当年话下

我已经解决了。我的变量顺序是错误的。该函数必须按以下顺序接收参数:add_submenu_page (string $ parent_slug, string $ page_title, string $ menu_title, string $ capability, string $ menu_slug, callable $ function = '', int $ position = null);我是这样做的:add_submenu_page (string $ Menu_slug, string $ page_title, string $ menu_title, string $ capability, string $ parent_slug, callable $ function = '', int $ position = null);正确的代码如下:<?phpdefined('ABSPATH') or die("Bye bye");define('LSC_RUTA',plugin_dir_path(__FILE__));function insert_menu(){&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //Variables menú&nbsp; &nbsp; &nbsp; &nbsp; $nombre_pagina = 'LifeMiles Soap Client';&nbsp; &nbsp; &nbsp; &nbsp; $nombre_menu = 'Lifemiles Soap Client';&nbsp; &nbsp; &nbsp; &nbsp; $permisos = 'manage_options';&nbsp; &nbsp; &nbsp; &nbsp; $menu_slug = LSC_RUTA . "admin/configuracion.php";&nbsp; &nbsp; &nbsp; &nbsp; $function = '';&nbsp; &nbsp; &nbsp; &nbsp; $icon = 'dashicons-plugins-checked';&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; add_menu_page($nombre_pagina, $nombre_menu, $permisos, $menu_slug, $function, $icon, 31);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; add_submenu_page($menu_slug,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Ajustes',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Ajustes',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'manage_options',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $menu_slug);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; add_submenu_page($menu_slug,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Prueba Conectividad',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Prueba Conectividad',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'manage_options',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LSC_RUTA . "conectividad.php");}register_activation_hook( __FILE__, 'create_plugin_database_table' );add_action( 'admin_menu', 'insert_menu' );?>问候。
随时随地看视频慕课网APP
我要回答