wp/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   169 
   169 
   170 		if ( ! preg_match( self::ID_PATTERN, $id, $matches ) ) {
   170 		if ( ! preg_match( self::ID_PATTERN, $id, $matches ) ) {
   171 			throw new Exception( "Illegal widget setting ID: $id" );
   171 			throw new Exception( "Illegal widget setting ID: $id" );
   172 		}
   172 		}
   173 
   173 
   174 		$this->post_id = intval( $matches['id'] );
   174 		$this->post_id = (int) $matches['id'];
   175 		add_action( 'wp_update_nav_menu_item', array( $this, 'flush_cached_value' ), 10, 2 );
   175 		add_action( 'wp_update_nav_menu_item', array( $this, 'flush_cached_value' ), 10, 2 );
   176 
   176 
   177 		parent::__construct( $manager, $id, $args );
   177 		parent::__construct( $manager, $id, $args );
   178 
   178 
   179 		// Ensure that an initially-supplied value is valid.
   179 		// Ensure that an initially-supplied value is valid.
   366 			}
   366 			}
   367 		}
   367 		}
   368 
   368 
   369 		foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) {
   369 		foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) {
   370 			if ( ! is_int( $this->value[ $key ] ) ) {
   370 			if ( ! is_int( $this->value[ $key ] ) ) {
   371 				$this->value[ $key ] = intval( $this->value[ $key ] );
   371 				$this->value[ $key ] = (int) $this->value[ $key ];
   372 			}
   372 			}
   373 		}
   373 		}
   374 		foreach ( array( 'classes', 'xfn' ) as $key ) {
   374 		foreach ( array( 'classes', 'xfn' ) as $key ) {
   375 			if ( is_array( $this->value[ $key ] ) ) {
   375 			if ( is_array( $this->value[ $key ] ) ) {
   376 				$this->value[ $key ] = implode( ' ', $this->value[ $key ] );
   376 				$this->value[ $key ] = implode( ' ', $this->value[ $key ] );
   603 		}
   603 		}
   604 		if ( $item->title ) {
   604 		if ( $item->title ) {
   605 			$item->post_title = $item->title;
   605 			$item->post_title = $item->title;
   606 		}
   606 		}
   607 
   607 
       
   608 		// 'classes' should be an array, as in wp_setup_nav_menu_item().
       
   609 		if ( isset( $item->classes ) && is_scalar( $item->classes ) ) {
       
   610 			$item->classes = explode( ' ', $item->classes );
       
   611 		}
       
   612 
   608 		$item->ID    = $this->post_id;
   613 		$item->ID    = $this->post_id;
   609 		$item->db_id = $this->post_id;
   614 		$item->db_id = $this->post_id;
   610 		$post        = new WP_Post( (object) $item );
   615 		$post        = new WP_Post( (object) $item );
   611 
   616 
   612 		if ( empty( $post->post_author ) ) {
   617 		if ( empty( $post->post_author ) ) {
   682 			'nav_menu_term_id' => 0,
   687 			'nav_menu_term_id' => 0,
   683 			'_invalid'         => false,
   688 			'_invalid'         => false,
   684 		);
   689 		);
   685 		$menu_item_value             = array_merge( $default, $menu_item_value );
   690 		$menu_item_value             = array_merge( $default, $menu_item_value );
   686 		$menu_item_value             = wp_array_slice_assoc( $menu_item_value, array_keys( $default ) );
   691 		$menu_item_value             = wp_array_slice_assoc( $menu_item_value, array_keys( $default ) );
   687 		$menu_item_value['position'] = intval( $menu_item_value['position'] );
   692 		$menu_item_value['position'] = (int) $menu_item_value['position'];
   688 
   693 
   689 		foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) {
   694 		foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) {
   690 			// Note we need to allow negative-integer IDs for previewed objects not inserted yet.
   695 			// Note we need to allow negative-integer IDs for previewed objects not inserted yet.
   691 			$menu_item_value[ $key ] = intval( $menu_item_value[ $key ] );
   696 			$menu_item_value[ $key ] = (int) $menu_item_value[ $key ];
   692 		}
   697 		}
   693 
   698 
   694 		foreach ( array( 'type', 'object', 'target' ) as $key ) {
   699 		foreach ( array( 'type', 'object', 'target' ) as $key ) {
   695 			$menu_item_value[ $key ] = sanitize_key( $menu_item_value[ $key ] );
   700 			$menu_item_value[ $key ] = sanitize_key( $menu_item_value[ $key ] );
   696 		}
   701 		}
   796 					$this->update_status = 'error';
   801 					$this->update_status = 'error';
   797 					$this->update_error  = new WP_Error( 'nav_menu_setting_failure' );
   802 					$this->update_error  = new WP_Error( 'nav_menu_setting_failure' );
   798 					return;
   803 					return;
   799 				}
   804 				}
   800 
   805 
   801 				if ( intval( $value['nav_menu_term_id'] ) !== $nav_menu_setting->previous_term_id ) {
   806 				if ( (int) $value['nav_menu_term_id'] !== $nav_menu_setting->previous_term_id ) {
   802 					$this->update_status = 'error';
   807 					$this->update_status = 'error';
   803 					$this->update_error  = new WP_Error( 'unexpected_previous_term_id' );
   808 					$this->update_error  = new WP_Error( 'unexpected_previous_term_id' );
   804 					return;
   809 					return;
   805 				}
   810 				}
   806 
   811 
   822 					$this->update_status = 'error';
   827 					$this->update_status = 'error';
   823 					$this->update_error  = new WP_Error( 'nav_menu_item_setting_failure' );
   828 					$this->update_error  = new WP_Error( 'nav_menu_item_setting_failure' );
   824 					return;
   829 					return;
   825 				}
   830 				}
   826 
   831 
   827 				if ( intval( $value['menu_item_parent'] ) !== $parent_nav_menu_item_setting->previous_post_id ) {
   832 				if ( (int) $value['menu_item_parent'] !== $parent_nav_menu_item_setting->previous_post_id ) {
   828 					$this->update_status = 'error';
   833 					$this->update_status = 'error';
   829 					$this->update_error  = new WP_Error( 'unexpected_previous_post_id' );
   834 					$this->update_error  = new WP_Error( 'unexpected_previous_post_id' );
   830 					return;
   835 					return;
   831 				}
   836 				}
   832 
   837