wp/wp-includes/class-walker-category.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    28 
    28 
    29 	/**
    29 	/**
    30 	 * Database fields to use.
    30 	 * Database fields to use.
    31 	 *
    31 	 *
    32 	 * @since 2.1.0
    32 	 * @since 2.1.0
    33 	 * @var array
    33 	 * @var string[]
    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(
    38 	public $db_fields = array(
    84 
    84 
    85 	/**
    85 	/**
    86 	 * Starts the element output.
    86 	 * Starts the element output.
    87 	 *
    87 	 *
    88 	 * @since 2.1.0
    88 	 * @since 2.1.0
       
    89 	 * @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
       
    90 	 *              to match parent class for PHP 8 named parameter support.
    89 	 *
    91 	 *
    90 	 * @see Walker::start_el()
    92 	 * @see Walker::start_el()
    91 	 *
    93 	 *
    92 	 * @param string  $output   Used to append additional content (passed by reference).
    94 	 * @param string  $output            Used to append additional content (passed by reference).
    93 	 * @param WP_Term $category Category data object.
    95 	 * @param WP_Term $data_object       Category data object.
    94 	 * @param int     $depth    Optional. Depth of category in reference to parents. Default 0.
    96 	 * @param int     $depth             Optional. Depth of category in reference to parents. Default 0.
    95 	 * @param array   $args     Optional. An array of arguments. See wp_list_categories(). Default empty array.
    97 	 * @param array   $args              Optional. An array of arguments. See wp_list_categories().
    96 	 * @param int     $id       Optional. ID of the current category. Default 0.
    98 	 *                                   Default empty array.
    97 	 */
    99 	 * @param int     $current_object_id Optional. ID of the current category. Default 0.
    98 	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
   100 	 */
       
   101 	public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
       
   102 		// Restores the more descriptive, specific name for use within this method.
       
   103 		$category = $data_object;
       
   104 
    99 		/** This filter is documented in wp-includes/category-template.php */
   105 		/** This filter is documented in wp-includes/category-template.php */
   100 		$cat_name = apply_filters( 'list_cats', esc_attr( $category->name ), $category );
   106 		$cat_name = apply_filters( 'list_cats', esc_attr( $category->name ), $category );
   101 
   107 
   102 		// Don't generate an element if the category name is empty.
   108 		// Don't generate an element if the category name is empty.
   103 		if ( '' === $cat_name ) {
   109 		if ( '' === $cat_name ) {
   128 		 *     The HTML attributes applied to the list item's `<a>` element, empty strings are ignored.
   134 		 *     The HTML attributes applied to the list item's `<a>` element, empty strings are ignored.
   129 		 *
   135 		 *
   130 		 *     @type string $href  The href attribute.
   136 		 *     @type string $href  The href attribute.
   131 		 *     @type string $title The title attribute.
   137 		 *     @type string $title The title attribute.
   132 		 * }
   138 		 * }
   133 		 * @param WP_Term $category Term data object.
   139 		 * @param WP_Term $category          Term data object.
   134 		 * @param int     $depth    Depth of category, used for padding.
   140 		 * @param int     $depth             Depth of category, used for padding.
   135 		 * @param array   $args     An array of arguments.
   141 		 * @param array   $args              An array of arguments.
   136 		 * @param int     $id       ID of the current category.
   142 		 * @param int     $current_object_id ID of the current category.
   137 		 */
   143 		 */
   138 		$atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $id );
   144 		$atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $current_object_id );
   139 
   145 
   140 		$attributes = '';
   146 		$attributes = '';
   141 		foreach ( $atts as $attr => $value ) {
   147 		foreach ( $atts as $attr => $value ) {
   142 			if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
   148 			if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
   143 				$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
   149 				$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
   156 
   162 
   157 			if ( empty( $args['feed_image'] ) ) {
   163 			if ( empty( $args['feed_image'] ) ) {
   158 				$link .= '(';
   164 				$link .= '(';
   159 			}
   165 			}
   160 
   166 
   161 			$link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"';
   167 			$link .= '<a href="' . esc_url( get_term_feed_link( $category, $category->taxonomy, $args['feed_type'] ) ) . '"';
   162 
   168 
   163 			if ( empty( $args['feed'] ) ) {
   169 			if ( empty( $args['feed'] ) ) {
   164 				/* translators: %s: Category name. */
   170 				/* translators: %s: Category name. */
   165 				$alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
   171 				$alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
   166 			} else {
   172 			} else {
   246 
   252 
   247 	/**
   253 	/**
   248 	 * Ends the element output, if needed.
   254 	 * Ends the element output, if needed.
   249 	 *
   255 	 *
   250 	 * @since 2.1.0
   256 	 * @since 2.1.0
       
   257 	 * @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
   251 	 *
   258 	 *
   252 	 * @see Walker::end_el()
   259 	 * @see Walker::end_el()
   253 	 *
   260 	 *
   254 	 * @param string $output Used to append additional content (passed by reference).
   261 	 * @param string $output      Used to append additional content (passed by reference).
   255 	 * @param object $page   Not used.
   262 	 * @param object $data_object Category data object. Not used.
   256 	 * @param int    $depth  Optional. Depth of category. Not used.
   263 	 * @param int    $depth       Optional. Depth of category. Not used.
   257 	 * @param array  $args   Optional. An array of arguments. Only uses 'list' for whether should append
   264 	 * @param array  $args        Optional. An array of arguments. Only uses 'list' for whether should
   258 	 *                       to output. See wp_list_categories(). Default empty array.
   265 	 *                            append to output. See wp_list_categories(). Default empty array.
   259 	 */
   266 	 */
   260 	public function end_el( &$output, $page, $depth = 0, $args = array() ) {
   267 	public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
   261 		if ( 'list' !== $args['style'] ) {
   268 		if ( 'list' !== $args['style'] ) {
   262 			return;
   269 			return;
   263 		}
   270 		}
   264 
   271 
   265 		$output .= "</li>\n";
   272 		$output .= "</li>\n";