• Resolved Ethan O’Sullivan

    (@ethanosullivan)


    I’m working on an option page for my plugin and I’m trying to display all of the current admin menu items, including custom menus, in a list of checkboxes. So far, I’ve been able to use the following to get the list of the menu items:

    global $menu;
    foreach ( $menu as $group => $items ) {
        foreach ( $items as $position => $item ) {
            // echo $item;
            printf(
                '<input type="checkbox" name="menu_option_name[menu_items]" id="menu_items" value="menu_items" %s> <label for="menu_items">' . $item . '</label>',
                ( isset( $this->menu_options['menu_items'] ) && $this->menu_options['menu_items'] === 'menu_items' ) ? 'checked' : ''
            );
            echo '<br>';
        }
    }

    Which gives this output:
    https://s32.postimg.org/3oej4pbdh/menu_array.png

    How can I have this list just the file name (ex: index.php)? I noticed that the menu’s file name is on the [2] position of each array.

Viewing 1 replies (of 1 total)
  • Thread Starter Ethan O’Sullivan

    (@ethanosullivan)

    Solved. Use the following to get a list of just the name and the filename:

    
    global $menu;
    foreach ( $menu as $group => $item ) {
        if ( ! empty( $item[0] ) ) {
            echo $item[0] . " > " . $item[2] . "<br>";
        }
    }
    

    As a result:

    
    Dashboard > index.php
    Posts > edit.php
    Media > upload.php
    Pages > edit.php?post_type=page
    Comments 0 > edit-comments.php
    Test > edit.php?post_type=test
    Appearance > themes.php
    Plugins 0 > plugins.php
    Users > users.php
    Tools > tools.php
    Settings > options-general.php
    ...
    
Viewing 1 replies (of 1 total)
  • The topic ‘Display admin menu items in checkboxes’ is closed to new replies.