Making WordPress.org

Changeset 6174


Ignore:
Timestamp:
11/27/2017 06:45:12 PM (7 years ago)
Author:
obenland
Message:

Rosetta: Add Download Button handler.

Makes a link to the downloads page a button-style link like on wp.org.

See #2861.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/class-plugin.php

    r5339 r6174  
    3434    private function __construct() {
    3535        add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ], 1 );
     36        add_action( 'wp_nav_menu_objects', [ $this, 'download_button_menu_item' ], 11 );
    3637
    3738        $this->sites = [
     
    6263        // Customizations for all sites.
    6364        $this->filter_date_options();
     65    }
     66
     67    /**
     68     * Turns a menu item that links to the Downloads page into a download button.
     69     *
     70     * @param array $menu_items The menu items, sorted by each menu item's menu order.
     71     * @return array
     72     */
     73    public function download_button_menu_item( $menu_items ) {
     74        foreach ( $menu_items as $menu_item ) {
     75            if ( false !== stripos( $menu_item->url, 'download/' ) || 'page-templates/download.php' === get_page_template_slug( $menu_item->object_id ) ) {
     76                $menu_item->classes = array_merge( $menu_item->classes, ['button', 'button-primary', 'download'] );
     77                $menu_item->title   = _x( 'Download WordPress', 'Menu title', 'rosetta' );
     78                break;
     79            }
     80        }
     81
     82        return $menu_items;
    6483    }
    6584
Note: See TracChangeset for help on using the changeset viewer.