wp/wp-includes/class-walker-page.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    33 	 * @var array
    33 	 * @var array
    34 	 *
    34 	 *
    35 	 * @see Walker::$db_fields
    35 	 * @see Walker::$db_fields
    36 	 * @todo Decouple this.
    36 	 * @todo Decouple this.
    37 	 */
    37 	 */
    38 	public $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
    38 	public $db_fields = array(
       
    39 		'parent' => 'post_parent',
       
    40 		'id'     => 'ID',
       
    41 	);
    39 
    42 
    40 	/**
    43 	/**
    41 	 * Outputs the beginning of the current level in the tree before elements are output.
    44 	 * Outputs the beginning of the current level in the tree before elements are output.
    42 	 *
    45 	 *
    43 	 * @since 2.1.0
    46 	 * @since 2.1.0
    55 			$n = "\n";
    58 			$n = "\n";
    56 		} else {
    59 		} else {
    57 			$t = '';
    60 			$t = '';
    58 			$n = '';
    61 			$n = '';
    59 		}
    62 		}
    60 		$indent = str_repeat( $t, $depth );
    63 		$indent  = str_repeat( $t, $depth );
    61 		$output .= "{$n}{$indent}<ul class='children'>{$n}";
    64 		$output .= "{$n}{$indent}<ul class='children'>{$n}";
    62 	}
    65 	}
    63 
    66 
    64 	/**
    67 	/**
    65 	 * Outputs the end of the current level in the tree after elements are output.
    68 	 * Outputs the end of the current level in the tree after elements are output.
    79 			$n = "\n";
    82 			$n = "\n";
    80 		} else {
    83 		} else {
    81 			$t = '';
    84 			$t = '';
    82 			$n = '';
    85 			$n = '';
    83 		}
    86 		}
    84 		$indent = str_repeat( $t, $depth );
    87 		$indent  = str_repeat( $t, $depth );
    85 		$output .= "{$indent}</ul>{$n}";
    88 		$output .= "{$indent}</ul>{$n}";
    86 	}
    89 	}
    87 
    90 
    88 	/**
    91 	/**
    89 	 * Outputs the beginning of the current element in the tree.
    92 	 * Outputs the beginning of the current element in the tree.
   125 			if ( $page->ID == $current_page ) {
   128 			if ( $page->ID == $current_page ) {
   126 				$css_class[] = 'current_page_item';
   129 				$css_class[] = 'current_page_item';
   127 			} elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
   130 			} elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
   128 				$css_class[] = 'current_page_parent';
   131 				$css_class[] = 'current_page_parent';
   129 			}
   132 			}
   130 		} elseif ( $page->ID == get_option('page_for_posts') ) {
   133 		} elseif ( $page->ID == get_option( 'page_for_posts' ) ) {
   131 			$css_class[] = 'current_page_parent';
   134 			$css_class[] = 'current_page_parent';
   132 		}
   135 		}
   133 
   136 
   134 		/**
   137 		/**
   135 		 * Filters the list of CSS classes to include with each page item in the list.
   138 		 * Filters the list of CSS classes to include with each page item in the list.
   136 		 *
   139 		 *
   137 		 * @since 2.8.0
   140 		 * @since 2.8.0
   138 		 *
   141 		 *
   139 		 * @see wp_list_pages()
   142 		 * @see wp_list_pages()
   140 		 *
   143 		 *
   141 		 * @param array   $css_class    An array of CSS classes to be applied
   144 		 * @param string[] $css_class    An array of CSS classes to be applied to each list item.
   142 		 *                              to each list item.
   145 		 * @param WP_Post  $page         Page data object.
   143 		 * @param WP_Post $page         Page data object.
   146 		 * @param int      $depth        Depth of page, used for padding.
   144 		 * @param int     $depth        Depth of page, used for padding.
   147 		 * @param array    $args         An array of arguments.
   145 		 * @param array   $args         An array of arguments.
   148 		 * @param int      $current_page ID of the current page.
   146 		 * @param int     $current_page ID of the current page.
       
   147 		 */
   149 		 */
   148 		$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
   150 		$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
       
   151 		$css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
   149 
   152 
   150 		if ( '' === $page->post_title ) {
   153 		if ( '' === $page->post_title ) {
   151 			/* translators: %d: ID of a post */
   154 			/* translators: %d: ID of a post */
   152 			$page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
   155 			$page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
   153 		}
   156 		}
   154 
   157 
   155 		$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
   158 		$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
   156 		$args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
   159 		$args['link_after']  = empty( $args['link_after'] ) ? '' : $args['link_after'];
   157 
   160 
   158 		$atts = array();
   161 		$atts                 = array();
   159 		$atts['href'] = get_permalink( $page->ID );
   162 		$atts['href']         = get_permalink( $page->ID );
       
   163 		$atts['aria-current'] = ( $page->ID == $current_page ) ? 'page' : '';
   160 
   164 
   161 		/**
   165 		/**
   162 		 * Filters the HTML attributes applied to a page menu item's anchor element.
   166 		 * Filters the HTML attributes applied to a page menu item's anchor element.
   163 		 *
   167 		 *
   164 		 * @since 4.8.0
   168 		 * @since 4.8.0
   165 		 *
   169 		 *
   166 		 * @param array $atts {
   170 		 * @param array $atts {
   167 		 *     The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
   171 		 *     The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
   168 		 *
   172 		 *
   169 		 *     @type string $href The href attribute.
   173 		 *     @type string $href         The href attribute.
       
   174 		 *     @type string $aria_current The aria-current attribute.
   170 		 * }
   175 		 * }
   171 		 * @param WP_Post $page         Page data object.
   176 		 * @param WP_Post $page         Page data object.
   172 		 * @param int     $depth        Depth of page, used for padding.
   177 		 * @param int     $depth        Depth of page, used for padding.
   173 		 * @param array   $args         An array of arguments.
   178 		 * @param array   $args         An array of arguments.
   174 		 * @param int     $current_page ID of the current page.
   179 		 * @param int     $current_page ID of the current page.
   176 		$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
   181 		$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
   177 
   182 
   178 		$attributes = '';
   183 		$attributes = '';
   179 		foreach ( $atts as $attr => $value ) {
   184 		foreach ( $atts as $attr => $value ) {
   180 			if ( ! empty( $value ) ) {
   185 			if ( ! empty( $value ) ) {
   181 				$value = esc_attr( $value );
   186 				$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
   182 				$attributes .= ' ' . $attr . '="' . $value . '"';
   187 				$attributes .= ' ' . $attr . '="' . $value . '"';
   183 			}
   188 			}
   184 		}
   189 		}
   185 
   190 
   186 		$output .= $indent . sprintf(
   191 		$output .= $indent . sprintf(
   187 			'<li class="%s"><a%s>%s%s%s</a>',
   192 			'<li%s><a%s>%s%s%s</a>',
   188 			$css_classes,
   193 			$css_classes,
   189 			$attributes,
   194 			$attributes,
   190 			$args['link_before'],
   195 			$args['link_before'],
   191 			/** This filter is documented in wp-includes/post-template.php */
   196 			/** This filter is documented in wp-includes/post-template.php */
   192 			apply_filters( 'the_title', $page->post_title, $page->ID ),
   197 			apply_filters( 'the_title', $page->post_title, $page->ID ),
   199 			} else {
   204 			} else {
   200 				$time = $page->post_date;
   205 				$time = $page->post_date;
   201 			}
   206 			}
   202 
   207 
   203 			$date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
   208 			$date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
   204 			$output .= " " . mysql2date( $date_format, $time );
   209 			$output     .= ' ' . mysql2date( $date_format, $time );
   205 		}
   210 		}
   206 	}
   211 	}
   207 
   212 
   208 	/**
   213 	/**
   209 	 * Outputs the end of the current element in the tree.
   214 	 * Outputs the end of the current element in the tree.