PluginProbe
Polylang / 3.3
Polylang v3.3
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 +43 -17 2.83.3 View file →
@@ -9,11 +9,35 @@
9 9 *
10 10 * @since 1.7.7
11 11 */
12 12 class PLL_Nav_Menu {
13 - public $model, $options;
13 + /**
14 + * Stores the plugin options.
15 + *
16 + * @var array
17 + */
18 + public $options;
14 19
15 20 /**
21 + * @var PLL_Model
22 + */
23 + public $model;
24 +
25 + /**
26 + * Theme name.
27 + *
28 + * @var string
29 + */
30 + protected $theme;
31 +
32 + /**
33 + * Array of menu ids in a given language used when auto add pages to menus.
34 + *
35 + * @var int[]
36 + */
37 + protected $auto_add_menus = array();
38 +
39 + /**
16 40 * Constructor: setups filters and actions
17 41 *
18 42 * @since 1.7.7
19 43 *
@@ -38,13 +62,13 @@
38 62 * Assigns the title and label to the language switcher menu items
39 63 *
40 64 * @since 2.6
41 65 *
42 - * @param object $item Menu item.
43 - * @return object
66 + * @param stdClass $item Menu item.
67 + * @return stdClass
44 68 */
45 69 public function wp_setup_nav_menu_item( $item ) {
46 - if ( '#pll_switcher' === $item->url ) {
70 + if ( isset( $item->url ) && '#pll_switcher' === $item->url ) {
47 71 $item->post_title = __( 'Languages', 'polylang' );
48 72 $item->type_label = __( 'Language switcher', 'polylang' );
49 73 }
50 74 return $item;
@@ -54,8 +78,10 @@
54 78 * Create temporary nav menu locations ( one per location and per language ) for all non-default language
55 79 * to do only one time
56 80 *
57 81 * @since 1.2
82 + *
83 + * @return void
58 84 */
59 85 public function create_nav_menu_locations() {
60 86 static $once;
61 87 global $_wp_registered_nav_menus;
@@ -78,10 +104,10 @@
78 104 * Creates a temporary nav menu location from a location and a language
79 105 *
80 106 * @since 1.8
81 107 *
82 - * @param string $loc nav menu location
83 - * @param object $lang
108 + * @param string $loc Nav menu location.
109 + * @param PLL_Language $lang Language object.
84 110 * @return string
85 111 */
86 112 public function combine_location( $loc, $lang ) {
87 113 return $loc . ( strpos( $loc, '___' ) || $this->options['default_lang'] === $lang->slug ? '' : '___' . $lang->slug );
@@ -87,16 +113,17 @@
87 113 return $loc . ( strpos( $loc, '___' ) || $this->options['default_lang'] === $lang->slug ? '' : '___' . $lang->slug );
88 114 }
89 115
90 116 /**
91 - * Get nav menu locations and language from a temporary location
117 + * Get nav menu locations and language from a temporary location.
92 118 *
93 119 * @since 1.8
94 120 *
95 - * @param string $loc temporary location
96 - * @return array
97 - * 'location' => nav menu location
98 - * 'lang' => language slug
121 + * @param string $loc Temporary location.
122 + * @return string[] {
123 + * @type string $location Nav menu location.
124 + * @type string $lang Language code.
125 + * }
99 126 */
100 127 public function explode_location( $loc ) {
101 128 $infos = explode( '___', $loc );
102 129 if ( 1 == count( $infos ) ) {
@@ -118,15 +145,16 @@
118 145 return $options;
119 146 }
120 147
121 148 /**
122 - * Filters _wp_auto_add_pages_to_menu by language
149 + * Filters _wp_auto_add_pages_to_menu by language.
123 150 *
124 151 * @since 0.9.4
125 152 *
126 - * @param string $new_status Transition to this post status.
127 - * @param string $old_status Previous post status.
128 - * @param object $post Post data.
153 + * @param string $new_status Transition to this post status.
154 + * @param string $old_status Previous post status.
155 + * @param WP_Post $post Post object.
156 + * @return void
129 157 */
130 158 public function auto_add_pages_to_menu( $new_status, $old_status, $post ) {
131 159 if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type || ! empty( $post->post_parent ) ) {
132 160 return;
@@ -132,10 +160,8 @@
132 160 return;
133 161 }
134 162
135 163 if ( ! empty( $this->options['nav_menus'][ $this->theme ] ) ) {
136 - $this->auto_add_menus = array();
137 -
138 164 $lang = $this->model->post->get_language( $post->ID );
139 165 $lang = empty( $lang ) ? $this->options['default_lang'] : $lang->slug; // If the page has no language yet, the default language will be assigned
140 166
141 167 // Get all the menus in the page language