Make WordPress Core

Ticket #43842: 43842.diff

File 43842.diff, 1.9 KB (added by rnaby, 7 years ago)

The refactored get_children function patch.

  • src/wp-includes/post.php

     
    526526function get_children( $args = '', $output = OBJECT ) {
    527527        $kids = array();
    528528        if ( empty( $args ) ) {
    529                 if ( isset( $GLOBALS['post'] ) ) {
    530                         $args = array( 'post_parent' => (int) $GLOBALS['post']->post_parent );
    531                 } else {
     529                if ( ! isset( $GLOBALS['post'] ) ) {
    532530                        return $kids;
    533531                }
     532                $args['post_parent'] = (int) $GLOBALS['post']->post_parent;
    534533        } elseif ( is_object( $args ) ) {
    535                 $args = array( 'post_parent' => (int) $args->post_parent );
     534                $args['post_parent'] = (int) $args->post_parent;
    536535        } elseif ( is_numeric( $args ) ) {
    537                 $args = array( 'post_parent' => (int) $args );
     536                $args['post_parent'] = (int) $args;
    538537        }
    539538
    540539        $defaults = array(
     
    562561                $kids[ $child->ID ] = $children[ $key ];
    563562        }
    564563
    565         if ( $output == OBJECT ) {
    566                 return $kids;
    567         } elseif ( $output == ARRAY_A ) {
    568                 $weeuns = array();
    569                 foreach ( (array) $kids as $kid ) {
    570                         $weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] );
    571                 }
    572                 return $weeuns;
    573         } elseif ( $output == ARRAY_N ) {
    574                 $babes = array();
    575                 foreach ( (array) $kids as $kid ) {
    576                         $babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) );
    577                 }
    578                 return $babes;
    579         } else {
    580                 return $kids;
     564        switch ( $output ) {
     565                case OBJECT:
     566                        return $kids;
     567                        break;
     568                case ARRAY_A:
     569                        $weeuns = array();
     570                        foreach ( (array) $kids as $kid ) {
     571                                $weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] );
     572                        }
     573                        return $weeuns;
     574                        break;
     575                case ARRAY_N:
     576                        $babies = array();
     577                        foreach ( (array) $kids as $kid ) {
     578                                $babies[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) );
     579                        }
     580                        return $babies;
     581                        break;
     582                default:
     583                        return $kids;
     584                        break;
    581585        }
    582586}
    583587