From 7f125c513578d1395625e9e1f11a496863776598 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 2 Mar 2006 06:37:00 +0000 Subject: [PATCH] Use array_merge() to set defaults. git-svn-id: http://svn.automattic.com/wordpress/trunk@3595 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/template-functions-bookmarks.php | 22 +--- wp-includes/template-functions-category.php | 100 ++++--------------- wp-includes/template-functions-post.php | 39 ++------ 3 files changed, 32 insertions(+), 129 deletions(-) diff --git a/wp-includes/template-functions-bookmarks.php b/wp-includes/template-functions-bookmarks.php index 71d1bf63c..5c6e22f14 100644 --- a/wp-includes/template-functions-bookmarks.php +++ b/wp-includes/template-functions-bookmarks.php @@ -255,23 +255,13 @@ function get_bookmarks($args = '') { else parse_str($args, $r); - if ( !isset($r['orderby']) ) - $r['orderby'] = 'name'; - if ( !isset($r['order']) ) - $r['order'] = 'ASC'; - if ( !isset($r['limit']) ) - $r['limit'] = -1; - if ( !isset($r['category']) ) - $r['category'] = -1; - if ( !isset($r['category_name']) ) - $r['category_name'] = ''; - if ( !isset($r['hide_invisible']) ) - $r['hide_invisible'] = 1; - if ( !isset($r['show_updated']) ) - $r['show_updated'] = 0; + $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => -1, + 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0); + $r = array_merge($defaults, $r); + extract($r); $exclusions = ''; - if ( !empty($r['exclude']) ) { + if ( !empty($exclude) ) { $exlinks = preg_split('/[\s,]+/',$r['exclude']); if ( count($exlinks) ) { foreach ( $exlinks as $exlink ) { @@ -280,8 +270,6 @@ function get_bookmarks($args = '') { } } - extract($r); - if ( ! empty($category_name) ) { if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") ) $category = $cat_id; diff --git a/wp-includes/template-functions-category.php b/wp-includes/template-functions-category.php index 21840db9a..7f531f534 100644 --- a/wp-includes/template-functions-category.php +++ b/wp-includes/template-functions-category.php @@ -155,37 +155,13 @@ function wp_dropdown_categories($args = '') { else parse_str($args, $r); - if ( !isset($r['show_option_all'])) - $r['show_option_all'] = ''; - if ( !isset($r['show_option_none'])) - $r['show_option_none'] = ''; - if ( !isset($r['orderby']) ) - $r['orderby'] = 'ID'; - if ( !isset($r['order']) ) - $r['order'] = 'ASC'; - if ( !isset($r['show_last_update']) ) - $r['show_last_update'] = 0; - if ( !isset($r['show_counts']) ) - $r['show_counts'] = 0; - if ( !isset($r['hide_empty']) ) - $r['hide_empty'] = 1; - if ( !isset($r['child_of']) ) - $r['child_of'] = 0; - if ( !isset($r['exclude']) ) - $r['exclude'] = ''; - if ( !isset($r['echo']) ) - $r['echo'] = 1; - if ( !isset($r['selected']) ) - $r['selected'] = 0; - if ( !isset($r['hierarchical']) ) - $r['hierarchical'] = 0; - if ( !isset($r['name']) ) - $r['name'] = 'cat'; - if ( !isset($r['class']) ) - $r['class'] = 'postform'; - + $defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID', + 'order' => 'ASC', 'show_last_update' => 0, 'show_counts' => 0, + 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, + 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', + 'class' => 'postform'); + $r = array_merge($defaults, $r); $r['include_last_update_time'] = $r['show_last_update']; - extract($r); $categories = get_categories($r); @@ -251,44 +227,17 @@ function wp_list_categories($args = '') { else parse_str($args, $r); - if ( !isset($r['optionall'])) - $r['optionall'] = 0; - if ( !isset($r['all'])) - $r['all'] = 'All'; - if ( !isset($r['sort_column']) ) - $r['sort_column'] = 'ID'; - if ( !isset($r['sort_order']) ) - $r['sort_order'] = 'asc'; - if ( !isset($r['file']) ) - $r['file'] = ''; - if ( !isset($r['list']) ) - $r['list'] = true; - if ( !isset($r['optiondates']) ) - $r['optiondates'] = 0; - if ( !isset($r['optioncount']) ) - $r['optioncount'] = 0; - if ( !isset($r['hide_empty']) ) - $r['hide_empty'] = 1; - if ( !isset($r['use_desc_for_title']) ) - $r['use_desc_for_title'] = 1; - if ( !isset($r['child_of']) ) - $r['child_of'] = 0; - if ( !isset($r['feed']) ) - $r['feed'] = ''; - if ( !isset($r['feed_image']) ) - $r['feed_image'] = ''; - if ( !isset($r['exclude']) ) - $r['exclude'] = ''; - if ( !isset($r['hierarchical']) ) - $r['hierarchical'] = false; - if ( !isset($r['title_li']) ) - $r['title_li'] = ''; - if ( !isset($r['orderby']) ) + $defaults = array('optionall' => 0, 'all' => 'All', 'sort_column' => 'ID', + 'sort_order' => 'asc', 'list' => true, 'optiondates' => 0, + 'optioncount' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, + 'child_of' => 0, 'feed' => '', 'feed_image' => '', 'exclude' => '', + 'hierarchical' => false, 'title_li' => ''); + $r = array_merge($defaults, $r); + if ( ! isset($r['orderby']) ) $r['orderby'] = $r['sort_column']; - if ( !isset($r['order']) ) - $r['order'] = $r['sort_order']; + if ( ! isset($r['order']) ) + $r['order'] = $r['sort_order']; $r['include_last_update_time'] = $r['optiondates']; - extract($r); $categories = get_categories($r); @@ -436,23 +385,10 @@ function &get_categories($args = '') { else parse_str($args, $r); - if ( !isset($r['type']) ) // 'post' or 'link' - $r['type'] = 'post'; - if ( !isset($r['child_of']) ) - $r['child_of'] = 0; - if ( !isset($r['orderby']) ) - $r['orderby'] = 'name'; - if ( !isset($r['order']) ) - $r['order'] = 'ASC'; - if ( !isset($r['hide_empty']) ) - $r['hide_empty'] = true; - if ( !isset($r['include_last_update_time']) ) - $r['include_last_update_time'] = false; - if ( !isset($r['hierarchical']) ) - $r['hierarchical'] = 1; - + $defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', + 'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1); + $r = array_merge($defaults, $r); $r['orderby'] = "cat_" . $r['orderby']; - extract($r); $exclusions = ''; diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php index 51380e584..3a95bd1d0 100644 --- a/wp-includes/template-functions-post.php +++ b/wp-includes/template-functions-post.php @@ -301,14 +301,9 @@ function &get_pages($args = '') { else parse_str($args, $r); - if ( !isset($r['child_of']) ) - $r['child_of'] = 0; - if ( !isset($r['sort_column']) ) - $r['sort_column'] = 'post_title'; - if ( !isset($r['sort_order']) ) - $r['sort_order'] = 'ASC'; - if ( !isset($r['hierarchical']) ) - $r['hierarchical'] = 1; + $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', + 'hierarchical' => 1); + $r = array_merge($defaults, $r); $exclusions = ''; if ( !empty($r['exclude']) ) { @@ -344,16 +339,9 @@ function wp_dropdown_pages($args = '') { else parse_str($args, $r); - if ( !isset($r['depth']) ) - $r['depth'] = 0; - if ( !isset($r['child_of']) ) - $r['child_of'] = 0; - if ( !isset($r['echo']) ) - $r['echo'] = 1; - if ( !isset($r['selected']) ) - $r['selected'] = 0; - if ( !isset($r['name']) ) - $r['name'] = 'page_id'; + $defaults = array('depth' => 0, 'child_of' => 0, 'selected' => 0, 'echo' => 1, + 'name' => 'page_id'); + $r = array_merge($defaults, $r); extract($r); $pages = get_pages($r); @@ -393,18 +381,9 @@ function wp_list_pages($args = '') { else parse_str($args, $r); - if ( !isset($r['depth']) ) - $r['depth'] = 0; - if ( !isset($r['show_date']) ) - $r['show_date'] = ''; - if ( !isset($r['date_format']) ) - $r['date_format'] = get_settings('date_format'); - if ( !isset($r['child_of']) ) - $r['child_of'] = 0; - if ( !isset($r['title_li']) ) - $r['title_li'] = __('Pages'); - if ( !isset($r['echo']) ) - $r['echo'] = 1; + $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_settings('date_format'), + 'child_of' => 0, 'title_li' => __('Pages'), 'echo' => 1); + $r = array_merge($defaults, $r); $output = '';