Adding a menu item to the v1.5.0 admin
Every time I'm adding a new item to my v1.5.0 admin, I search the forums and can never find the post (I know it's there) that identifies how to get your new tool added to the admin menu ... so I'm noting the process here.
Let's say that you have a new tool named new_tool.php that you want to plug into the Tools menu. Here's the file-system structure you should wind up with:
Code:
/YOUR_ADMIN/new_tool.php
Contains the code that implements your new tool.
/YOUR_ADMIN/includes/extra_datafiles/new_tool_filenames.php
Contains the filename definition for your new tool, e.g. define('FILENAME_NEW_TOOL', 'new_tool.php');
/YOUR_ADMIN/includes/languages/english/extra_definitions/new_tool_name.php
Contains the menu entry text definition for your new tool, e.g. define('BOX_TOOLS_NEW_TOOL', 'New Tool');
/YOUR_ADMIN/includes/languages/english/new_tool.php
Contains the language-specific defines for your new tool, filename must be the same name as to tool itself.
The following file is where your tool is actually added to the admin Tools menu.
/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php:
Code:
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
//----
// If the installation supports admin-page registration (i.e. v1.5.0 and later), then
// register the New Tools tool into the admin menu structure.
//
if (function_exists('zen_register_admin_page')) {
if (!zen_page_key_exists('toolsNewTool')) {
zen_register_admin_page('toolsNewTool', 'BOX_TOOLS_NEW_TOOL', 'FILENAME_NEW_TOOL','' , 'tools', 'Y', 20);
}
}
- The value toolsNewTool is a (hopefully) unique value that identifies your new tool.
- The values BOX_TOOLS_NEW_TOOL and FILENAME_NEW_TOOL are defined within the other files within your toolset.
- The fourth parameter ('') has any parameters that your tool might require. (Rarely used.)
- The fifth parameter ('tools' in the example) identifies which of the high-level menu items your tool "attaches" to, one of: configuration, catalog, modules, customers, taxes, localization, reports, tools, gv, access, or extras.
- The sixth parameter ('Y') identifies whether ('Y') or not ('N') to display the page on the admin menu.
- The seventh parameter (20) is the sort order for the page, i.e. where it lives on the drop-down menu in relation to the sort order of others.
Re: Adding a menu item to the v1.5.0 admin
NOTE: This post has been updated and converted to an FAQ article at: http://www.zen-cart.com/content.php?...e-v1-5-0-admin
Re: Adding a menu item to the v1.5.0 admin
Thanks, DrByte! Is there a procedure that I can use to modify that FAQ? I was eventually planning on adding instructions for enabling plugins that attach to the Configuration menu via SQL patches.
Re: Adding a menu item to the v1.5.0 admin
I found it ... I suppose since I'm noted as the author there's a teeny "Edit" button next to the FAQ title. I'll try not to mess it up when I edit it!
Re: Adding a menu item to the v1.5.0 admin
Thanks lat9 - much clearer now.
Re: Adding a menu item to the v1.5.0 admin
Does this work with Zen Cart 1.5.1 also?
Re: Adding a menu item to the v1.5.0 admin
I added a plugin to the admin menu for 1.5.1.
How do you add the following to the admin? Ann admin menu item with and ID.
Code:
http://www.YourDomain.com/shop/admin/configuration.php?gID=33
Re: Adding a menu item to the v1.5.0 admin
By using this method, new menu items gets added to different parts of the admin; specifically to “zen_admin_pages” table in the database?
1. Once added do you leave the “/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php” file, or do delete it?
2. If you want to change the sort order of this file, would the change be done from this file “/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php” or you would have to it from change “zen_admin_pages” table?
3. Is “zen_admin_pages” table, the only table getting effected by creating “/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php” file?
4. If you make a mistake, where can correct your mistake, in the “zen_admin_pages” table or “/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php” file?
I went ahead and added the following to the admin menu,
Quote:
Originally Posted by
Kevin205
How do you add the following to the admin? Ann admin menu item with and ID.
Code:
http://www.YourDomain.com/shop/admin/configuration.php?gID=33
Ofsource the menu is not seen under the configuration menu!
And I saw what I did wrong “zen_admin_pages” table.
Question, can I fix this in SQL or is there another way of doing it?
Re: Adding a menu item to the v1.5.0 admin
Quote:
Originally Posted by
Kevin205
Does this work with Zen Cart 1.5.1 also?
Yes, it does.
Quote:
Originally Posted by
Kevin205
I added a plugin to the admin menu for 1.5.1.
How do you add the following to the admin? Ann admin menu item with and ID.
Code:
http://www.YourDomain.com/shop/admin/configuration.php?gID=33
You need to upload (via FTP) a file named /YOUR_ADMIN/includes/languages/english/extra_definitions/your_menu_item.php. That file needs to contain a definition:
Code:
define('BOX_YOUR_MENU_ITEM', 'My Menu Item');
Once that file's uploaded, you can use your admin's Admin Access Management->Admin Page Registration and enter:
Page Key Name ... myMenuItemConfiguration
Page Name ........... BOX_YOUR_MENU_ITEM
Page File Name ..... FILENAME_CONFIGURATION
Page Parameters .. gID=33
Menu ..................... Configuration
Display on Menu? .. checked
Sort Order ............. nn
Then click "Insert".
Quote:
Originally Posted by
Kevin205
By using this method, new menu items gets added to different parts of the admin; specifically to “zen_admin_pages” table in the database?
1. Once added do you leave the “/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php” file, or do delete it?
2. If you want to change the sort order of this file, would the change be done from this file “/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php” or you would have to it from change “zen_admin_pages” table?
3. Is “zen_admin_pages” table, the only table getting effected by creating “/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php” file?
4. If you make a mistake, where can correct your mistake, in the “zen_admin_pages” table or “/YOUR_ADMIN/includes/functions/extra_functions/init_new_tool.php” file?
I went ahead and added the following to the admin menu,
Ofsource the menu is not seen under the configuration menu!
And I saw what I did wrong “zen_admin_pages” table.
Question, can I fix this in SQL or is there another way of doing it?
1. Your choice, you can either leave it or delete it.
2. The easiest way to change the sort order is to use phpMyAdmin and change the sort order in your DB_PREFIX . admin_pages entry.
3. Yes. It's the admin_pages table with your DB_PREFIX value prepended.
4. If you make a mistake, your can delete the item you created using the following SQL patch (run from your admin's Tools->Install SQL Patches:
Code:
DELETE FROM admin_pages WHERE page_key='myMenuItemConfiguration';
Note that if you're testing out a plugin that you're creating you should be creating a backup of your database that you can restore to in the event that your modification doesn't work "quite right".
Re: Adding a menu item to the v1.5.0 admin
Thank you for a very detailed set of instructions. I will give it try tomorrow.