Changeset 13552
- Timestamp:
- 04/17/2024 10:00:08 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support-2024/functions.php
r13544 r13552 18 18 19 19 /** 20 * Get the local navigation menu object if it exists. 21 */ 22 function get_local_nav_menu_object() { 23 $local_nav_menu_locations = get_nav_menu_locations(); 24 $local_nav_menu_object = isset( $local_nav_menu_locations['local-navigation'] ) 25 ? wp_get_nav_menu_object( $local_nav_menu_locations['local-navigation'] ) 26 : false; 27 28 return $local_nav_menu_object; 29 } 30 31 /** 32 * Register a local nav menu for non-English forums, if it doesn't already exist. 33 */ 34 function register_local_nav_menu() { 35 if ( substr( get_locale(), 0, 2 ) === 'en' || get_local_nav_menu_object() ) { 36 return; 37 } 38 39 register_nav_menu( 'local-navigation', __( 'Local Navigation', 'wporg-forums' ) ); 40 } 41 add_action( 'after_setup_theme', 'register_local_nav_menu' ); 42 43 /** 20 44 * Provide a list of local navigation menus. 21 45 */ 22 46 function add_site_navigation_menus( $menus ) { 23 return array( 24 'forums' => array( 25 array( 26 'label' => __( 'Welcome to Support', 'wporg-forums' ), 27 'url' => '/welcome/', 47 if ( is_admin() ) { 48 return; 49 } 50 51 if ( substr( get_locale(), 0, 2 ) === 'en' ) { 52 return array( 53 'forums' => array( 54 array( 55 'label' => __( 'Welcome to Support', 'wporg-forums' ), 56 'url' => '/welcome/', 57 ), 58 array( 59 'label' => __( 'Guidelines', 'wporg-forums' ), 60 'url' => '/guidelines/', 61 ), 62 array( 63 'label' => __( 'Get Involved', 'wporg-forums' ), 64 'url' => 'https://make.wordpress.org/support/handbook/contributing-to-the-wordpress-forums/', 65 ) 28 66 ), 29 array( 30 'label' => __( 'Guidelines', 'wporg-forums' ), 31 'url' => '/guidelines/', 67 ); 68 } else { 69 $local_nav_menu_object = get_local_nav_menu_object(); 70 $menu_items_fallback = array( 71 'forums' => array( 72 array( 73 'label' => __( 'Get Involved', 'wporg-forums' ), 74 'url' => 'https://make.wordpress.org/support/handbook/contributing-to-the-wordpress-forums/', 75 ) 32 76 ), 33 array( 34 'label' => __( 'Get Involved', 'wporg-forums' ), 35 'url' => 'https://make.wordpress.org/support/handbook/contributing-to-the-wordpress-forums/', 77 ); 78 79 if ( ! $local_nav_menu_object ) { 80 return $menu_items_fallback; 81 } 82 83 $menu_items = wp_get_nav_menu_items( $local_nav_menu_object->term_id ); 84 85 if ( ! $menu_items || empty( $menu_items ) ) { 86 return $menu_items_fallback; 87 } 88 89 return array( 90 'forums' => array_map( 91 function( $menu_item ) { 92 return array( 93 'label' => esc_html( $menu_item->title ), 94 'url' => esc_url( $menu_item->url ) 95 ); 96 }, 97 // Limit local nav items to 3 98 array_slice( $menu_items, 0, 3 ) 36 99 ) 37 ) ,38 );100 ); 101 } 39 102 } 40 103 add_filter( 'wporg_block_navigation_menus', '\add_site_navigation_menus' );
Note: See TracChangeset
for help on using the changeset viewer.