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 = '') { function wp_list_authors($args = '') {
global $wpdb; global $wpdb;
if ( is_array($args) ) $defaults = array(
$r = &$args; 'optioncount' => false, 'exclude_admin' => true,
else 'show_fullname' => false, 'hide_empty' => true,
parse_str($args, $r); 'feed' => '', 'feed_image' => ''
);
$defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => ''); $r = wp_parse_args( $args, $defaults );
$r = array_merge($defaults, $r);
extract($r); extract($r);
// TODO: Move select to get_authors(). // TODO: Move select to get_authors().

View File

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

View File

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

View File

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

View File

@ -16,22 +16,25 @@ function get_all_category_ids() {
function &get_categories($args = '') { function &get_categories($args = '') {
global $wpdb, $category_links; global $wpdb, $category_links;
if ( is_array($args) ) $defaults = array(
$r = &$args; 'type' => 'post', 'child_of' => 0,
else 'orderby' => 'name', 'order' => 'ASC',
parse_str($args, $r); 'hide_empty' => true, 'include_last_update_time' => false,
'hierarchical' => 1, 'exclude' => '',
$defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 'include' => '', 'number' => '',
'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'pad_counts' => false
'number' => '', 'pad_counts' => false); );
$r = array_merge($defaults, $r);
if ( 'count' == $r['orderby'] ) $r = wp_parse_args( $args, $defaults );
if ( $r['orderby'] == 'count' ) {
$r['orderby'] = 'category_count'; $r['orderby'] = 'category_count';
else } else {
$r['orderby'] = "cat_" . $r['orderby']; // restricts order by to cat_ID and cat_name fields $r['orderby'] = 'cat_' . $r['orderby'];
$r['number'] = (int) $r['number']; }
extract($r);
extract( $r );
$key = md5( serialize( $r ) ); $key = md5( serialize( $r ) );
if ( $cache = wp_cache_get( 'get_categories', 'category' ) ) 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' // a WP_Error object can be passed in 'id' or 'data'
function add( $args = '' ) { function add( $args = '' ) {
if ( is_array($args) ) $defaults = array(
$r = &$args; 'what' => 'object', 'action' => false,
else 'id' => '0', 'old_id' => false,
parse_str($args, $r); 'data' => '', 'supplemental' => array()
);
$defaults = array('what' => 'object', 'action' => false, 'id' => '0', 'old_id' => false,
'data' => '', 'supplemental' => array()); $r = wp_parse_args( $args, $defaults );
extract( $r );
$r = array_merge($defaults, $r);
extract($r);
if ( is_wp_error($id) ) { if ( is_wp_error($id) ) {
$data = $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 = '') { function wp_list_cats($args = '') {
if ( is_array($args) ) $r = wp_parse_args( $args );
$r = &$args;
else
parse_str($args, $r);
// Map to new names. // Map to new names.
if ( isset($r['optionall']) && isset($r['all'])) 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 = '') { function wp_get_archives($args = '') {
global $wp_locale, $wpdb; global $wpdb;
if ( is_array($args) ) $defaults = array(
$r = &$args; 'type' => 'monthly', 'limit' => '',
else 'format' => 'html', 'before' => '',
parse_str($args, $r); 'after' => '', 'show_post_count' => false
);
$defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false);
$r = array_merge($defaults, $r); $r = wp_parse_args( $args, $defaults );
extract($r); extract( $r );
if ( '' == $type ) if ( '' == $type )
$type = 'monthly'; $type = 'monthly';

View File

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

View File

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