Use wp_parse_args(). fixes #4237

git-svn-id: http://svn.automattic.com/wordpress/trunk@5444 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rob1n 2007-05-11 03:10:05 +00:00
parent 70c17cc871
commit e6c189902c
10 changed files with 195 additions and 191 deletions

View File

@ -175,14 +175,13 @@ function get_author_name( $auth_id ) {
function wp_list_authors($args = '') {
global $wpdb;
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => '');
$r = array_merge($defaults, $r);
$defaults = array(
'optioncount' => false, 'exclude_admin' => true,
'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => ''
);
$r = wp_parse_args( $args, $defaults );
extract($r);
// TODO: Move select to get_authors().

View File

@ -9,28 +9,23 @@
**/
function wp_get_links($args = '') {
global $wpdb;
if ( empty($args) )
return;
if ( false === strpos($args, '=') ) {
if ( strpos( $args, '=' ) === false ) {
$cat_id = $args;
$args = add_query_arg('category', $cat_id, $args);
$args = add_query_arg( 'category', $cat_id, $args );
}
parse_str($args);
if ( !isset($category) ) $category = -1;
if ( !isset($before) ) $before = '';
if ( !isset($after) ) $after = '<br />';
if ( !isset($between) ) $between = ' ';
if ( !isset($show_images) ) $show_images = true;
if ( !isset($orderby) ) $orderby = 'name';
if ( !isset($show_description) ) $show_description = true;
if ( !isset($show_rating) ) $show_rating = false;
if ( !isset($limit) ) $limit = -1;
if ( !isset($show_updated) ) $show_updated = 1;
if ( !isset($echo) ) $echo = true;
$defaults = array(
'category' => -1, 'before' => '',
'after' => '<br />', 'between' => ' ',
'show_images' => true, 'orderby' => 'name',
'show_description' => true, 'show_rating' => false,
'limit' => -1, 'show_updated' => true,
'echo' => true
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo);
} // end wp_get_links
@ -245,15 +240,14 @@ function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
}
function _walk_bookmarks($bookmarks, $args = '' ) {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('show_updated' => 0, 'show_description' => 0, 'show_images' => 1, 'before' => '<li>',
'after' => '</li>', 'between' => "\n");
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'show_updated' => 0, 'show_description' => 0,
'show_images' => 1, 'before' => '<li>',
'after' => '</li>', 'between' => "\n"
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
foreach ( (array) $bookmarks as $bookmark ) {
if ( !isset($bookmark->recently_updated) )
@ -320,18 +314,20 @@ function _walk_bookmarks($bookmarks, $args = '' ) {
}
function wp_list_bookmarks($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '',
'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' => 1,
'categorize' => 1, 'title_li' => __('Bookmarks'), 'title_before' => '<h2>', 'title_after' => '</h2>',
'category_orderby' => 'name', 'category_order' => 'ASC', 'class' => 'linkcat',
'category_before' => '<li id="%id" class="%class">', 'category_after' => '</li>');
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'orderby' => 'name', 'order' => 'ASC',
'limit' => -1, 'category' => '',
'category_name' => '', 'hide_invisible' => 1,
'show_updated' => 0, 'echo' => 1,
'categorize' => 1, 'title_li' => __('Bookmarks'),
'title_before' => '<h2>', 'title_after' => '</h2>',
'category_orderby' => 'name', 'category_order' => 'ASC',
'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
'category_after' => '</li>'
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
$output = '';

View File

@ -25,16 +25,17 @@ function get_link($bookmark_id, $output = OBJECT) {
function get_bookmarks($args = '') {
global $wpdb;
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '',
'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '');
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'orderby' => 'name', 'order' => 'ASC',
'limit' => -1, 'category' => '',
'category_name' => '', 'hide_invisible' => 1,
'show_updated' => 0, 'include' => '',
'exclude' => ''
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
$key = md5( serialize( $r ) );
if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) )

View File

@ -169,20 +169,21 @@ function category_description($category = 0) {
}
function wp_dropdown_categories($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID',
'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0,
'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1,
'selected' => 0, 'hierarchical' => 0, 'name' => 'cat',
'class' => 'postform');
$defaults = array(
'show_option_all' => '', 'show_option_none' => '',
'orderby' => 'ID', 'order' => 'ASC',
'show_last_update' => 0, 'show_count' => 0,
'hide_empty' => 1, 'child_of' => 0,
'exclude' => '', 'echo' => 1,
'selected' => 0, 'hierarchical' => 0,
'name' => 'cat', 'class' => 'postform'
);
$defaults['selected'] = ( is_category() ) ? get_query_var('cat') : 0;
$r = array_merge($defaults, $r);
$r = wp_parse_args( $args, $defaults );
$r['include_last_update_time'] = $r['show_last_update'];
extract($r);
extract( $r );
$categories = get_categories($r);
@ -218,23 +219,28 @@ function wp_dropdown_categories($args = '') {
}
function wp_list_categories($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('show_option_all' => '', 'orderby' => 'name',
'order' => 'ASC', 'show_last_update' => 0, 'style' => 'list',
'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1,
'child_of' => 0, 'feed' => '', 'feed_image' => '', 'exclude' => '',
'hierarchical' => true, 'title_li' => __('Categories'));
$r = array_merge($defaults, $r);
if ( !isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical'] )
$defaults = array(
'show_option_all' => '', 'orderby' => 'name',
'order' => 'ASC', 'show_last_update' => 0,
'style' => 'list', 'show_count' => 0,
'hide_empty' => 1, 'use_desc_for_title' => 1,
'child_of' => 0, 'feed' => '',
'feed_image' => '', 'exclude' => '',
'hierarchical' => true, 'title_li' => __('Categories')
);
$r = wp_parse_args( $args, $defaults );
if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
if ( isset($r['show_date']) )
}
if ( isset( $r['show_date'] ) ) {
$r['include_last_update_time'] = $r['show_date'];
extract($r);
}
extract( $r );
$categories = get_categories($r);
$output = '';

View File

@ -16,22 +16,25 @@ function get_all_category_ids() {
function &get_categories($args = '') {
global $wpdb, $category_links;
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC',
'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '', 'include' => '',
'number' => '', 'pad_counts' => false);
$r = array_merge($defaults, $r);
if ( 'count' == $r['orderby'] )
$defaults = array(
'type' => 'post', 'child_of' => 0,
'orderby' => 'name', 'order' => 'ASC',
'hide_empty' => true, 'include_last_update_time' => false,
'hierarchical' => 1, 'exclude' => '',
'include' => '', 'number' => '',
'pad_counts' => false
);
$r = wp_parse_args( $args, $defaults );
if ( $r['orderby'] == 'count' ) {
$r['orderby'] = 'category_count';
else
$r['orderby'] = "cat_" . $r['orderby']; // restricts order by to cat_ID and cat_name fields
$r['number'] = (int) $r['number'];
extract($r);
} else {
$r['orderby'] = 'cat_' . $r['orderby'];
}
extract( $r );
$key = md5( serialize( $r ) );
if ( $cache = wp_cache_get( 'get_categories', 'category' ) )

View File

@ -687,16 +687,14 @@ class WP_Ajax_Response {
// a WP_Error object can be passed in 'id' or 'data'
function add( $args = '' ) {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('what' => 'object', 'action' => false, 'id' => '0', 'old_id' => false,
'data' => '', 'supplemental' => array());
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'what' => 'object', 'action' => false,
'id' => '0', 'old_id' => false,
'data' => '', 'supplemental' => array()
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
if ( is_wp_error($id) ) {
$data = $id;

View File

@ -427,10 +427,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
}
function wp_list_cats($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$r = wp_parse_args( $args );
// Map to new names.
if ( isset($r['optionall']) && isset($r['all']))

View File

@ -313,16 +313,16 @@ function get_archives_link($url, $text, $format = 'html', $before = '', $after =
function wp_get_archives($args = '') {
global $wp_locale, $wpdb;
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false);
$r = array_merge($defaults, $r);
extract($r);
global $wpdb;
$defaults = array(
'type' => 'monthly', 'limit' => '',
'format' => 'html', 'before' => '',
'after' => '', 'show_post_count' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
if ( '' == $type )
$type = 'monthly';

View File

@ -135,19 +135,17 @@ function has_excerpt( $id = 0 ) {
}
function wp_link_pages($args = '') {
global $post;
$defaults = array(
'before' => '<p>' . __('Pages:'), 'after' => '</p>',
'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
'previouspagelink' => __('Previous page'), 'pagelink' => '%',
'more_file' => '', 'echo' => 1
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('before' => '<p>' . __('Pages:'), 'after' => '</p>', 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
'previouspagelink' => __('Previous page'), 'pagelink' => '%', 'more_file' => '', 'echo' => 1);
$r = array_merge($defaults, $r);
extract($r);
global $id, $page, $numpages, $multipage, $more, $pagenow;
global $post, $id, $page, $numpages, $multipage, $more, $pagenow;
if ( $more_file != '' )
$file = $more_file;
else
@ -251,15 +249,14 @@ function the_meta() {
//
function wp_dropdown_pages($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('depth' => 0, 'child_of' => 0, 'selected' => 0, 'echo' => 1,
'name' => 'page_id', 'show_option_none' => '');
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'depth' => 0, 'child_of' => 0,
'selected' => 0, 'echo' => 1,
'name' => 'page_id', 'show_option_none' => ''
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
$pages = get_pages($r);
$output = '';
@ -281,14 +278,16 @@ function wp_dropdown_pages($args = '') {
}
function wp_list_pages($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'),
'child_of' => 0, 'exclude' => '', 'title_li' => __('Pages'), 'echo' => 1, 'authors' => '', 'sort_column' => 'menu_order, post_title');
$r = array_merge($defaults, $r);
$defaults = array(
'depth' => 0, 'show_date' => '',
'date_format' => get_option('date_format'),
'child_of' => 0, 'exclude' => '',
'title_li' => __('Pages'), 'echo' => 1,
'authors' => '', 'sort_column' => 'menu_order, post_title'
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
$output = '';
$current_page = 0;

View File

@ -27,23 +27,25 @@ function update_attached_file( $attachment_id, $file ) {
function &get_children($args = '', $output = OBJECT) {
global $post_cache, $wpdb, $blog_id;
if ( empty($args) ) {
if ( isset($GLOBALS['post']) )
$r = array('post_parent' => & $GLOBALS['post']->post_parent);
else
if ( empty( $args ) ) {
if ( isset( $GLOBALS['post'] ) ) {
$args = 'post_parent=' . (int) $GLOBALS['post']->post_parent;
} else {
return false;
} elseif ( is_object($args) )
$r = array('post_parent' => $post->post_parent);
elseif ( is_numeric($args) )
$r = array('post_parent' => $args);
elseif ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('numberposts' => -1, 'post_type' => '', 'post_status' => '', 'post_parent' => 0);
$r = array_merge($defaults, $r);
}
} elseif ( is_object( $args ) ) {
$args = 'post_parent=' . (int) $args->post_parent;
} elseif ( is_numeric( $args ) ) {
$args = 'post_parent=' . (int) $args;
}
$defaults = array(
'numberposts' => -1, 'post_type' => '',
'post_status' => '', 'post_parent' => 0
);
$r = wp_parse_args( $args, $defaults );
$children = get_posts( $r );
@ -172,17 +174,19 @@ function get_post_type($post = false) {
function get_posts($args) {
global $wpdb;
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('numberposts' => 5, 'offset' => 0, 'category' => 0,
'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '',
'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'publish', 'post_parent' => 0);
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'numberposts' => 5, 'offset' => 0,
'category' => 0, 'orderby' => 'post_date',
'order' => 'DESC', 'include' => '',
'exclude' => '', 'meta_key' => '',
'meta_value' =>'', 'post_type' => 'post',
'post_status' => 'publish', 'post_parent' => 0
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
$numberposts = (int) $numberposts;
$offset = (int) $offset;
$category = (int) $category;
@ -1163,16 +1167,17 @@ function get_page_uri($page_id) {
function &get_pages($args = '') {
global $wpdb;
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title',
'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '');
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'child_of' => 0, 'sort_order' => 'ASC',
'sort_column' => 'post_title', 'hierarchical' => 1,
'exclude' => '', 'include' => '',
'meta_key' => '', 'meta_value' => '',
'authors' => ''
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
$key = md5( serialize( $r ) );
if ( $cache = wp_cache_get( 'get_pages', 'page' ) )