Funciones para agregar menús en wordpress





//Ej 1 Agregar menú en el de otro plugin. ***** FUNCIONA ******
//https://wordpress.stackexchange.com/questions/91377/admin-menu-as-submenu-from-another-plugin
add_action('admin_menu', 'submenu_woocommerce_booking_calendario', 11 ); //<=Notar la prioridad 11 para agregar en submenú de otro plugin
function submenu_woocommerce_booking_calendario() 
{
    add_submenu_page(
        'edit.php?post_type=wc_booking', //Third party plugin Slug 
        'Calendario Nexo', 
        'Calendario Nexo', 
        'read', //Capability: https://codex.wordpress.org/Roles_and_Capabilities
        'nexo-calendario', //El slug que aparecerá como "...&page=nexo-calendario"
        'func_callback'
    );
}
function func_callback() 
{ 
    echo '<h1>OK</h1>'; 
}

//Ej 2 Ejemplo FUNCIONANDO de agregar menú/submenú:
//https://wordpress.stackexchange.com/questions/66498/add-menu-page-with-different-name-for-first-submenu-item
add_action('admin_menu', 'my_menu_pages');

add_menu_page('My Page Title',
        	'My Menu Title',
        	'manage_options', //Capability: https://codex.wordpress.org/Roles_and_Capabilities
        	'my-menu', //Plugin slug
        	'my_menu_output_callback' );

add_submenu_page(
        	'my-menu', //plugin slug
        	'Submenu Page Title', 'Whatever You Want', 'manage_options', 'my-menu', 'callback' );

add_submenu_page('my-menu', 'Submenu Page Title2', 'Whatever You Want2', 'manage_options', 'my-menu2', 'callback' );


//Ej 3 Agrega opción al menú AJUSTES: https://developer.wordpress.org/reference/functions/add_options_page/
add_action( 'admin_menu', 'my_plugin_menu' );
function my_plugin_menu() {
	add_options_page( 'My Plugin Options', 
'My Plugin',
'manage_options', //Capability: https://codex.wordpress.org/Roles_and_Capabilities
'my-unique-identifier', 'my_plugin_options' );
}
function my_plugin_options() {
	if ( !current_user_can( 'manage_options' ) )  {
		wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
	}
	echo '<div class="wrap">';
	echo '<p>Here is where the form would go if I actually had options.</p>';
	echo '</div>';
}

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *