Notifications
Clear all
Topic starter
Exists two way to add an admin menu, and one is more customizable. You can write the next lines from functions.php of your theme or index.php from your plugin.
The 1st way:
/**
* Headers in the admin panel
*/
osc_add_hook('admin_menu_init', function() {
osc_add_admin_submenu_divider(
"plugins", __("Header menu", "my_plugin"), "my_plugin", "administrator"
);
osc_add_admin_submenu_page(
"plugins", __('Page menu', "my_plugin"), osc_route_admin_url("my-plugin-route"), "my-plugin-route", "administrator"
);
osc_add_admin_submenu_page(
"plugins", __('Page menu 2', "my_plugin"), osc_route_admin_url("my-plugin-route-2"), "my-plugin-route-2", "administrator"
);
});
In this case, we added a simple admin menu with header and respective page (route).
¿You need add a title to the pages admin of plugin? Not problem:
switch (Params::getParam("route")) {
case 'my-plugin-route':
$filter = function($string) {
return __("Title of page menu", "my_plugin");
};
// Page title (in <head />)
osc_add_filter("admin_title", $filter, 10);
// Page title (in <h1 />)
osc_add_filter("custom_plugin_title", $filter);
break;
case 'my-plugin-route-2':
$filter = function($string) {
return __("Title of page menu 2", "my_plugin");
};
// Page title (in <head />)
osc_add_filter("admin_title", $filter, 10);
// Page title (in <h1 />)
osc_add_filter("custom_plugin_title", $filter);
break;
}
The 2nd way (customizable):
/**
* Plugin menu in admin panel
*/
function my_plugin_admin_menu() {
echo '<h3><a href=""#">Header" menu</a></h3>
<ul>
<li><a href=""'.osc_route_admin_url('my-plugin-route').'">»" '.__('Page menu', 'my_plugin').'</a></li>
<li><a href=""'.osc_route_admin_url('my-plugin-route-2').'">»" '.__('Page menu 2', 'my_plugin').'</a></li>
</ul>';
}
osc_add_hook('admin_menu', 'my_plugin_admin_menu');
Add title to the pages of admin menu:
/**
* Headers in the admin panel depend of route's url
*/
function my_plugin_admin_page_header() {
?>
<h1><?php _e('Page menu'); ?></h1>
<?php
}
function my_plugin_admin_page_header_2() {
?>
<h1><?php _e('Page menu 2'); ?></h1>
<?php
}
function my_plugin_admin_page_headers() {
switch (Params::getParam('route')) {
case 'my-plugin-route':
osc_remove_hook('admin_page_header', 'customPageHeader');
osc_add_hook('admin_page_header', 'my_plugin_admin_page_header');
break;
case 'my-plugin-route-2':
osc_remove_hook('admin_page_header', 'customPageHeader');
osc_add_hook('admin_page_header', 'my_plugin_admin_page_header_2');
break;
}
}
// Run headers in the admin panel, depend of route
osc_add_hook('admin_header', 'my_plugin_admin_page_headers');
This second way is more customizable by how you can see, since it allows you to interact directly on the HTML content of the menu.
Reference: Elsewhere you can follow this link that explains a tutorial about How to make a Plugin in Osclass. Download its file here!
Posted : 21/01/2020 5:48 pm
Thanks
Posted : 27/01/2020 1:25 pm