Stop Censorship Stop Censorship Ribbon  Word Press Role dependent admin-menus | A Blog about Web Design & Development. WordPress development. Tutorials

Word Press Role dependent admin-menus Published on March 8, 2010

Reduzir tamanho de letra Aumentar tamanho de letra Impressão optimizada do artigo Enviar por email

Sometimes we need to give different tasks to different admin-users in our word-press blogs, in order to do so, we need to have some way to give them what we want, and just that. The safest way to do it is the WYSIWYG way, “they will only get what they see”.

This means you will only show them the menus or options they are supposed to act upon. We can achieve this by means of the Word Press roles “user level capabilities”, as was described in the previous article (“Word Press roles and capabilities“), and that will here be put to practice.

Origin: The Word Press Codex

Admin Menu Functions

First thing you need to do is decide weather your plugin or option manager should be inside one of the native top level menus on the left column, or should it have a brand new menu of its own.

Top-Level menu

To add a new top-level menu, you’ll use the add_menu_page function:

add_menu_page(page_title, menu_title, capability, handle, [function], [icon_url]);

or if you want an options page:

add_options_page(page_title, menu_title, capability, handle, [function]);

Parameter values:
page_title:

Text that will go into the HTML page title for the page when the menu is active.

menu_title:

The on-screen name text for the menu.

Capability:

The minimum capability required to display and use this menu page. Whilst for legacy reasons, you may also use user level – the usage of user level is discouraged for future compatibility and has been deprecated since WordPress 1.5.
NOTE: However, if you define user capability by means of the role name instead of the user level, the options you are setting will ONLY be available to that role and not any of the others, including upper hierarchy levels or roles!

handle/file:

If the function parameter is omitted, this should be the PHP file that handles the display of the menu page content. Otherwise, and more commonly, it will be a unique “handle” for the page. e.g. “my-awesome-plugin-settings”

function:

The function that displays the page content for the menu page.
Technically, the function parameter is optional, but if it is not supplied, then WordPress will basically assume that including the PHP file will generate the administration screen, without calling a function. Most plugin authors choose to put the page-generating code in a function within their main plugin file.

In the event that the function parameter is specified, It’s possible to use any string for the file parameter. This allows usage of pages such as ?page=my_super_plugin_page instead of ?page=my-super-plugin/admin-options.php.

Go ahead! Leave your comment on this subject!

Fields marked with (*) are mandatory!

Spam Protection by WP-SpamFree

Resources
Goodies & Infos
Earn money with your photos

Tip: go to Shutterstock, submit your photos and make an extra income every month. - I do!

MAC

 

Categories

 

External Resources
Twitter Updates
    © 2010 - All rights reserved - WDMAC A Blog about Web Design & Development. WordPress development. Tutorials