Make WordPress Core


Ignore:
Timestamp:
05/11/2007 03:10:05 AM (18 years ago)
Author:
rob1n
Message:

Use wp_parse_args(). fixes #4237

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r5271 r5444  
    2828function &get_children($args = '', $output = OBJECT) {
    2929    global $post_cache, $wpdb, $blog_id;
    30 
    31     if ( empty($args) ) {
    32         if ( isset($GLOBALS['post']) )
    33             $r = array('post_parent' => & $GLOBALS['post']->post_parent);
    34         else
     30   
     31    if ( empty( $args ) ) {
     32        if ( isset( $GLOBALS['post'] ) ) {
     33            $args = 'post_parent=' . (int) $GLOBALS['post']->post_parent;
     34        } else {
    3535            return false;
    36     } elseif ( is_object($args) )
    37         $r = array('post_parent' => $post->post_parent);
    38     elseif ( is_numeric($args) )
    39         $r = array('post_parent' => $args);
    40     elseif ( is_array($args) )
    41         $r = &$args;
    42     else
    43         parse_str($args, $r);
    44 
    45     $defaults = array('numberposts' => -1, 'post_type' => '', 'post_status' => '', 'post_parent' => 0);
    46     $r = array_merge($defaults, $r);
     36        }
     37    } elseif ( is_object( $args ) ) {
     38        $args = 'post_parent=' . (int) $args->post_parent;
     39    } elseif ( is_numeric( $args ) ) {
     40        $args = 'post_parent=' . (int) $args;
     41    }
     42   
     43    $defaults = array(
     44        'numberposts' => -1, 'post_type' => '',
     45        'post_status' => '', 'post_parent' => 0
     46    );
     47   
     48    $r = wp_parse_args( $args, $defaults );
    4749
    4850    $children = get_posts( $r );
     
    173175function get_posts($args) {
    174176    global $wpdb;
    175 
    176     if ( is_array($args) )
    177         $r = &$args;
    178     else
    179         parse_str($args, $r);
    180 
    181     $defaults = array('numberposts' => 5, 'offset' => 0, 'category' => 0,
    182         'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '',
    183         'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'publish', 'post_parent' => 0);
    184     $r = array_merge($defaults, $r);
    185     extract($r);
     177   
     178    $defaults = array(
     179        'numberposts' => 5, 'offset' => 0,
     180        'category' => 0, 'orderby' => 'post_date',
     181        'order' => 'DESC', 'include' => '',
     182        'exclude' => '', 'meta_key' => '',
     183        'meta_value' =>'', 'post_type' => 'post',
     184        'post_status' => 'publish', 'post_parent' => 0
     185    );
     186   
     187    $r = wp_parse_args( $args, $defaults );
     188    extract( $r );
     189   
    186190    $numberposts = (int) $numberposts;
    187191    $offset = (int) $offset;
     
    11641168function &get_pages($args = '') {
    11651169    global $wpdb;
    1166 
    1167     if ( is_array($args) )
    1168         $r = &$args;
    1169     else
    1170         parse_str($args, $r);
    1171 
    1172     $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title',
    1173                 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '');
    1174     $r = array_merge($defaults, $r);
    1175     extract($r);
     1170   
     1171    $defaults = array(
     1172        'child_of' => 0, 'sort_order' => 'ASC',
     1173        'sort_column' => 'post_title', 'hierarchical' => 1,
     1174        'exclude' => '', 'include' => '',
     1175        'meta_key' => '', 'meta_value' => '',
     1176        'authors' => ''
     1177    );
     1178   
     1179    $r = wp_parse_args( $args, $defaults );
     1180    extract( $r );
    11761181
    11771182    $key = md5( serialize( $r ) );
Note: See TracChangeset for help on using the changeset viewer.