Plugin Directory

Changeset 728325


Ignore:
Timestamp:
06/19/2013 11:07:35 AM (13 years ago)
Author:
davidmosterd
Message:

2.3, with some feedback from community

Location:
codepress-menu
Files:
11 added
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • codepress-menu/tags/2.3/codepress-menu.php

    r682297 r728325  
    33Plugin Name:        Codepress Menu
    44Plugin URI:         http://wordpress.org/extend/plugins/codepress-menu/
    5 Version:            2.2.2
    6 Description:        A more flexible take on displaying a WordPress menu in your theme
     5Version:            2.3
     6Description:        Extensions for WordPress nav-menu's
    77Author:             Codepress
    88License:            GPLv2
     
    2424*/
    2525
    26 class Codepress_Walker_Nav_Menu extends Walker_Nav_Menu {
     26define( 'CODEPRESS_MENU_URL', plugin_dir_url( __FILE__ ) );
     27define( 'CODEPRESS_MENU_DIR', plugin_dir_path( __FILE__ ) );
    2728
    28     /**
    29      * Indents any object as long as it has a unique id and that of its parent.
    30      *
    31      * @since 2.1
    32      */
    33     protected function indent( array $items, $root, $parent, $id ) {
    34         $indent = array();
    35 
    36         foreach( $items as $k => $item ) {
    37             if ( $item->$parent == $root ) {
    38                 unset( $items[$k] );
    39 
    40                 $item->children = $this->indent( $items, $item->$id, $parent, $id );
    41                 $indent[]       = $item;
    42             }
    43         }
    44 
    45         return $indent;
    46     }
    47 
    48     /**
    49      * Only return a level from a indented list of items.
    50      *
    51      * @since 2.0
    52      */
    53     protected function level( $items, $level, $reached = 1, $currentBranch = false)  {
    54 
    55         foreach ( $items as $item ) {
    56 
    57             // check for current or ancestor
    58             if ( $item->current || $item->current_item_ancestor || $currentBranch ) {
    59 
    60                 // catch top level
    61                 if ( $level == 1 && $reached == 1 )
    62                     return array( $item );
    63 
    64                 // catch all other levels
    65                 if ( $reached + 1 == $level && ! empty( $item->children ) )
    66                     return $item->children;
    67 
    68                 if ( ! empty( $item->children ) )
    69                    return $this->level( $item->children, $level, $reached + 1, true );
    70             }
    71         }
    72 
    73         return array();
    74     }
    75 
    76     /**
    77      * Unset children exceeding max depth.
    78      *
    79      * @since 1.0
    80      */
    81     protected function depth( $items, $depth, $level = 1 ) {
    82 
    83         foreach( $items as $k => $item ) {
    84             // unset the children, or go a level deeper
    85             if ( $depth == $level )
    86                 unset( $items[$k]->children );
    87             elseif ( ! empty( $item->children ) )
    88                 $items[$k]->children = $this->depth( $item->children, $depth, $level + 1 );
    89         }
    90 
    91         return $items;
    92     }
    93 
    94     /**
    95      * Adds classes to the first and last item of each level.
    96      *
    97      * @since 2.1
    98      */
    99     protected function mark_first_and_last( array $items ) {
    100         $i = 0;
    101 
    102         foreach( $items as $item ) {
    103             if ( $i == 0 )
    104                 $item->classes[] = 'first';
    105 
    106             $i++;
    107 
    108             if ( $i == count( $items ) )
    109                 $item->classes[] = 'last';
    110 
    111             if ( ! empty( $item->children ) )
    112                 $item->children = $this->mark_first_and_last( $item->children );
    113         }
    114 
    115         return $items;
    116     }
    117 
    118     /**
    119      * Sanitize classes by removing some of them and renaming others.
    120      *
    121      * @since 2.1.1
    122      */
    123     protected function sanitize_classes( $items, $args ) {
    124 
    125         foreach( $items as $k => $item ) {
    126             // always allow custom assigned classes
    127             $filtered = (array) get_post_meta( $item->ID, '_menu_item_classes', true );
    128             $allowed  = array();
    129 
    130             if ( $args->classes == 'minimal' || $args->classes == 'simple' ) {
    131                 $allowed = array(
    132                     'current-menu-item'     => 'current',
    133                     'current-menu-parent'   => 'current-parent',
    134                     'current-menu-ancestor' => 'current-ancestor',
    135                 );
    136             }
    137 
    138             if ( $args->classes == 'sanitize' ) {
    139                 $allowed = array(
    140                     'current-menu-item',
    141                     'current-menu-parent',
    142                     'current-menu-ancestor',
    143                 );
    144             }
    145 
    146             if ( $args->classes == 'simple' || $args->classes == 'sanitize' )
    147                 $allowed = array_merge( $allowed, array( 'first', 'last' ) );
    148 
    149             $allowed = apply_filters( 'codepress_menu_filter_classes', $allowed, $item, $args );
    150 
    151             // check for class that is allowed, but needs transformation
    152             foreach ( $item->classes as $class ) {
    153                 if ( array_key_exists( $class, $allowed ) )
    154                     $filtered[] = $allowed[$class];
    155                  elseif ( in_array( $class, $allowed ) )
    156                     $filtered[] = $class;
    157             }
    158 
    159             $items[$k]->classes = array_filter( $filtered );;
    160         }
    161 
    162         return $items;
    163     }
    164 
    165     /**
    166      * Walkers have a walk method, makes sense.
    167      *
    168      * @since 2.1
    169      */
    170     public function walk( $items, $depth, $args ) {
    171         $items = $this->indent( $items, 0, $this->db_fields['parent'], $this->db_fields['id'] );
    172 
    173         if ( $args->level )
    174             $items = $this->level( $items, $args->level );
    175 
    176         $items = $this->depth( $items, $depth );
    177 
    178         if ( $args->classes ) {
    179             $items = $this->mark_first_and_last( $items );
    180             $items = $this->sanitize_classes( $items, $args );
    181         }
    182 
    183         $items = apply_filters( 'codepress_menu_filter', $items );
    184 
    185         return $this->get_menu( $items, $args );
    186     }
    187 
    188     /**
    189      * Get the menu string.
    190      *
    191      * @return string
    192      * @since 1.0
    193      */
    194     public function get_menu( $items, $args, $level = 1 ) {
    195         $output = '';
    196 
    197         if ( $level > 1)
    198             $this->start_lvl( $output, 0, $args );
    199 
    200         foreach( $items as $item ) {
    201             $this->start_el( $output, $item, 0, $args );
    202 
    203             if ( ! empty( $item->children ) )
    204                 $output .= $this->get_menu( $item->children, $args, $level + 1);
    205 
    206             $this->end_el( $output, $item, 0, $args );
    207         }
    208 
    209         if ( $level > 1 )
    210             $this->end_lvl( $output, 0, $args );
    211 
    212         return $output;
    213     }
    214 }
     29require CODEPRESS_MENU_DIR . '/class-codepress-menu-walker.php';
    21530
    21631/**
    217  * Init Codepress Menu.
     32 * Init Codepress Menu
    21833 *
    21934 * @uses apply_filters() To ignore certain theme_locations.
     
    24459
    24560    $defaults = array(
    246         'level'     => 0,
    247         'classes'   => false,
    248         'walker'    => new Codepress_Walker_Nav_Menu,
     61        'level'  => 0,
     62        'walker' => new Codepress_Menu_Walker,
    24963    );
    25064
    25165    foreach( $defaults as $option => $default ) {
    252         if ( empty( $args[$option] ) )
    253             $args[$option] = $default;
     66        if ( empty( $args[ $option ] ) )
     67            $args[ $option ] = $default;
    25468    }
    25569
     
    25771}
    25872add_filter( 'wp_nav_menu_args', 'codepress_menu_init' );
     73
     74/**
     75 * Enqueue styles and scripts for nav-menus page
     76 *
     77 * @since 2.3
     78 */
     79function codepress_menu_admin_scripts() {
     80    global $pagenow;
     81
     82    if ( 'nav-menus.php' != $pagenow )
     83        return;
     84
     85    wp_enqueue_script( 'codepress-menu-backend', CODEPRESS_MENU_URL . '/js/codepress-menu.js' );
     86    wp_enqueue_style( 'codepress-menu-backend', CODEPRESS_MENU_URL . '/css/codepress-menu.css' );
     87}
     88add_action( 'admin_print_scripts', 'codepress_menu_admin_scripts' );
     89
     90/**
     91 * Show or hide the menu-item delete link
     92 *
     93 * @since 2.3
     94 */
     95function codepress_menu_manage_nav_menus_columns( $columns ) {
     96    $columns['codepress-menu-simple-delete'] = __( 'Remove' );
     97
     98    return $columns;
     99}
     100add_filter( 'manage_nav-menus_columns', 'codepress_menu_manage_nav_menus_columns', 15 );
  • codepress-menu/tags/2.3/readme.txt

    r682419 r728325  
    33Tags: wordpress, menu, submenu, walker, navigation, nav, php, code, wp_nav_menu
    44Requires at least: 3.1
    5 Tested up to: 3.4.2
    6 Stable tag: 2.2.2
     5Tested up to: 3.5
     6Stable tag: 2.3
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
    99
    10 Allows you to display a sub-menu, it's depth from there on and gives you good control over the menu-item classes.
     10Allows you to display a sub-menu, it's depth from there on and gives you control over the menu-item classes.
    1111
    1212== Description ==
    1313
    14 Uses the native [wp_nav_menu()](http://codex.wordpress.org/Function_Reference/wp_nav_menu) but adds some flexibility.
     14Uses the native [wp_nav_menu()](http://codex.wordpress.org/Function_Reference/wp_nav_menu). Add parameters to the wp_nav_menu() to enable functionality.
     15Also, ships with one-click delete menu-items in the WordPress admin. Turned off or on using the screen-options. Sweet.
    1516
    16 No configuration required, just adds runtime parameters that can be used to tweak your menu.
     17**Examples**
    1718
    1819This will get the first sub-menu from the active branch and 2 levels beyond (menu + sub-menu + sub-menu):
     
    2425`
    2526
    26 Show the whole current branch only:
     27Show the current branch only:
    2728`
    2829wp_nav_menu( array(
     
    3132`
    3233
    33 Aimed on simple use on various use cases:
     34Aimed on simple use in various use cases:
    3435`
    3536// display first level in the header
     
    4546`
    4647
    47 Another feature is it's controll over the css classes that are assigned. You might be faced with a html template of
    48 which you cannot or do not want to change the css.
    49 
    50 Use the filter 'codepress_menu_filter_classes' to define your own class filter.
    51 
    52 There are also a few pre-configured variants:
    53 
    54 * *sanitize* Keep only a few WordPress classes (li.current-menu-item, li.current-menu-parent, li.current-menu-ancestor) and add li.first and li.last.
    55 * *simple* Use even more simple classes (li.current, li.current-parent, li.current-ancestor) and add li.first and li.last.
    56 * *minimal* Same as simple, but without list.first and li.last because you target modern browsers only or use something like selectivizr
    57 * *false* Do nothing (default)
     48Another feature is it's control over the css classes that are given to a menu-item. You might be faced with css selectors
     49which you cannot change. The 'codepress_menu_filter_classes' filter can be used in your functions.php to set the class property:
    5850
    5951`
    60 wp_nav_menu( array(
    61     'classes' => 'sanitize'
    62 ));
     52/**
     53 * Change the classes of a menu item
     54 *
     55 * @param array $classes List current classes
     56 * @param object $item Current menu item
     57 * @param array $items Current list of items (per level)
     58 * @param integer $k Key of the current item in $items
     59 */
     60function codepress_menu_item_classes( $classes, $item, $items, $k ) {
     61    // mark the first item
     62    if ( reset( $items ) == $items[ $k ] )
     63        $classes[] = 'first';
     64
     65    // mark the last item
     66    if ( end( $items ) == $items[ $k ] )
     67        $classes[] = 'last';
     68
     69    // map the WordPress default 'current-menu-item' class to 'active'
     70    if ( in_array( 'current-menu-item', $classes ) )
     71        $classes[] = 'active';
     72
     73    return $classes;
     74}
     75add_filter( 'codepress_menu_item_classes', 'codepress_menu_item_classes', 10, 4 );
    6376`
     77
     78**Simple Menu Delete**
     79
     80It ships with one-click delete menu-items within WordPress.
     81This functionality was integrated from our Simple Menu Delete plugin and enhanced a bit:
     82
     83* Turned off or on using the screen-options.
     84* Display is more in line with WordPress's way of delete-links.
     85* Works exactly the same now as the nested delete-link which is a click further inside the menu item.
     86
     87
     88== Frequently Asked Questions ==
     89
     90= Something is broken? Have an idea? =
     91
     92Great! Tell us, we'd love to help out.
    6493
    6594
    6695== Upgrade Notice ==
     96
     97= 2.3 =
     98We have decided that current way of changing of classes is not in line with how WordPress works. We still offer the possibility to influence the
     99classes, but the focus is on using giving you the tools to do what you want 'codepress_menu_item_classes'. See the examples for some intended usage.
    67100
    68101= 2.2 =
     
    75108== Installation ==
    76109
    77 Search for `codepress menu` as described in the [Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins) or
     110Search for `codepress menu` as described in the [Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins)
     111
     112or
    78113
    791141. Upload codepress-menu to the `/wp-content/plugins/` directory
     
    84119
    85120== Changelog ==
     121
     122= 2.3 =
     123
     124* A more WordPress-like implementation of the menu-item class control.
     125* Added a one-click delete for menu-items in wp-admin (can be turned off or on via screen options).
     126* Minor code cleanup, adhering WordPress standards... even more!
    86127
    87128= 2.2.2 =
  • codepress-menu/trunk/codepress-menu.php

    r682297 r728325  
    33Plugin Name:        Codepress Menu
    44Plugin URI:         http://wordpress.org/extend/plugins/codepress-menu/
    5 Version:            2.2.2
    6 Description:        A more flexible take on displaying a WordPress menu in your theme
     5Version:            2.3
     6Description:        Extensions for WordPress nav-menu's
    77Author:             Codepress
    88License:            GPLv2
     
    2424*/
    2525
    26 class Codepress_Walker_Nav_Menu extends Walker_Nav_Menu {
     26define( 'CODEPRESS_MENU_URL', plugin_dir_url( __FILE__ ) );
     27define( 'CODEPRESS_MENU_DIR', plugin_dir_path( __FILE__ ) );
    2728
    28     /**
    29      * Indents any object as long as it has a unique id and that of its parent.
    30      *
    31      * @since 2.1
    32      */
    33     protected function indent( array $items, $root, $parent, $id ) {
    34         $indent = array();
    35 
    36         foreach( $items as $k => $item ) {
    37             if ( $item->$parent == $root ) {
    38                 unset( $items[$k] );
    39 
    40                 $item->children = $this->indent( $items, $item->$id, $parent, $id );
    41                 $indent[]       = $item;
    42             }
    43         }
    44 
    45         return $indent;
    46     }
    47 
    48     /**
    49      * Only return a level from a indented list of items.
    50      *
    51      * @since 2.0
    52      */
    53     protected function level( $items, $level, $reached = 1, $currentBranch = false)  {
    54 
    55         foreach ( $items as $item ) {
    56 
    57             // check for current or ancestor
    58             if ( $item->current || $item->current_item_ancestor || $currentBranch ) {
    59 
    60                 // catch top level
    61                 if ( $level == 1 && $reached == 1 )
    62                     return array( $item );
    63 
    64                 // catch all other levels
    65                 if ( $reached + 1 == $level && ! empty( $item->children ) )
    66                     return $item->children;
    67 
    68                 if ( ! empty( $item->children ) )
    69                    return $this->level( $item->children, $level, $reached + 1, true );
    70             }
    71         }
    72 
    73         return array();
    74     }
    75 
    76     /**
    77      * Unset children exceeding max depth.
    78      *
    79      * @since 1.0
    80      */
    81     protected function depth( $items, $depth, $level = 1 ) {
    82 
    83         foreach( $items as $k => $item ) {
    84             // unset the children, or go a level deeper
    85             if ( $depth == $level )
    86                 unset( $items[$k]->children );
    87             elseif ( ! empty( $item->children ) )
    88                 $items[$k]->children = $this->depth( $item->children, $depth, $level + 1 );
    89         }
    90 
    91         return $items;
    92     }
    93 
    94     /**
    95      * Adds classes to the first and last item of each level.
    96      *
    97      * @since 2.1
    98      */
    99     protected function mark_first_and_last( array $items ) {
    100         $i = 0;
    101 
    102         foreach( $items as $item ) {
    103             if ( $i == 0 )
    104                 $item->classes[] = 'first';
    105 
    106             $i++;
    107 
    108             if ( $i == count( $items ) )
    109                 $item->classes[] = 'last';
    110 
    111             if ( ! empty( $item->children ) )
    112                 $item->children = $this->mark_first_and_last( $item->children );
    113         }
    114 
    115         return $items;
    116     }
    117 
    118     /**
    119      * Sanitize classes by removing some of them and renaming others.
    120      *
    121      * @since 2.1.1
    122      */
    123     protected function sanitize_classes( $items, $args ) {
    124 
    125         foreach( $items as $k => $item ) {
    126             // always allow custom assigned classes
    127             $filtered = (array) get_post_meta( $item->ID, '_menu_item_classes', true );
    128             $allowed  = array();
    129 
    130             if ( $args->classes == 'minimal' || $args->classes == 'simple' ) {
    131                 $allowed = array(
    132                     'current-menu-item'     => 'current',
    133                     'current-menu-parent'   => 'current-parent',
    134                     'current-menu-ancestor' => 'current-ancestor',
    135                 );
    136             }
    137 
    138             if ( $args->classes == 'sanitize' ) {
    139                 $allowed = array(
    140                     'current-menu-item',
    141                     'current-menu-parent',
    142                     'current-menu-ancestor',
    143                 );
    144             }
    145 
    146             if ( $args->classes == 'simple' || $args->classes == 'sanitize' )
    147                 $allowed = array_merge( $allowed, array( 'first', 'last' ) );
    148 
    149             $allowed = apply_filters( 'codepress_menu_filter_classes', $allowed, $item, $args );
    150 
    151             // check for class that is allowed, but needs transformation
    152             foreach ( $item->classes as $class ) {
    153                 if ( array_key_exists( $class, $allowed ) )
    154                     $filtered[] = $allowed[$class];
    155                  elseif ( in_array( $class, $allowed ) )
    156                     $filtered[] = $class;
    157             }
    158 
    159             $items[$k]->classes = array_filter( $filtered );;
    160         }
    161 
    162         return $items;
    163     }
    164 
    165     /**
    166      * Walkers have a walk method, makes sense.
    167      *
    168      * @since 2.1
    169      */
    170     public function walk( $items, $depth, $args ) {
    171         $items = $this->indent( $items, 0, $this->db_fields['parent'], $this->db_fields['id'] );
    172 
    173         if ( $args->level )
    174             $items = $this->level( $items, $args->level );
    175 
    176         $items = $this->depth( $items, $depth );
    177 
    178         if ( $args->classes ) {
    179             $items = $this->mark_first_and_last( $items );
    180             $items = $this->sanitize_classes( $items, $args );
    181         }
    182 
    183         $items = apply_filters( 'codepress_menu_filter', $items );
    184 
    185         return $this->get_menu( $items, $args );
    186     }
    187 
    188     /**
    189      * Get the menu string.
    190      *
    191      * @return string
    192      * @since 1.0
    193      */
    194     public function get_menu( $items, $args, $level = 1 ) {
    195         $output = '';
    196 
    197         if ( $level > 1)
    198             $this->start_lvl( $output, 0, $args );
    199 
    200         foreach( $items as $item ) {
    201             $this->start_el( $output, $item, 0, $args );
    202 
    203             if ( ! empty( $item->children ) )
    204                 $output .= $this->get_menu( $item->children, $args, $level + 1);
    205 
    206             $this->end_el( $output, $item, 0, $args );
    207         }
    208 
    209         if ( $level > 1 )
    210             $this->end_lvl( $output, 0, $args );
    211 
    212         return $output;
    213     }
    214 }
     29require CODEPRESS_MENU_DIR . '/class-codepress-menu-walker.php';
    21530
    21631/**
    217  * Init Codepress Menu.
     32 * Init Codepress Menu
    21833 *
    21934 * @uses apply_filters() To ignore certain theme_locations.
     
    24459
    24560    $defaults = array(
    246         'level'     => 0,
    247         'classes'   => false,
    248         'walker'    => new Codepress_Walker_Nav_Menu,
     61        'level'  => 0,
     62        'walker' => new Codepress_Menu_Walker,
    24963    );
    25064
    25165    foreach( $defaults as $option => $default ) {
    252         if ( empty( $args[$option] ) )
    253             $args[$option] = $default;
     66        if ( empty( $args[ $option ] ) )
     67            $args[ $option ] = $default;
    25468    }
    25569
     
    25771}
    25872add_filter( 'wp_nav_menu_args', 'codepress_menu_init' );
     73
     74/**
     75 * Enqueue styles and scripts for nav-menus page
     76 *
     77 * @since 2.3
     78 */
     79function codepress_menu_admin_scripts() {
     80    global $pagenow;
     81
     82    if ( 'nav-menus.php' != $pagenow )
     83        return;
     84
     85    wp_enqueue_script( 'codepress-menu-backend', CODEPRESS_MENU_URL . '/js/codepress-menu.js' );
     86    wp_enqueue_style( 'codepress-menu-backend', CODEPRESS_MENU_URL . '/css/codepress-menu.css' );
     87}
     88add_action( 'admin_print_scripts', 'codepress_menu_admin_scripts' );
     89
     90/**
     91 * Show or hide the menu-item delete link
     92 *
     93 * @since 2.3
     94 */
     95function codepress_menu_manage_nav_menus_columns( $columns ) {
     96    $columns['codepress-menu-simple-delete'] = __( 'Remove' );
     97
     98    return $columns;
     99}
     100add_filter( 'manage_nav-menus_columns', 'codepress_menu_manage_nav_menus_columns', 15 );
  • codepress-menu/trunk/readme.txt

    r682419 r728325  
    33Tags: wordpress, menu, submenu, walker, navigation, nav, php, code, wp_nav_menu
    44Requires at least: 3.1
    5 Tested up to: 3.4.2
    6 Stable tag: 2.2.2
     5Tested up to: 3.5
     6Stable tag: 2.3
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
    99
    10 Allows you to display a sub-menu, it's depth from there on and gives you good control over the menu-item classes.
     10Allows you to display a sub-menu, it's depth from there on and gives you control over the menu-item classes.
    1111
    1212== Description ==
    1313
    14 Uses the native [wp_nav_menu()](http://codex.wordpress.org/Function_Reference/wp_nav_menu) but adds some flexibility.
     14Uses the native [wp_nav_menu()](http://codex.wordpress.org/Function_Reference/wp_nav_menu). Add parameters to the wp_nav_menu() to enable functionality.
     15Also, ships with one-click delete menu-items in the WordPress admin. Turned off or on using the screen-options. Sweet.
    1516
    16 No configuration required, just adds runtime parameters that can be used to tweak your menu.
     17**Examples**
    1718
    1819This will get the first sub-menu from the active branch and 2 levels beyond (menu + sub-menu + sub-menu):
     
    2425`
    2526
    26 Show the whole current branch only:
     27Show the current branch only:
    2728`
    2829wp_nav_menu( array(
     
    3132`
    3233
    33 Aimed on simple use on various use cases:
     34Aimed on simple use in various use cases:
    3435`
    3536// display first level in the header
     
    4546`
    4647
    47 Another feature is it's controll over the css classes that are assigned. You might be faced with a html template of
    48 which you cannot or do not want to change the css.
    49 
    50 Use the filter 'codepress_menu_filter_classes' to define your own class filter.
    51 
    52 There are also a few pre-configured variants:
    53 
    54 * *sanitize* Keep only a few WordPress classes (li.current-menu-item, li.current-menu-parent, li.current-menu-ancestor) and add li.first and li.last.
    55 * *simple* Use even more simple classes (li.current, li.current-parent, li.current-ancestor) and add li.first and li.last.
    56 * *minimal* Same as simple, but without list.first and li.last because you target modern browsers only or use something like selectivizr
    57 * *false* Do nothing (default)
     48Another feature is it's control over the css classes that are given to a menu-item. You might be faced with css selectors
     49which you cannot change. The 'codepress_menu_filter_classes' filter can be used in your functions.php to set the class property:
    5850
    5951`
    60 wp_nav_menu( array(
    61     'classes' => 'sanitize'
    62 ));
     52/**
     53 * Change the classes of a menu item
     54 *
     55 * @param array $classes List current classes
     56 * @param object $item Current menu item
     57 * @param array $items Current list of items (per level)
     58 * @param integer $k Key of the current item in $items
     59 */
     60function codepress_menu_item_classes( $classes, $item, $items, $k ) {
     61    // mark the first item
     62    if ( reset( $items ) == $items[ $k ] )
     63        $classes[] = 'first';
     64
     65    // mark the last item
     66    if ( end( $items ) == $items[ $k ] )
     67        $classes[] = 'last';
     68
     69    // map the WordPress default 'current-menu-item' class to 'active'
     70    if ( in_array( 'current-menu-item', $classes ) )
     71        $classes[] = 'active';
     72
     73    return $classes;
     74}
     75add_filter( 'codepress_menu_item_classes', 'codepress_menu_item_classes', 10, 4 );
    6376`
     77
     78**Simple Menu Delete**
     79
     80It ships with one-click delete menu-items within WordPress.
     81This functionality was integrated from our Simple Menu Delete plugin and enhanced a bit:
     82
     83* Turned off or on using the screen-options.
     84* Display is more in line with WordPress's way of delete-links.
     85* Works exactly the same now as the nested delete-link which is a click further inside the menu item.
     86
     87
     88== Frequently Asked Questions ==
     89
     90= Something is broken? Have an idea? =
     91
     92Great! Tell us, we'd love to help out.
    6493
    6594
    6695== Upgrade Notice ==
     96
     97= 2.3 =
     98We have decided that current way of changing of classes is not in line with how WordPress works. We still offer the possibility to influence the
     99classes, but the focus is on using giving you the tools to do what you want 'codepress_menu_item_classes'. See the examples for some intended usage.
    67100
    68101= 2.2 =
     
    75108== Installation ==
    76109
    77 Search for `codepress menu` as described in the [Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins) or
     110Search for `codepress menu` as described in the [Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins)
     111
     112or
    78113
    791141. Upload codepress-menu to the `/wp-content/plugins/` directory
     
    84119
    85120== Changelog ==
     121
     122= 2.3 =
     123
     124* A more WordPress-like implementation of the menu-item class control.
     125* Added a one-click delete for menu-items in wp-admin (can be turned off or on via screen options).
     126* Minor code cleanup, adhering WordPress standards... even more!
    86127
    87128= 2.2.2 =
Note: See TracChangeset for help on using the changeset viewer.