equal
deleted
inserted
replaced
123 * |
123 * |
124 * Any supplied $args override class property defaults. |
124 * Any supplied $args override class property defaults. |
125 * |
125 * |
126 * @since 4.3.0 |
126 * @since 4.3.0 |
127 * |
127 * |
128 * @param WP_Customize_Manager $manager Bootstrap Customizer instance. |
128 * @throws Exception If $id is not valid for this setting type. |
129 * @param string $id An specific ID of the setting. Can be a |
129 * |
130 * theme mod or option name. |
130 * @param WP_Customize_Manager $manager Customizer bootstrap instance. |
|
131 * @param string $id A specific ID of the setting. |
|
132 * Can be a theme mod or option name. |
131 * @param array $args Optional. Setting arguments. |
133 * @param array $args Optional. Setting arguments. |
132 * |
|
133 * @throws Exception If $id is not valid for this setting type. |
|
134 */ |
134 */ |
135 public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) { |
135 public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) { |
136 if ( empty( $manager->nav_menus ) ) { |
136 if ( empty( $manager->nav_menus ) ) { |
137 throw new Exception( 'Expected WP_Customize_Manager::$nav_menus to be set.' ); |
137 throw new Exception( 'Expected WP_Customize_Manager::$nav_menus to be set.' ); |
138 } |
138 } |
154 * @see wp_get_nav_menu_object() |
154 * @see wp_get_nav_menu_object() |
155 * |
155 * |
156 * @return array Instance data. |
156 * @return array Instance data. |
157 */ |
157 */ |
158 public function value() { |
158 public function value() { |
159 if ( $this->is_previewed && $this->_previewed_blog_id === get_current_blog_id() ) { |
159 if ( $this->is_previewed && get_current_blog_id() === $this->_previewed_blog_id ) { |
160 $undefined = new stdClass(); // Symbol. |
160 $undefined = new stdClass(); // Symbol. |
161 $post_value = $this->post_value( $undefined ); |
161 $post_value = $this->post_value( $undefined ); |
162 |
162 |
163 if ( $undefined === $post_value ) { |
163 if ( $undefined === $post_value ) { |
164 $value = $this->_original_value; |
164 $value = $this->_original_value; |
177 |
177 |
178 $nav_menu_options = (array) get_option( 'nav_menu_options', array() ); |
178 $nav_menu_options = (array) get_option( 'nav_menu_options', array() ); |
179 $value['auto_add'] = false; |
179 $value['auto_add'] = false; |
180 |
180 |
181 if ( isset( $nav_menu_options['auto_add'] ) && is_array( $nav_menu_options['auto_add'] ) ) { |
181 if ( isset( $nav_menu_options['auto_add'] ) && is_array( $nav_menu_options['auto_add'] ) ) { |
182 $value['auto_add'] = in_array( $term->term_id, $nav_menu_options['auto_add'] ); |
182 $value['auto_add'] = in_array( $term->term_id, $nav_menu_options['auto_add'], true ); |
183 } |
183 } |
184 } |
184 } |
185 } |
185 } |
186 |
186 |
187 if ( ! is_array( $value ) ) { |
187 if ( ! is_array( $value ) ) { |
188 $value = $this->default; |
188 $value = $this->default; |
189 } |
189 } |
190 } |
190 } |
|
191 |
191 return $value; |
192 return $value; |
192 } |
193 } |
193 |
194 |
194 /** |
195 /** |
195 * Handle previewing the setting. |
196 * Handle previewing the setting. |
283 array( |
284 array( |
284 $args['orderby'] => 'ASC', |
285 $args['orderby'] => 'ASC', |
285 ) |
286 ) |
286 ); |
287 ); |
287 } |
288 } |
288 // @todo add support for $args['hide_empty'] === true |
289 // @todo Add support for $args['hide_empty'] === true. |
289 |
290 |
290 return $menus; |
291 return $menus; |
291 } |
292 } |
292 |
293 |
293 /** |
294 /** |
379 * Filters the nav_menu_options option to include this menu's auto_add preference. |
380 * Filters the nav_menu_options option to include this menu's auto_add preference. |
380 * |
381 * |
381 * @since 4.3.0 |
382 * @since 4.3.0 |
382 * |
383 * |
383 * @param array $nav_menu_options Nav menu options including auto_add. |
384 * @param array $nav_menu_options Nav menu options including auto_add. |
384 * @return array (Kaybe) modified nav menu options. |
385 * @return array (Maybe) modified nav menu options. |
385 */ |
386 */ |
386 public function filter_nav_menu_options( $nav_menu_options ) { |
387 public function filter_nav_menu_options( $nav_menu_options ) { |
387 if ( $this->_previewed_blog_id !== get_current_blog_id() ) { |
388 if ( get_current_blog_id() !== $this->_previewed_blog_id ) { |
388 return $nav_menu_options; |
389 return $nav_menu_options; |
389 } |
390 } |
390 |
391 |
391 $menu = $this->value(); |
392 $menu = $this->value(); |
392 $nav_menu_options = $this->filter_nav_menu_options_value( |
393 $nav_menu_options = $this->filter_nav_menu_options_value( |
515 $r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) ); |
516 $r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) ); |
516 $original_name = $menu_data['menu-name']; |
517 $original_name = $menu_data['menu-name']; |
517 $name_conflict_suffix = 1; |
518 $name_conflict_suffix = 1; |
518 while ( is_wp_error( $r ) && 'menu_exists' === $r->get_error_code() ) { |
519 while ( is_wp_error( $r ) && 'menu_exists' === $r->get_error_code() ) { |
519 $name_conflict_suffix += 1; |
520 $name_conflict_suffix += 1; |
520 /* translators: 1: original menu name, 2: duplicate count */ |
521 /* translators: 1: Original menu name, 2: Duplicate count. */ |
521 $menu_data['menu-name'] = sprintf( __( '%1$s (%2$d)' ), $original_name, $name_conflict_suffix ); |
522 $menu_data['menu-name'] = sprintf( __( '%1$s (%2$d)' ), $original_name, $name_conflict_suffix ); |
522 $r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) ); |
523 $r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) ); |
523 } |
524 } |
524 |
525 |
525 if ( is_wp_error( $r ) ) { |
526 if ( is_wp_error( $r ) ) { |
553 if ( ! preg_match( '/^nav_menu_locations\[/', $setting->id ) ) { |
554 if ( ! preg_match( '/^nav_menu_locations\[/', $setting->id ) ) { |
554 continue; |
555 continue; |
555 } |
556 } |
556 |
557 |
557 $post_value = $setting->post_value( null ); |
558 $post_value = $setting->post_value( null ); |
558 if ( ! is_null( $post_value ) && $this->previous_term_id === intval( $post_value ) ) { |
559 if ( ! is_null( $post_value ) && intval( $post_value ) === $this->previous_term_id ) { |
559 $this->manager->set_post_value( $setting->id, $this->term_id ); |
560 $this->manager->set_post_value( $setting->id, $this->term_id ); |
560 $setting->save(); |
561 $setting->save(); |
561 } |
562 } |
562 } |
563 } |
563 |
564 |
600 $nav_menu_options = (array) $nav_menu_options; |
601 $nav_menu_options = (array) $nav_menu_options; |
601 if ( ! isset( $nav_menu_options['auto_add'] ) ) { |
602 if ( ! isset( $nav_menu_options['auto_add'] ) ) { |
602 $nav_menu_options['auto_add'] = array(); |
603 $nav_menu_options['auto_add'] = array(); |
603 } |
604 } |
604 |
605 |
605 $i = array_search( $menu_id, $nav_menu_options['auto_add'] ); |
606 $i = array_search( $menu_id, $nav_menu_options['auto_add'], true ); |
|
607 |
606 if ( $auto_add && false === $i ) { |
608 if ( $auto_add && false === $i ) { |
607 array_push( $nav_menu_options['auto_add'], $this->term_id ); |
609 array_push( $nav_menu_options['auto_add'], $this->term_id ); |
608 } elseif ( ! $auto_add && false !== $i ) { |
610 } elseif ( ! $auto_add && false !== $i ) { |
609 array_splice( $nav_menu_options['auto_add'], $i, 1 ); |
611 array_splice( $nav_menu_options['auto_add'], $i, 1 ); |
610 } |
612 } |