wp/wp-includes/customize/class-wp-customize-nav-menu-setting.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   139 
   139 
   140 		if ( ! preg_match( self::ID_PATTERN, $id, $matches ) ) {
   140 		if ( ! preg_match( self::ID_PATTERN, $id, $matches ) ) {
   141 			throw new Exception( "Illegal widget setting ID: $id" );
   141 			throw new Exception( "Illegal widget setting ID: $id" );
   142 		}
   142 		}
   143 
   143 
   144 		$this->term_id = intval( $matches['id'] );
   144 		$this->term_id = (int) $matches['id'];
   145 
   145 
   146 		parent::__construct( $manager, $id, $args );
   146 		parent::__construct( $manager, $id, $args );
   147 	}
   147 	}
   148 
   148 
   149 	/**
   149 	/**
   431 		$value   = array_merge( $default, $value );
   431 		$value   = array_merge( $default, $value );
   432 		$value   = wp_array_slice_assoc( $value, array_keys( $default ) );
   432 		$value   = wp_array_slice_assoc( $value, array_keys( $default ) );
   433 
   433 
   434 		$value['name']        = trim( esc_html( $value['name'] ) ); // This sanitization code is used in wp-admin/nav-menus.php.
   434 		$value['name']        = trim( esc_html( $value['name'] ) ); // This sanitization code is used in wp-admin/nav-menus.php.
   435 		$value['description'] = sanitize_text_field( $value['description'] );
   435 		$value['description'] = sanitize_text_field( $value['description'] );
   436 		$value['parent']      = max( 0, intval( $value['parent'] ) );
   436 		$value['parent']      = max( 0, (int) $value['parent'] );
   437 		$value['auto_add']    = ! empty( $value['auto_add'] );
   437 		$value['auto_add']    = ! empty( $value['auto_add'] );
   438 
   438 
   439 		if ( '' === $value['name'] ) {
   439 		if ( '' === $value['name'] ) {
   440 			$value['name'] = _x( '(unnamed)', 'Missing menu name.' );
   440 			$value['name'] = _x( '(unnamed)', 'Missing menu name.' );
   441 		}
   441 		}
   554 				if ( ! preg_match( '/^nav_menu_locations\[/', $setting->id ) ) {
   554 				if ( ! preg_match( '/^nav_menu_locations\[/', $setting->id ) ) {
   555 					continue;
   555 					continue;
   556 				}
   556 				}
   557 
   557 
   558 				$post_value = $setting->post_value( null );
   558 				$post_value = $setting->post_value( null );
   559 				if ( ! is_null( $post_value ) && intval( $post_value ) === $this->previous_term_id ) {
   559 				if ( ! is_null( $post_value ) && (int) $post_value === $this->previous_term_id ) {
   560 					$this->manager->set_post_value( $setting->id, $this->term_id );
   560 					$this->manager->set_post_value( $setting->id, $this->term_id );
   561 					$setting->save();
   561 					$setting->save();
   562 				}
   562 				}
   563 			}
   563 			}
   564 
   564 
   568 				if ( ! $nav_menu_widget_setting || ! preg_match( '/^widget_nav_menu\[/', $nav_menu_widget_setting->id ) ) {
   568 				if ( ! $nav_menu_widget_setting || ! preg_match( '/^widget_nav_menu\[/', $nav_menu_widget_setting->id ) ) {
   569 					continue;
   569 					continue;
   570 				}
   570 				}
   571 
   571 
   572 				$widget_instance = $nav_menu_widget_setting->post_value(); // Note that this calls WP_Customize_Widgets::sanitize_widget_instance().
   572 				$widget_instance = $nav_menu_widget_setting->post_value(); // Note that this calls WP_Customize_Widgets::sanitize_widget_instance().
   573 				if ( empty( $widget_instance['nav_menu'] ) || intval( $widget_instance['nav_menu'] ) !== $this->previous_term_id ) {
   573 				if ( empty( $widget_instance['nav_menu'] ) || (int) $widget_instance['nav_menu'] !== $this->previous_term_id ) {
   574 					continue;
   574 					continue;
   575 				}
   575 				}
   576 
   576 
   577 				$widget_instance['nav_menu'] = $this->term_id;
   577 				$widget_instance['nav_menu'] = $this->term_id;
   578 				$updated_widget_instance     = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance );
   578 				$updated_widget_instance     = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance );