| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Manages custom menus translations as well as the language switcher menu item on admin side |
| 8 | 5 | * |
| @@ -96,13 +93,10 @@ | ||
| 96 | 93 | |
| 97 | 94 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 98 | 95 | wp_enqueue_script( 'pll_nav_menu', plugins_url( '/js/nav-menu' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery' ), POLYLANG_VERSION ); |
| 99 | 96 | |
| 100 | - $data = array( | |
| 101 | - 'strings' => PLL_Switcher::get_switcher_options( 'menu', 'string' ), // The strings for the options | |
| 102 | - 'title' => __( 'Languages', 'polylang' ), // The title | |
| 103 | - 'val' => array(), | |
| 104 | - ); | |
| 97 | + $data['strings'] = PLL_Switcher::get_switcher_options( 'menu', 'string' ); // The strings for the options | |
| 98 | + $data['title'] = __( 'Languages', 'polylang' ); // The title | |
| 105 | 99 | |
| 106 | 100 | // Get all language switcher menu items |
| 107 | 101 | $items = get_posts( |
| 108 | 102 | array( |
| @@ -114,8 +108,9 @@ | ||
| 114 | 108 | ) |
| 115 | 109 | ); |
| 116 | 110 | |
| 117 | 111 | // The options values for the language switcher |
| 112 | + $data['val'] = array(); | |
| 118 | 113 | foreach ( $items as $item ) { |
| 119 | 114 | $data['val'][ $item ] = get_post_meta( $item, '_pll_menu_item', true ); |
| 120 | 115 | } |
| 121 | 116 | |
| @@ -147,9 +142,9 @@ | ||
| 147 | 142 | update_post_meta( $menu_item_db_id, '_pll_menu_item', $options ); |
| 148 | 143 | } |
| 149 | 144 | } |
| 150 | 145 | else { |
| 151 | - foreach ( array_keys( $options ) as $opt ) { | |
| 146 | + foreach ( $options as $opt => $v ) { | |
| 152 | 147 | $options[ $opt ] = empty( $_POST[ 'menu-item-' . $opt ][ $menu_item_db_id ] ) ? 0 : 1; |
| 153 | 148 | } |
| 154 | 149 | update_post_meta( $menu_item_db_id, '_pll_menu_item', $options ); // Allow us to easily identify our nav menu item |
| 155 | 150 | } |
| @@ -164,8 +159,10 @@ | ||
| 164 | 159 | * @param array $locations nav menu locations |
| 165 | 160 | * @return array |
| 166 | 161 | */ |
| 167 | 162 | public function update_nav_menu_locations( $locations ) { |
| 163 | + $default = $this->options['default_lang']; | |
| 164 | + | |
| 168 | 165 | // Extract language and menu from locations |
| 169 | 166 | foreach ( $locations as $loc => $menu ) { |
| 170 | 167 | $infos = $this->explode_location( $loc ); |
| 171 | 168 | $this->options['nav_menus'][ $this->theme ][ $infos['location'] ][ $infos['lang'] ] = $menu; |
| @@ -234,9 +231,9 @@ | ||
| 234 | 231 | $menus = is_array( $menus ) ? array_merge( $locations, $menus ) : $locations; |
| 235 | 232 | } |
| 236 | 233 | |
| 237 | 234 | if ( is_array( $menus ) ) { |
| 238 | - foreach ( array_keys( $menus ) as $loc ) { | |
| 235 | + foreach ( $menus as $loc => $menu ) { | |
| 239 | 236 | foreach ( $this->model->get_languages_list() as $lang ) { |
| 240 | 237 | if ( ! empty( $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ] ) && term_exists( $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ], 'nav_menu' ) ) { |
| 241 | 238 | $menus[ $this->combine_location( $loc, $lang ) ] = $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ]; |
| 242 | 239 | } |