Making WordPress.org

Changeset 14104


Ignore:
Timestamp:
10/10/2024 03:43:26 PM (2 years ago)
Author:
ryelle
Message:

Forums: Navigation: Add "Log in" link to local nav

Fixes https://github.com/WordPress/wordpress.org/issues/227, closes https://github.com/WordPress/wordpress.org/pull/394, See https://github.com/WordPress/wporg-mu-plugins/issues/647.

File:
1 edited

Legend:

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

    r13635 r14104  
    5555
    5656        if ( substr( get_locale(), 0, 2 ) === 'en' ) {
    57                 return array(
    58                         'forums' => array(
    59                                 array(
    60                                         'label' => __( 'Welcome to Support', 'wporg-forums' ),
    61                                         'url' => '/welcome/',
    62                                 ),
    63                                 array(
    64                                         'label' => __( 'Guidelines', 'wporg-forums' ),
    65                                         'url' => '/guidelines/',
    66                                 ),
    67                                 array(
    68                                         'label' => __( 'Get Involved', 'wporg-forums' ),
    69                                         'url' => 'https://make.wordpress.org/support/handbook/contributing-to-the-wordpress-forums/',
    70                                 )
     57                $menu = array(
     58                        array(
     59                                'label' => __( 'Welcome to Support', 'wporg-forums' ),
     60                                'url' => '/welcome/',
     61                        ),
     62                        array(
     63                                'label' => __( 'Guidelines', 'wporg-forums' ),
     64                                'url' => '/guidelines/',
     65                        ),
     66                        array(
     67                                'label' => __( 'Get involved', 'wporg-forums' ),
     68                                'url' => 'https://make.wordpress.org/support/handbook/contributing-to-the-wordpress-forums/',
    7169                        ),
    7270                );
    7371        } else {
    7472                $local_nav_menu_object = wporg_support_get_local_nav_menu_object();
    75                 $menu_items_fallback = array(
    76                         'forums' => array(
    77                                  array(
    78                                         'label' => __( 'Get Involved', 'wporg-forums' ),
    79                                         'url' => 'https://make.wordpress.org/support/handbook/contributing-to-the-wordpress-forums/',
    80                                 )
     73                $menu = array(
     74                        array(
     75                                'label' => __( 'Get involved', 'wporg-forums' ),
     76                                'url' => 'https://make.wordpress.org/support/handbook/contributing-to-the-wordpress-forums/',
    8177                        ),
    8278                );
    8379
     80                if ( ! is_user_logged_in() ) {
     81                        global $wp;
     82                        $redirect_url = home_url( $wp->request );
     83                        $menu[] = array(
     84                                'label' => __( 'Log in', 'wporg-forums' ),
     85                                'url' => wp_login_url( $redirect_url ),
     86                                'className' => 'has-separator',
     87                        );
     88                }
     89
    8490                if ( ! $local_nav_menu_object ) {
    85                         return $menu_items_fallback;
     91                        return array( 'forums' => $menu );
    8692                }
    8793
     
    8995
    9096                if ( ! $menu_items || empty( $menu_items ) ) {
    91                         return $menu_items_fallback;
    92                 }
    93 
    94                 return array(
    95                         'forums' => array_map(
    96                                 function( $menu_item ) {
    97                                         return array(
    98                                                 'label' => esc_html( $menu_item->title ),
    99                                                 'url' => esc_url( $menu_item->url )
    100                                         );
    101                                 },
    102                                 // Limit local nav items to 3
    103                                 array_slice( $menu_items, 0, 3 )
    104                         )
     97                        return array( 'forums' => $menu );
     98                }
     99
     100                $menu = array_map(
     101                        function( $menu_item ) {
     102                                return array(
     103                                        'label' => esc_html( $menu_item->title ),
     104                                        'url' => esc_url( $menu_item->url )
     105                                );
     106                        },
     107                        // Limit local nav items to 3
     108                        array_slice( $menu_items, 0, 3 )
    105109                );
    106110        }
     111
     112        if ( ! is_user_logged_in() ) {
     113                global $wp;
     114                $redirect_url = home_url( $wp->request );
     115                $menu[] = array(
     116                        'label' => __( 'Log in', 'wporg-forums' ),
     117                        'url' => wp_login_url( $redirect_url ),
     118                        'className' => 'has-separator',
     119                );
     120        }
     121
     122        return array( 'forums' => $menu );
    107123}
    108124add_filter( 'wporg_block_navigation_menus', 'wporg_support_add_site_navigation_menus' );
Note: See TracChangeset for help on using the changeset viewer.