Ticket #9007: deprecate_get_category_children.9007.diff

File deprecate_get_category_children.9007.diff, 2.5 KB (added by filosofo, 4 years ago)

Deprecate get_category_children. Really, how often do you need a string of concatenated category children ids?

Line 
1Index: wp-includes/deprecated.php
2===================================================================
3--- wp-includes/deprecated.php  (revision 10474)
4+++ wp-includes/deprecated.php  (working copy)
5@@ -1303,3 +1303,31 @@
6        return get_comment($comment_ID, ARRAY_A);
7 }
8 
9+/**
10+ * Retrieve category children list separated before and after the term IDs.
11+ *
12+ * @since 1.2.0
13+ * @deprecated Use get_term_children()
14+ * @see get_term_children()
15+ *
16+ * @param int $id Category ID to retrieve children.
17+ * @param string $before Optional. Prepend before category term ID.
18+ * @param string $after Optional, default is empty string. Append after category term ID.
19+ * @param array $visited Optional. Category Term IDs that have already been added.
20+ * @return string
21+ */
22+function get_category_children( $id, $before = '/', $after = '' ) {
23+       _deprecated_function(__FUNCTION__, '2.8', 'get_term_children()');
24+       if ( 0 == $id )
25+               return '';
26+
27+       $children = get_term_children( $id, 'category' );
28+
29+       if ( !is_wp_error( $children ) && !empty( $children ) )
30+               $chain = $before . join( $after . $before, $children ) . $after;
31+       else
32+               $chain = '';
33+           
34+       return $chain;
35+}
36+
37Index: wp-includes/category-template.php
38===================================================================
39--- wp-includes/category-template.php   (revision 10474)
40+++ wp-includes/category-template.php   (working copy)
41@@ -7,40 +7,6 @@
42  */
43 
44 /**
45- * Retrieve category children list separated before and after the term IDs.
46- *
47- * @since 1.2.0
48- *
49- * @param int $id Category ID to retrieve children.
50- * @param string $before Optional. Prepend before category term ID.
51- * @param string $after Optional, default is empty string. Append after category term ID.
52- * @param array $visited Optional. Category Term IDs that have already been added.
53- * @return string
54- */
55-function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
56-       if ( 0 == $id )
57-               return '';
58-
59-       $chain = '';
60-       /** TODO: consult hierarchy */
61-       $cat_ids = get_all_category_ids();
62-       foreach ( (array) $cat_ids as $cat_id ) {
63-               if ( $cat_id == $id )
64-                       continue;
65-
66-               $category = get_category( $cat_id );
67-               if ( is_wp_error( $category ) )
68-                       return $category;
69-               if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
70-                       $visited[] = $category->term_id;
71-                       $chain .= $before.$category->term_id.$after;
72-                       $chain .= get_category_children( $category->term_id, $before, $after );
73-               }
74-       }
75-       return $chain;
76-}
77-
78-/**
79  * Retrieve category link URL.
80  *
81  * @since 1.0.0