WordPress.org

Making WordPress.org


Ignore:
Timestamp:
11/09/2017 09:58:20 PM (2 years ago)
Author:
obenland
Message:

Main: Turn download menu items into buttons

This will emulate w.org's behavior by turning any link to txt-download into a download button.

H/t netweb, SergeyBiryukov.
See #2861.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/functions.php

    r6091 r6100  
    4646
    4747/**
     48 * Turns a menu item that links to the Downloads page into a download button.
     49 *
     50 * @param array $menu_items The menu items, sorted by each menu item's menu order.
     51 * @return array
     52 */
     53function nav_menu_objects( $menu_items ) {
     54    foreach ( $menu_items as $menu_item ) {
     55        if ( false !== stripos( $menu_item->url, 'txt-download' ) ) {
     56            $menu_item->classes = array_merge( $menu_item->classes, ['button', 'button-primary', 'download'] );
     57            $menu_item->title   = _x( 'Download WordPress', 'Menu title', 'wporg' );
     58            break;
     59        }
     60    }
     61
     62    return $menu_items;
     63}
     64add_action( 'wp_nav_menu_objects', __NAMESPACE__ . '\nav_menu_objects' );
     65
     66/**
    4867 * Custom template tags.
    4968 */
Note: See TracChangeset for help on using the changeset viewer.