PLL_Nav_Menu

Manages custom menus translations common to admin and frontend for the customizer.

Defined (1)

The class is defined in the following location(s).

/include/nav-menu.php  
  1. class PLL_Nav_Menu { 
  2. public $model, $options; 
  3.  
  4. /** 
  5. * constructor: setups filters and actions 
  6. * @since 1.7.7 
  7. * @param object $polylang 
  8. */ 
  9. public function __construct( &$polylang ) { 
  10. $this->model = &$polylang->model; 
  11. $this->options = &$polylang->options; 
  12.  
  13. // integration with WP customizer 
  14. add_action( 'customize_register', array( $this, 'create_nav_menu_locations' ), 5 ); 
  15.  
  16. /** 
  17. * create temporary nav menu locations ( one per location and per language ) for all non-default language 
  18. * to do only one time 
  19. * @since 1.2 
  20. */ 
  21. public function create_nav_menu_locations() { 
  22. static $once; 
  23. global $_wp_registered_nav_menus; 
  24.  
  25. if ( isset( $_wp_registered_nav_menus ) && ! $once ) { 
  26. foreach ( $_wp_registered_nav_menus as $loc => $name ) { 
  27. foreach ( $this->model->get_languages_list() as $lang ) { 
  28. $arr[ $this->combine_location( $loc, $lang ) ] = $name . ' ' . $lang->name; 
  29.  
  30. $_wp_registered_nav_menus = $arr; 
  31. $once = true; 
  32.  
  33. /** 
  34. * creates a temporary nav menu location from a location and a language 
  35. * @since 1.8 
  36. * @param string $loc nav menu location 
  37. * @param object $lang 
  38. * @return string 
  39. */ 
  40. public function combine_location( $loc, $lang ) { 
  41. return $loc . ( strpos( $loc, '___' ) || $this->options['default_lang'] === $lang->slug ? '' : '___' . $lang->slug ); 
  42.  
  43. /** 
  44. * get nav menu locations and language from a temporary locaction 
  45. * @since 1.8 
  46. * @param string $loc temporary location 
  47. * @return array 
  48. * 'location' => nav menu location 
  49. * 'lang' => language slug 
  50. */ 
  51. public function explode_location( $loc ) { 
  52. $infos = explode( '___', $loc ); 
  53. if ( 1 == count( $infos ) ) { 
  54. $infos[] = $this->options['default_lang']; 
  55. return array_combine( array( 'location', 'lang' ), $infos );