Edit File by line
/home/barbar84/www/wp-inclu...
File: class-walker-page.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Post API: Walker_Page class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Template
[5] Fix | Delete
* @since 4.4.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core walker class used to create an HTML list of pages.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 2.1.0
[12] Fix | Delete
*
[13] Fix | Delete
* @see Walker
[14] Fix | Delete
*/
[15] Fix | Delete
class Walker_Page extends Walker {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* What the class handles.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 2.1.0
[21] Fix | Delete
* @var string
[22] Fix | Delete
*
[23] Fix | Delete
* @see Walker::$tree_type
[24] Fix | Delete
*/
[25] Fix | Delete
public $tree_type = 'page';
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Database fields to use.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 2.1.0
[31] Fix | Delete
* @var array
[32] Fix | Delete
*
[33] Fix | Delete
* @see Walker::$db_fields
[34] Fix | Delete
* @todo Decouple this.
[35] Fix | Delete
*/
[36] Fix | Delete
public $db_fields = array(
[37] Fix | Delete
'parent' => 'post_parent',
[38] Fix | Delete
'id' => 'ID',
[39] Fix | Delete
);
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Outputs the beginning of the current level in the tree before elements are output.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 2.1.0
[45] Fix | Delete
*
[46] Fix | Delete
* @see Walker::start_lvl()
[47] Fix | Delete
*
[48] Fix | Delete
* @param string $output Used to append additional content (passed by reference).
[49] Fix | Delete
* @param int $depth Optional. Depth of page. Used for padding. Default 0.
[50] Fix | Delete
* @param array $args Optional. Arguments for outputting the next level.
[51] Fix | Delete
* Default empty array.
[52] Fix | Delete
*/
[53] Fix | Delete
public function start_lvl( &$output, $depth = 0, $args = array() ) {
[54] Fix | Delete
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
[55] Fix | Delete
$t = "\t";
[56] Fix | Delete
$n = "\n";
[57] Fix | Delete
} else {
[58] Fix | Delete
$t = '';
[59] Fix | Delete
$n = '';
[60] Fix | Delete
}
[61] Fix | Delete
$indent = str_repeat( $t, $depth );
[62] Fix | Delete
$output .= "{$n}{$indent}<ul class='children'>{$n}";
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* Outputs the end of the current level in the tree after elements are output.
[67] Fix | Delete
*
[68] Fix | Delete
* @since 2.1.0
[69] Fix | Delete
*
[70] Fix | Delete
* @see Walker::end_lvl()
[71] Fix | Delete
*
[72] Fix | Delete
* @param string $output Used to append additional content (passed by reference).
[73] Fix | Delete
* @param int $depth Optional. Depth of page. Used for padding. Default 0.
[74] Fix | Delete
* @param array $args Optional. Arguments for outputting the end of the current level.
[75] Fix | Delete
* Default empty array.
[76] Fix | Delete
*/
[77] Fix | Delete
public function end_lvl( &$output, $depth = 0, $args = array() ) {
[78] Fix | Delete
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
[79] Fix | Delete
$t = "\t";
[80] Fix | Delete
$n = "\n";
[81] Fix | Delete
} else {
[82] Fix | Delete
$t = '';
[83] Fix | Delete
$n = '';
[84] Fix | Delete
}
[85] Fix | Delete
$indent = str_repeat( $t, $depth );
[86] Fix | Delete
$output .= "{$indent}</ul>{$n}";
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Outputs the beginning of the current element in the tree.
[91] Fix | Delete
*
[92] Fix | Delete
* @see Walker::start_el()
[93] Fix | Delete
* @since 2.1.0
[94] Fix | Delete
*
[95] Fix | Delete
* @param string $output Used to append additional content. Passed by reference.
[96] Fix | Delete
* @param WP_Post $page Page data object.
[97] Fix | Delete
* @param int $depth Optional. Depth of page. Used for padding. Default 0.
[98] Fix | Delete
* @param array $args Optional. Array of arguments. Default empty array.
[99] Fix | Delete
* @param int $current_page Optional. Page ID. Default 0.
[100] Fix | Delete
*/
[101] Fix | Delete
public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
[102] Fix | Delete
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
[103] Fix | Delete
$t = "\t";
[104] Fix | Delete
$n = "\n";
[105] Fix | Delete
} else {
[106] Fix | Delete
$t = '';
[107] Fix | Delete
$n = '';
[108] Fix | Delete
}
[109] Fix | Delete
if ( $depth ) {
[110] Fix | Delete
$indent = str_repeat( $t, $depth );
[111] Fix | Delete
} else {
[112] Fix | Delete
$indent = '';
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
$css_class = array( 'page_item', 'page-item-' . $page->ID );
[116] Fix | Delete
[117] Fix | Delete
if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
[118] Fix | Delete
$css_class[] = 'page_item_has_children';
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
if ( ! empty( $current_page ) ) {
[122] Fix | Delete
$_current_page = get_post( $current_page );
[123] Fix | Delete
[124] Fix | Delete
if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
[125] Fix | Delete
$css_class[] = 'current_page_ancestor';
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( $page->ID == $current_page ) {
[129] Fix | Delete
$css_class[] = 'current_page_item';
[130] Fix | Delete
} elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
[131] Fix | Delete
$css_class[] = 'current_page_parent';
[132] Fix | Delete
}
[133] Fix | Delete
} elseif ( get_option( 'page_for_posts' ) == $page->ID ) {
[134] Fix | Delete
$css_class[] = 'current_page_parent';
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Filters the list of CSS classes to include with each page item in the list.
[139] Fix | Delete
*
[140] Fix | Delete
* @since 2.8.0
[141] Fix | Delete
*
[142] Fix | Delete
* @see wp_list_pages()
[143] Fix | Delete
*
[144] Fix | Delete
* @param string[] $css_class An array of CSS classes to be applied to each list item.
[145] Fix | Delete
* @param WP_Post $page Page data object.
[146] Fix | Delete
* @param int $depth Depth of page, used for padding.
[147] Fix | Delete
* @param array $args An array of arguments.
[148] Fix | Delete
* @param int $current_page ID of the current page.
[149] Fix | Delete
*/
[150] Fix | Delete
$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
[151] Fix | Delete
$css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
[152] Fix | Delete
[153] Fix | Delete
if ( '' === $page->post_title ) {
[154] Fix | Delete
/* translators: %d: ID of a post. */
[155] Fix | Delete
$page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
[159] Fix | Delete
$args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
[160] Fix | Delete
[161] Fix | Delete
$atts = array();
[162] Fix | Delete
$atts['href'] = get_permalink( $page->ID );
[163] Fix | Delete
$atts['aria-current'] = ( $page->ID == $current_page ) ? 'page' : '';
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Filters the HTML attributes applied to a page menu item's anchor element.
[167] Fix | Delete
*
[168] Fix | Delete
* @since 4.8.0
[169] Fix | Delete
*
[170] Fix | Delete
* @param array $atts {
[171] Fix | Delete
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
[172] Fix | Delete
*
[173] Fix | Delete
* @type string $href The href attribute.
[174] Fix | Delete
* @type string $aria_current The aria-current attribute.
[175] Fix | Delete
* }
[176] Fix | Delete
* @param WP_Post $page Page data object.
[177] Fix | Delete
* @param int $depth Depth of page, used for padding.
[178] Fix | Delete
* @param array $args An array of arguments.
[179] Fix | Delete
* @param int $current_page ID of the current page.
[180] Fix | Delete
*/
[181] Fix | Delete
$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
[182] Fix | Delete
[183] Fix | Delete
$attributes = '';
[184] Fix | Delete
foreach ( $atts as $attr => $value ) {
[185] Fix | Delete
if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
[186] Fix | Delete
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
[187] Fix | Delete
$attributes .= ' ' . $attr . '="' . $value . '"';
[188] Fix | Delete
}
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
$output .= $indent . sprintf(
[192] Fix | Delete
'<li%s><a%s>%s%s%s</a>',
[193] Fix | Delete
$css_classes,
[194] Fix | Delete
$attributes,
[195] Fix | Delete
$args['link_before'],
[196] Fix | Delete
/** This filter is documented in wp-includes/post-template.php */
[197] Fix | Delete
apply_filters( 'the_title', $page->post_title, $page->ID ),
[198] Fix | Delete
$args['link_after']
[199] Fix | Delete
);
[200] Fix | Delete
[201] Fix | Delete
if ( ! empty( $args['show_date'] ) ) {
[202] Fix | Delete
if ( 'modified' === $args['show_date'] ) {
[203] Fix | Delete
$time = $page->post_modified;
[204] Fix | Delete
} else {
[205] Fix | Delete
$time = $page->post_date;
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
$date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
[209] Fix | Delete
$output .= ' ' . mysql2date( $date_format, $time );
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Outputs the end of the current element in the tree.
[215] Fix | Delete
*
[216] Fix | Delete
* @since 2.1.0
[217] Fix | Delete
*
[218] Fix | Delete
* @see Walker::end_el()
[219] Fix | Delete
*
[220] Fix | Delete
* @param string $output Used to append additional content. Passed by reference.
[221] Fix | Delete
* @param WP_Post $page Page data object. Not used.
[222] Fix | Delete
* @param int $depth Optional. Depth of page. Default 0 (unused).
[223] Fix | Delete
* @param array $args Optional. Array of arguments. Default empty array.
[224] Fix | Delete
*/
[225] Fix | Delete
public function end_el( &$output, $page, $depth = 0, $args = array() ) {
[226] Fix | Delete
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
[227] Fix | Delete
$t = "\t";
[228] Fix | Delete
$n = "\n";
[229] Fix | Delete
} else {
[230] Fix | Delete
$t = '';
[231] Fix | Delete
$n = '';
[232] Fix | Delete
}
[233] Fix | Delete
$output .= "</li>{$n}";
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function