Commit a96340c
committed
General: Add optional callback argument to serialize_block(s).
Allow passing a function callback to serialize_block(s) that is invoked on each node in the tree of parsed blocks as it is traversed for serialization.
A function argument was chosen for passing the callback function as it reflects a pattern familiar from other algorithms that apply a given callback function while traversing a data structure -- most notably PHP's own `array_map()`.
Introducing a filter was considered as an alternative but ultimately dismissed. For a fairly low-level and general-purpose function such as `serialize_block()`, using a filter to pass the callback seemed risky, as it also requires ''removing'' that filter after usage in order to prevent the callback from being accidentally applied when `serialize_block()` is called in an entirely different context.
Introducing a separate function for applying a given operation during tree traversal (i.e. independently of serialization) was also considered but dismissed, as it would unnecessarily duplicate tree traversal.
Props dlh, gziolo.
Fixes #59327. See #59313.
Built from https://develop.svn.wordpress.org/trunk@56557
git-svn-id: https://core.svn.wordpress.org/trunk@56069 1a063a9b-81f0-0310-95a4-ce76da25c4cd1 parent 2f9b05c commit a96340c
2 files changed
+19
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
794 | 794 | | |
795 | 795 | | |
796 | 796 | | |
| 797 | + | |
797 | 798 | | |
798 | | - | |
| 799 | + | |
| 800 | + | |
799 | 801 | | |
800 | 802 | | |
801 | | - | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
802 | 808 | | |
803 | 809 | | |
804 | 810 | | |
805 | 811 | | |
806 | | - | |
| 812 | + | |
807 | 813 | | |
808 | 814 | | |
809 | 815 | | |
| |||
822 | 828 | | |
823 | 829 | | |
824 | 830 | | |
| 831 | + | |
825 | 832 | | |
826 | | - | |
| 833 | + | |
| 834 | + | |
827 | 835 | | |
828 | 836 | | |
829 | | - | |
830 | | - | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
831 | 843 | | |
832 | 844 | | |
833 | 845 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
0 commit comments