PluginProbe
Polylang / 2.5
Polylang v2.5
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
← All changes | include/nav-menu.php +0 -72 2.82.5 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages custom menus translations
8 5 * Common to admin and frontend for the customizer
@@ -22,36 +19,13 @@
22 19 public function __construct( &$polylang ) {
23 20 $this->model = &$polylang->model;
24 21 $this->options = &$polylang->options;
25 22
26 - $this->theme = get_option( 'stylesheet' );
27 -
28 - add_filter( 'wp_setup_nav_menu_item', array( $this, 'wp_setup_nav_menu_item' ) );
29 -
30 23 // Integration with WP customizer
31 24 add_action( 'customize_register', array( $this, 'create_nav_menu_locations' ), 5 );
32 -
33 - // Filter _wp_auto_add_pages_to_menu by language
34 - add_action( 'transition_post_status', array( $this, 'auto_add_pages_to_menu' ), 5, 3 ); // before _wp_auto_add_pages_to_menu
35 25 }
36 26
37 27 /**
38 - * Assigns the title and label to the language switcher menu items
39 - *
40 - * @since 2.6
41 - *
42 - * @param object $item Menu item.
43 - * @return object
44 - */
45 - public function wp_setup_nav_menu_item( $item ) {
46 - if ( '#pll_switcher' === $item->url ) {
47 - $item->post_title = __( 'Languages', 'polylang' );
48 - $item->type_label = __( 'Language switcher', 'polylang' );
49 - }
50 - return $item;
51 - }
52 -
53 - /**
54 28 * Create temporary nav menu locations ( one per location and per language ) for all non-default language
55 29 * to do only one time
56 30 *
57 31 * @since 1.2
@@ -59,10 +33,8 @@
59 33 public function create_nav_menu_locations() {
60 34 static $once;
61 35 global $_wp_registered_nav_menus;
62 36
63 - $arr = array();
64 -
65 37 if ( isset( $_wp_registered_nav_menus ) && ! $once ) {
66 38 foreach ( $_wp_registered_nav_menus as $loc => $name ) {
67 39 foreach ( $this->model->get_languages_list() as $lang ) {
68 40 $arr[ $this->combine_location( $loc, $lang ) ] = $name . ' ' . $lang->name;
@@ -102,50 +74,6 @@
102 74 if ( 1 == count( $infos ) ) {
103 75 $infos[] = $this->options['default_lang'];
104 76 }
105 77 return array_combine( array( 'location', 'lang' ), $infos );
106 - }
107 -
108 - /**
109 - * Filters the option nav_menu_options for auto added pages to menu
110 - *
111 - * @since 0.9.4
112 - *
113 - * @param array $options
114 - * @return array Modified options
115 - */
116 - public function nav_menu_options( $options ) {
117 - $options['auto_add'] = array_intersect( $options['auto_add'], $this->auto_add_menus );
118 - return $options;
119 - }
120 -
121 - /**
122 - * Filters _wp_auto_add_pages_to_menu by language
123 - *
124 - * @since 0.9.4
125 - *
126 - * @param string $new_status Transition to this post status.
127 - * @param string $old_status Previous post status.
128 - * @param object $post Post data.
129 - */
130 - public function auto_add_pages_to_menu( $new_status, $old_status, $post ) {
131 - if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type || ! empty( $post->post_parent ) ) {
132 - return;
133 - }
134 -
135 - if ( ! empty( $this->options['nav_menus'][ $this->theme ] ) ) {
136 - $this->auto_add_menus = array();
137 -
138 - $lang = $this->model->post->get_language( $post->ID );
139 - $lang = empty( $lang ) ? $this->options['default_lang'] : $lang->slug; // If the page has no language yet, the default language will be assigned
140 -
141 - // Get all the menus in the page language
142 - foreach ( $this->options['nav_menus'][ $this->theme ] as $loc ) {
143 - if ( ! empty( $loc[ $lang ] ) ) {
144 - $this->auto_add_menus[] = $loc[ $lang ];
145 - }
146 - }
147 -
148 - add_filter( 'option_nav_menu_options', array( $this, 'nav_menu_options' ) );
149 - }
150 78 }
151 79 }