WordPress.org

Ready to get started?Download WordPress

Forums

Locking up admin panels rather than hidding them? (5 posts)

  1. Zambrano Sergio
    Member
    Posted 4 years ago #

    Is there a way to keep all the panels in place for all users, and locking-up the links instead of not-showing them?

    I'd like to show off what they are missing by not reaching a high contribution level.

    I can hack the core code if needed.

    Does anybody know where to start?

    Thanks!

  2. Brandon Allen
    Member
    Posted 4 years ago #

    If you're willing to get dirty, you can do this without hacking the core. What you'll end up doing is disabling them menu items, and the adding them back, but having them link to '#' instead of the proper page. Then take a look at the add_menu_class() function, where you can add a css class like 'disabled', so that you can style the disable menu items. I've included some links below to get you started. The wp-admin/menu.php is where you'll find the add_menu_class function, along with the other code referenced in the tutorial.

    tutorial:
    http://hungred.com/how-to/remove-wordpress-admin-menu-affecting-wordpress-core-system/

    wp-admin/menu.php:
    http://lab.yukei.net/wp-code/wp-admin/menu.php.source.html#l233

  3. Zambrano Sergio
    Member
    Posted 4 years ago #

    Thanks for the tutorial, now I know how the menus are added/removed. But I couldn't find a centralized place where I can change the links to the different admin panels.

    I’d like to change the unset/remove actions for a "replace links" one, to make them all “#”.

    Do you know how I can replace the URL’s for a few? (or the ones out of the privileges)

    Thanks.

  4. Zambrano Sergio
    Member
    Posted 4 years ago #

    I assumed, as the linked tutorial said, the menu is constructed with ALL the submenus first, and commented all the functions after that, and any other with the word "unset" in them, and the submenus are not rendered. I believe there should be a way to show them WITHOUT adding full capabilities to my subscriber.

    I just got the titles (e.g. "Settings") but nothing inside it.
    Also, I see the url is the element [2] in the submenus. Can I just change the value of the filename.php for each of them in one of the loops of that script to change the link to "#" in all the restricted ones?

  5. Brandon Allen
    Member
    Posted 4 years ago #

    Can I just change the value of the filename.php for each of them in one of the loops of that script to change the link to "#" in all the restricted ones?

    Right, that's what I was getting at. It looks like you might be able to change the two unset function, to str_replace, and be done with it. For instance, change
    unset($submenu[$menu_item[2]][$i]);
    to
    str_replace($restricted, "#", $submenu[$menu_item[2]][$i][2]);
    and
    unset($menu[key($menu)]);
    to
    str_replace($restricted, "#", $menu_item[2]);

    As far as showing the menus to users without change their caps, you'll have to manually add the menus back. The menus aren't filterable, so you can't change what menus are hidden based on which capability. You'll have to add the missing menus based on contribution level, and what menus the users are missing. The 'Pages' menu is $menu[20], so what you might try, is redeclaring that menu at say, $menu[21], only for those users that are missing the menu. What I'm describing would look like this

    $menu[21] = array( __('Pages'), 'edit_pages', 'edit-pages.php', '', 'menu-top', 'menu-pages', 'div' );
    33	    $submenu['edit-pages.php'][5] = array( __('Edit'), 'edit_pages', 'edit-pages.php' );
    34	    /* translators: add new page */
    35	    $submenu['edit-pages.php'][10] = array( _x('Add New', 'page'), 'edit_pages', 'page-new.php' );

    That should get you started I think. I may also be totally wrong, and if I am, let me know. We'll keep brainstorming, and I'll actually try code before I post it. I really think you'll be good though.

Topic Closed

This topic has been closed to new replies.

About this Topic