~canonical-sysadmins/wordpress/4.8.3

« back to all changes in this revision

Viewing changes to wp-includes/class-wp-walker.php

  • Committer: Ryan Finnie
  • Date: 2015-08-31 16:09:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: ryan.finnie@canonical.com-20150831160947-1h6rfxby9z1ec62u
Merge WP4.3 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
         * @param int    $depth             Depth of current element.
128
128
         * @param array  $args              An array of arguments.
129
129
         * @param string $output            Passed by reference. Used to append additional content.
130
 
         * @return null Null on failure with no changes to parameters.
131
130
         */
132
131
        public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
133
 
 
134
 
                if ( !$element )
 
132
                if ( ! $element ) {
135
133
                        return;
 
134
                }
136
135
 
137
136
                $id_field = $this->db_fields['id'];
138
137
                $id       = $element->$id_field;
188
187
         * @param int   $max_depth The maximum hierarchical depth.
189
188
         * @return string The hierarchical item output.
190
189
         */
191
 
        public function walk( $elements, $max_depth) {
192
 
 
 
190
        public function walk( $elements, $max_depth ) {
193
191
                $args = array_slice(func_get_args(), 2);
194
192
                $output = '';
195
193
 
196
 
                if ($max_depth < -1) //invalid parameter
197
 
                        return $output;
198
 
 
199
 
                if (empty($elements)) //nothing to walk
200
 
                        return $output;
 
194
                //invalid parameter or nothing to walk
 
195
                if ( $max_depth < -1 || empty( $elements ) ) {
 
196
                        return $output;
 
197
                }
201
198
 
202
199
                $parent_field = $this->db_fields['parent'];
203
200
 
272
269
         *
273
270
         * @since 2.7.0
274
271
         *
275
 
         * @param int $max_depth The maximum hierarchical depth.
276
 
         * @param int $page_num  The specific page number, beginning with 1.
277
 
         * @return string XHTML of the specified page of elements
278
 
         */
 
272
         * @param array $elements
 
273
         * @param int   $max_depth The maximum hierarchical depth.
 
274
         * @param int   $page_num The specific page number, beginning with 1.
 
275
         * @param int   $per_page
 
276
         * @return string XHTML of the specified page of elements
 
277
         */
279
278
        public function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
280
 
 
281
 
                /* sanity check */
282
 
                if ( empty($elements) || $max_depth < -1 )
 
279
                if ( empty( $elements ) || $max_depth < -1 ) {
283
280
                        return '';
 
281
                }
284
282
 
285
283
                $args = array_slice( func_get_args(), 4 );
286
284
                $output = '';
383
381
                return $output;
384
382
        }
385
383
 
 
384
        /**
 
385
         *
 
386
         * @param array $elements
 
387
         * @return int
 
388
         */
386
389
        public function get_number_of_root_elements( $elements ){
387
 
 
388
390
                $num = 0;
389
391
                $parent_field = $this->db_fields['parent'];
390
392
 
395
397
                return $num;
396
398
        }
397
399
 
398
 
        // Unset all the children for a given top level element.
 
400
        /**
 
401
         * Unset all the children for a given top level element.
 
402
         *
 
403
         * @param object $e
 
404
         * @param array $children_elements
 
405
         */
399
406
        public function unset_children( $e, &$children_elements ){
400
 
 
401
 
                if ( !$e || !$children_elements )
 
407
                if ( ! $e || ! $children_elements ) {
402
408
                        return;
 
409
                }
403
410
 
404
411
                $id_field = $this->db_fields['id'];
405
412
                $id = $e->$id_field;
408
415
                        foreach ( (array) $children_elements[$id] as $child )
409
416
                                $this->unset_children( $child, $children_elements );
410
417
 
411
 
                if ( isset($children_elements[$id]) )
412
 
                        unset( $children_elements[$id] );
413
 
 
 
418
                unset( $children_elements[ $id ] );
414
419
        }
415
420
 
416
421
} // Walker