PluginProbe
Polylang / 1.9.2
Polylang v1.9.2
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / nav-menu.php

nav-menu.php in Polylang 1.9.2, at include/nav-menu.php

80 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * manages custom menus translations
5 * common to admin and frontend for the customizer
6 *
7 * @since 1.7.7
8 */
9 class PLL_Nav_Menu {
10 public $model, $options;
11
12 /**
13 * constructor: setups filters and actions
14 *
15 * @since 1.7.7
16 *
17 * @param object $polylang
18 */
19 public function __construct( &$polylang ) {
20 $this->model = &$polylang->model;
21 $this->options = &$polylang->options;
22
23 // integration with WP customizer
24 add_action( 'customize_register', array( &$this, 'create_nav_menu_locations' ), 5 );
25 }
26
27 /**
28 * create temporary nav menu locations ( one per location and per language ) for all non-default language
29 * to do only one time
30 *
31 * @since 1.2
32 */
33 public function create_nav_menu_locations() {
34 static $once;
35 global $_wp_registered_nav_menus;
36
37 if ( isset( $_wp_registered_nav_menus ) && ! $once ) {
38 foreach ( $_wp_registered_nav_menus as $loc => $name ) {
39 foreach ( $this->model->get_languages_list() as $lang ) {
40 $arr[ $this->combine_location( $loc, $lang ) ] = $name . ' ' . $lang->name;
41 }
42 }
43
44 $_wp_registered_nav_menus = $arr;
45 $once = true;
46 }
47 }
48
49 /**
50 * creates a temporary nav menu location from a location and a language
51 *
52 * @since 1.8
53 *
54 * @param string $loc nav menu location
55 * @param object $lang
56 * @return string
57 */
58 public function combine_location( $loc, $lang ) {
59 return $loc . ( strpos( $loc, '___' ) || $this->options['default_lang'] === $lang->slug ? '' : '___' . $lang->slug );
60 }
61
62 /**
63 * get nav menu locations and language from a temporary locaction
64 *
65 * @since 1.8
66 *
67 * @param string $loc temporary location
68 * @return array
69 * 'location' => nav menu location
70 * 'lang' => language slug
71 */
72 public function explode_location( $loc ) {
73 $infos = explode( '___', $loc );
74 if ( 1 == count( $infos ) ) {
75 $infos[] = $this->options['default_lang'];
76 }
77 return array_combine( array( 'location', 'lang' ), $infos );
78 }
79 }
80