WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 19 months ago

#39862 reopened enhancement

Track the number of children for a walker element scope

Reported by: AlexGW Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.2
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

Unless this had been deliberately omitted for performance reasons?

A minor change to the Walker class would provide the total number of children $this->total_children for the current element scope from within the display_element() function.

Currently a custom walker must be used and include an extension of display_element() for each X_Walker class where this information is needed.

Patch attached.

This change; for example could provide information to display the number of replies to a comment in an extended template of Comment_Walker::comment()

Attachments (5)

39862.diff (295 bytes) - added by AlexGW 2 years ago.
patch for class-wp-walker.php
39862.2.diff (295 bytes) - added by welcher 21 months ago.
39862.3.diff (915 bytes) - added by welcher 21 months ago.
Add_tracking_for_total_children.patch (1.1 KB) - added by AlexGW 21 months ago.
Updated patch for class-wp-walker.php
39862.4.diff (1.3 KB) - added by welcher 19 months ago.
Updated patch from root

Download all attachments as: .zip

Change History (15)

@AlexGW
2 years ago

patch for class-wp-walker.php

#1 @AlexGW
2 years ago

  • Keywords has-patch added

#2 @welcher
21 months ago

@AlexGW thanks for creating this ticket and welcome to core!

I was not able to apply the patch and it seems to be formatted strangely. I have taken the liberty of creating the patch again. Can you please review to be sure it's correct?

What is your process for creating the patch?

If you're using SVN you can refer to the codex for details on creating a patch file here https://codex.wordpress.org/Using_Subversion#Saving_patch.2Fdiff_files

Last edited 21 months ago by welcher (previous) (diff)

@welcher
21 months ago

@welcher
21 months ago

#3 @welcher
21 months ago

  • Keywords reporter-feedback added

#4 @AlexGW
21 months ago

@welcher Thanks for spotting that, the patch was created when I wasn't too familiar with creating patches. I can confirm the second patch is correct, the third is missing the initial declaration for

$this->total_children = 0

#5 @AlexGW
21 months ago

  • Keywords reporter-feedback removed
  • Resolution set to invalid
  • Status changed from new to closed

#6 @AlexGW
21 months ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

#7 @welcher
21 months ago

  • Keywords needs-refresh added; has-patch removed

@AlexGW can you regenerate the patch to add that back in?

@AlexGW
21 months ago

Updated patch for class-wp-walker.php

#8 @AlexGW
21 months ago

@welcher Updated patch added

#9 @welcher
19 months ago

@AlexGW thanks for generating that. Just a couple of formatting things for future patches.

Please try and generate the patch the root of the repository. That way if there are any unit tests added they are in the same patch. Also, usually we keep the filenames the same for the patches so that when uploaded, the patch files are names PATH.1, .2 .3 etc. It's easier to see what the latest patch is.

I've uploaded a revised patch.

@welcher
19 months ago

Updated patch from root

#10 @welcher
19 months ago

  • Keywords has-patch added; needs-refresh removed
Note: See TracTickets for help on using tickets.