wp/wp-includes/class-walker-page.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
   102 	 * @param array   $args              Optional. Array of arguments. Default empty array.
   102 	 * @param array   $args              Optional. Array of arguments. Default empty array.
   103 	 * @param int     $current_object_id Optional. ID of the current page. Default 0.
   103 	 * @param int     $current_object_id Optional. ID of the current page. Default 0.
   104 	 */
   104 	 */
   105 	public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
   105 	public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
   106 		// Restores the more descriptive, specific name for use within this method.
   106 		// Restores the more descriptive, specific name for use within this method.
   107 		$page            = $data_object;
   107 		$page = $data_object;
       
   108 
   108 		$current_page_id = $current_object_id;
   109 		$current_page_id = $current_object_id;
   109 
   110 
   110 		if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
   111 		if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
   111 			$t = "\t";
   112 			$t = "\t";
   112 			$n = "\n";
   113 			$n = "\n";
   131 
   132 
   132 			if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
   133 			if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
   133 				$css_class[] = 'current_page_ancestor';
   134 				$css_class[] = 'current_page_ancestor';
   134 			}
   135 			}
   135 
   136 
   136 			if ( $page->ID == $current_page_id ) {
   137 			if ( $page->ID === (int) $current_page_id ) {
   137 				$css_class[] = 'current_page_item';
   138 				$css_class[] = 'current_page_item';
   138 			} elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
   139 			} elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
   139 				$css_class[] = 'current_page_parent';
   140 				$css_class[] = 'current_page_parent';
   140 			}
   141 			}
   141 		} elseif ( get_option( 'page_for_posts' ) == $page->ID ) {
   142 		} elseif ( (int) get_option( 'page_for_posts' ) === $page->ID ) {
   142 			$css_class[] = 'current_page_parent';
   143 			$css_class[] = 'current_page_parent';
   143 		}
   144 		}
   144 
   145 
   145 		/**
   146 		/**
   146 		 * Filters the list of CSS classes to include with each page item in the list.
   147 		 * Filters the list of CSS classes to include with each page item in the list.
   166 		$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
   167 		$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
   167 		$args['link_after']  = empty( $args['link_after'] ) ? '' : $args['link_after'];
   168 		$args['link_after']  = empty( $args['link_after'] ) ? '' : $args['link_after'];
   168 
   169 
   169 		$atts                 = array();
   170 		$atts                 = array();
   170 		$atts['href']         = get_permalink( $page->ID );
   171 		$atts['href']         = get_permalink( $page->ID );
   171 		$atts['aria-current'] = ( $page->ID == $current_page_id ) ? 'page' : '';
   172 		$atts['aria-current'] = ( $page->ID === (int) $current_page_id ) ? 'page' : '';
   172 
   173 
   173 		/**
   174 		/**
   174 		 * Filters the HTML attributes applied to a page menu item's anchor element.
   175 		 * Filters the HTML attributes applied to a page menu item's anchor element.
   175 		 *
   176 		 *
   176 		 * @since 4.8.0
   177 		 * @since 4.8.0
   239 			$t = '';
   240 			$t = '';
   240 			$n = '';
   241 			$n = '';
   241 		}
   242 		}
   242 		$output .= "</li>{$n}";
   243 		$output .= "</li>{$n}";
   243 	}
   244 	}
   244 
       
   245 }
   245 }