PHP Cross Reference of WordPress Subversion HEAD |
| [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * Deprecated global variables. 5 */ 6 7 $tableposts = $wpdb->posts; 8 $tableusers = $wpdb->users; 9 $tablecategories = $wpdb->categories; 10 $tablepost2cat = $wpdb->post2cat; 11 $tablecomments = $wpdb->comments; 12 $tablelinks = $wpdb->links; 13 $tablelinkcategories = 'linkcategories_is_gone'; 14 $tableoptions = $wpdb->options; 15 $tablepostmeta = $wpdb->postmeta; 16 17 /* 18 * Deprecated functions come here to die. 19 */ 20 21 // Use get_post(). 22 function get_postdata($postid) { 23 $post = &get_post($postid); 24 25 $postdata = array ( 26 'ID' => $post->ID, 27 'Author_ID' => $post->post_author, 28 'Date' => $post->post_date, 29 'Content' => $post->post_content, 30 'Excerpt' => $post->post_excerpt, 31 'Title' => $post->post_title, 32 'Category' => $post->post_category, 33 'post_status' => $post->post_status, 34 'comment_status' => $post->comment_status, 35 'ping_status' => $post->ping_status, 36 'post_password' => $post->post_password, 37 'to_ping' => $post->to_ping, 38 'pinged' => $post->pinged, 39 'post_type' => $post->post_type, 40 'post_name' => $post->post_name 41 ); 42 43 return $postdata; 44 } 45 46 // Use the new post loop. 47 function start_wp() { 48 global $wp_query, $post; 49 50 // Since the old style loop is being used, advance the query iterator here. 51 $wp_query->next_post(); 52 53 setup_postdata($post); 54 } 55 56 function the_category_ID($echo = true) { 57 // Grab the first cat in the list. 58 $categories = get_the_category(); 59 $cat = $categories[0]->term_id; 60 61 if ( $echo ) 62 echo $cat; 63 64 return $cat; 65 } 66 67 function the_category_head($before='', $after='') { 68 global $currentcat, $previouscat; 69 // Grab the first cat in the list. 70 $categories = get_the_category(); 71 $currentcat = $categories[0]->category_id; 72 if ( $currentcat != $previouscat ) { 73 echo $before; 74 echo get_the_category_by_ID($currentcat); 75 echo $after; 76 $previouscat = $currentcat; 77 } 78 } 79 80 // Use previous_post_link(). 81 function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') { 82 83 if ( empty($in_same_cat) || 'no' == $in_same_cat ) 84 $in_same_cat = false; 85 else 86 $in_same_cat = true; 87 88 $post = get_previous_post($in_same_cat, $excluded_categories); 89 90 if ( !$post ) 91 return; 92 93 $string = '<a href="'.get_permalink($post->ID).'">'.$previous; 94 if ( 'yes' == $title ) 95 $string .= apply_filters('the_title', $post->post_title, $post); 96 $string .= '</a>'; 97 $format = str_replace('%', $string, $format); 98 echo $format; 99 } 100 101 // Use next_post_link(). 102 function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') { 103 104 if ( empty($in_same_cat) || 'no' == $in_same_cat ) 105 $in_same_cat = false; 106 else 107 $in_same_cat = true; 108 109 $post = get_next_post($in_same_cat, $excluded_categories); 110 111 if ( !$post ) 112 return; 113 114 $string = '<a href="'.get_permalink($post->ID).'">'.$next; 115 if ( 'yes' == $title ) 116 $string .= apply_filters('the_title', $post->post_title, $nextpost); 117 $string .= '</a>'; 118 $format = str_replace('%', $string, $format); 119 echo $format; 120 } 121 122 // 123 // Use current_user_can() for these. 124 // 125 126 /* returns true if $user_id can create a new post */ 127 function user_can_create_post($user_id, $blog_id = 1, $category_id = 'None') { 128 $author_data = get_userdata($user_id); 129 return ($author_data->user_level > 1); 130 } 131 132 /* returns true if $user_id can create a new post */ 133 function user_can_create_draft($user_id, $blog_id = 1, $category_id = 'None') { 134 $author_data = get_userdata($user_id); 135 return ($author_data->user_level >= 1); 136 } 137 138 /* returns true if $user_id can edit $post_id */ 139 function user_can_edit_post($user_id, $post_id, $blog_id = 1) { 140 $author_data = get_userdata($user_id); 141 $post = get_post($post_id); 142 $post_author_data = get_userdata($post->post_author); 143 144 if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' && $author_data->user_level < 2)) 145 || ($author_data->user_level > $post_author_data->user_level) 146 || ($author_data->user_level >= 10) ) { 147 return true; 148 } else { 149 return false; 150 } 151 } 152 153 /* returns true if $user_id can delete $post_id */ 154 function user_can_delete_post($user_id, $post_id, $blog_id = 1) { 155 // right now if one can edit, one can delete 156 return user_can_edit_post($user_id, $post_id, $blog_id); 157 } 158 159 /* returns true if $user_id can set new posts' dates on $blog_id */ 160 function user_can_set_post_date($user_id, $blog_id = 1, $category_id = 'None') { 161 $author_data = get_userdata($user_id); 162 return (($author_data->user_level > 4) && user_can_create_post($user_id, $blog_id, $category_id)); 163 } 164 165 /* returns true if $user_id can edit $post_id's date */ 166 function user_can_edit_post_date($user_id, $post_id, $blog_id = 1) { 167 $author_data = get_userdata($user_id); 168 return (($author_data->user_level > 4) && user_can_edit_post($user_id, $post_id, $blog_id)); 169 } 170 171 /* returns true if $user_id can edit $post_id's comments */ 172 function user_can_edit_post_comments($user_id, $post_id, $blog_id = 1) { 173 // right now if one can edit a post, one can edit comments made on it 174 return user_can_edit_post($user_id, $post_id, $blog_id); 175 } 176 177 /* returns true if $user_id can delete $post_id's comments */ 178 function user_can_delete_post_comments($user_id, $post_id, $blog_id = 1) { 179 // right now if one can edit comments, one can delete comments 180 return user_can_edit_post_comments($user_id, $post_id, $blog_id); 181 } 182 183 function user_can_edit_user($user_id, $other_user) { 184 $user = get_userdata($user_id); 185 $other = get_userdata($other_user); 186 if ( $user->user_level > $other->user_level || $user->user_level > 8 || $user->ID == $other->ID ) 187 return true; 188 else 189 return false; 190 } 191 192 /** function get_linksbyname() 193 ** Gets the links associated with category 'cat_name'. 194 ** Parameters: 195 ** cat_name (default 'noname') - The category name to use. If no 196 ** match is found uses all 197 ** before (default '') - the html to output before the link 198 ** after (default '<br />') - the html to output after the link 199 ** between (default ' ') - the html to output between the link/image 200 ** and it's description. Not used if no image or show_images == true 201 ** show_images (default true) - whether to show images (if defined). 202 ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', 203 ** 'url', 'description' or 'rating'. Or maybe owner. If you start the 204 ** name with an underscore the order will be reversed. 205 ** You can also specify 'rand' as the order which will return links in a 206 ** random order. 207 ** show_description (default true) - whether to show the description if 208 ** show_images=false/not defined 209 ** show_rating (default false) - show rating stars/chars 210 ** limit (default -1) - Limit to X entries. If not specified, all entries 211 ** are shown. 212 ** show_updated (default 0) - whether to show last updated timestamp 213 */ 214 function get_linksbyname($cat_name = "noname", $before = '', $after = '<br />', 215 $between = " ", $show_images = true, $orderby = 'id', 216 $show_description = true, $show_rating = false, 217 $limit = -1, $show_updated = 0) { 218 global $wpdb; 219 $cat_id = -1; 220 $cat = get_term_by('name', $cat_name, 'link_category'); 221 if ( $cat ) 222 $cat_id = $cat->term_id; 223 224 get_links($cat_id, $before, $after, $between, $show_images, $orderby, 225 $show_description, $show_rating, $limit, $show_updated); 226 } 227 228 /** function wp_get_linksbyname() 229 ** Gets the links associated with the named category. 230 ** Parameters: 231 ** category (no default) - The category to use. 232 **/ 233 function wp_get_linksbyname($category, $args = '') { 234 global $wpdb; 235 236 $cat = get_term_by('name', $cat_name, 'link_category'); 237 if ( !$cat ) 238 return false; 239 $cat_id = $cat->term_id; 240 241 $args = add_query_arg('category', $cat_id, $args); 242 wp_get_links($args); 243 } 244 245 /** function get_linkobjectsbyname() 246 ** Gets an array of link objects associated with category 'cat_name'. 247 ** Parameters: 248 ** cat_name (default 'noname') - The category name to use. If no 249 ** match is found uses all 250 ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', 251 ** 'url', 'description', or 'rating'. Or maybe owner. If you start the 252 ** name with an underscore the order will be reversed. 253 ** You can also specify 'rand' as the order which will return links in a 254 ** random order. 255 ** limit (default -1) - Limit to X entries. If not specified, all entries 256 ** are shown. 257 ** 258 ** Use this like: 259 ** $links = get_linkobjectsbyname('fred'); 260 ** foreach ($links as $link) { 261 ** echo '<li>'.$link->link_name.'</li>'; 262 ** } 263 **/ 264 function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) { 265 global $wpdb; 266 $cat_id = -1; 267 $cat = get_term_by('name', $cat_name, 'link_category'); 268 if ( $cat ) 269 $cat_id = $cat->term_id; 270 271 return get_linkobjects($cat_id, $orderby, $limit); 272 } 273 274 /** function get_linkobjects() 275 ** Gets an array of link objects associated with category n. 276 ** Parameters: 277 ** category (default -1) - The category to use. If no category supplied 278 ** uses all 279 ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', 280 ** 'url', 'description', or 'rating'. Or maybe owner. If you start the 281 ** name with an underscore the order will be reversed. 282 ** You can also specify 'rand' as the order which will return links in a 283 ** random order. 284 ** limit (default -1) - Limit to X entries. If not specified, all entries 285 ** are shown. 286 ** 287 ** Use this like: 288 ** $links = get_linkobjects(1); 289 ** if ($links) { 290 ** foreach ($links as $link) { 291 ** echo '<li>'.$link->link_name.'<br />'.$link->link_description.'</li>'; 292 ** } 293 ** } 294 ** Fields are: 295 ** link_id 296 ** link_url 297 ** link_name 298 ** link_image 299 ** link_target 300 ** link_category 301 ** link_description 302 ** link_visible 303 ** link_owner 304 ** link_rating 305 ** link_updated 306 ** link_rel 307 ** link_notes 308 **/ 309 // Deprecate in favor of get_linkz(). 310 function get_linkobjects($category = 0, $orderby = 'name', $limit = 0) { 311 global $wpdb; 312 313 $links = get_bookmarks("category=$category&orderby=$orderby&limit=$limit"); 314 315 $links_array = array(); 316 foreach ($links as $link) { 317 $links_array[] = $link; 318 } 319 320 return $links_array; 321 } 322 323 /** function get_linksbyname_withrating() 324 ** Gets the links associated with category 'cat_name' and display rating stars/chars. 325 ** Parameters: 326 ** cat_name (default 'noname') - The category name to use. If no 327 ** match is found uses all 328 ** before (default '') - the html to output before the link 329 ** after (default '<br />') - the html to output after the link 330 ** between (default ' ') - the html to output between the link/image 331 ** and it's description. Not used if no image or show_images == true 332 ** show_images (default true) - whether to show images (if defined). 333 ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', 334 ** 'url' or 'description'. Or maybe owner. If you start the 335 ** name with an underscore the order will be reversed. 336 ** You can also specify 'rand' as the order which will return links in a 337 ** random order. 338 ** show_description (default true) - whether to show the description if 339 ** show_images=false/not defined 340 ** limit (default -1) - Limit to X entries. If not specified, all entries 341 ** are shown. 342 ** show_updated (default 0) - whether to show last updated timestamp 343 */ 344 function get_linksbyname_withrating($cat_name = "noname", $before = '', 345 $after = '<br />', $between = " ", 346 $show_images = true, $orderby = 'id', 347 $show_description = true, $limit = -1, $show_updated = 0) { 348 349 get_linksbyname($cat_name, $before, $after, $between, $show_images, 350 $orderby, $show_description, true, $limit, $show_updated); 351 } 352 353 /** function get_links_withrating() 354 ** Gets the links associated with category n and display rating stars/chars. 355 ** Parameters: 356 ** category (default -1) - The category to use. If no category supplied 357 ** uses all 358 ** before (default '') - the html to output before the link 359 ** after (default '<br />') - the html to output after the link 360 ** between (default ' ') - the html to output between the link/image 361 ** and it's description. Not used if no image or show_images == true 362 ** show_images (default true) - whether to show images (if defined). 363 ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', 364 ** 'url' or 'description'. Or maybe owner. If you start the 365 ** name with an underscore the order will be reversed. 366 ** You can also specify 'rand' as the order which will return links in a 367 ** random order. 368 ** show_description (default true) - whether to show the description if 369 ** show_images=false/not defined . 370 ** limit (default -1) - Limit to X entries. If not specified, all entries 371 ** are shown. 372 ** show_updated (default 0) - whether to show last updated timestamp 373 */ 374 function get_links_withrating($category = -1, $before = '', $after = '<br />', 375 $between = " ", $show_images = true, 376 $orderby = 'id', $show_description = true, 377 $limit = -1, $show_updated = 0) { 378 379 get_links($category, $before, $after, $between, $show_images, $orderby, 380 $show_description, true, $limit, $show_updated); 381 } 382 383 /** function get_get_autotoggle() 384 ** Gets the auto_toggle setting of category n. 385 ** Parameters: id (default 0) - The category to get. If no category supplied 386 ** uses 0 387 */ 388 function get_autotoggle($id = 0) { 389 return 0; 390 } 391 392 // Use wp_list_cats(). 393 function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '', $hierarchical=FALSE) { 394 $query = compact('optionall', 'all', 'sort_column', 'sort_order', 'file', 'list', 'optiondates', 'optioncount', 'hide_empty', 'use_desc_for_title', 'children', 395 'child_of', 'categories', 'recurse', 'feed', 'feed_image', 'exclude', 'hierarchical'); 396 return wp_list_cats($query); 397 } 398 399 function wp_list_cats($args = '') { 400 $r = wp_parse_args( $args ); 401 402 // Map to new names. 403 if ( isset($r['optionall']) && isset($r['all'])) 404 $r['show_option_all'] = $r['all']; 405 if ( isset($r['sort_column']) ) 406 $r['orderby'] = $r['sort_column']; 407 if ( isset($r['sort_order']) ) 408 $r['order'] = $r['sort_order']; 409 if ( isset($r['optiondates']) ) 410 $r['show_last_update'] = $r['optiondates']; 411 if ( isset($r['optioncount']) ) 412 $r['show_count'] = $r['optioncount']; 413 if ( isset($r['list']) ) 414 $r['style'] = $r['list'] ? 'list' : 'break'; 415 $r['title_li'] = ''; 416 417 return wp_list_categories($r); 418 } 419 420 function dropdown_cats($optionall = 1, $all = 'All', $orderby = 'ID', $order = 'asc', 421 $show_last_update = 0, $show_count = 0, $hide_empty = 1, $optionnone = FALSE, 422 $selected = 0, $exclude = 0) { 423 424 $show_option_all = ''; 425 if ( $optionall ) 426 $show_option_all = $all; 427 428 $show_option_none = ''; 429 if ( $optionnone ) 430 $show_option_none = __('None'); 431 432 $vars = compact('show_option_all', 'show_option_none', 'orderby', 'order', 433 'show_last_update', 'show_count', 'hide_empty', 'selected', 'exclude'); 434 $query = add_query_arg($vars, ''); 435 return wp_dropdown_categories($query); 436 } 437 438 // Use wp_print_scripts() or WP_Scripts. 439 function tinymce_include() { 440 wp_print_script('wp_tiny_mce'); 441 } 442 443 function list_authors($optioncount = false, $exclude_admin = true, $show_fullname = false, $hide_empty = true, $feed = '', $feed_image = '') { 444 $args = compact('optioncount', 'exclude_admin', 'show_fullname', 'hide_empty', 'feed', 'feed_image'); 445 return wp_list_authors($args); 446 } 447 448 function wp_get_post_cats($blogid = '1', $post_ID = 0) { 449 return wp_get_post_categories($post_ID); 450 } 451 452 function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) { 453 return wp_set_post_categories($post_ID, $post_categories); 454 } 455 456 // Use wp_get_archives(). 457 function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) { 458 $args = compact('type', 'limit', 'format', 'before', 'after', 'show_post_count'); 459 return wp_get_archives($args); 460 } 461 462 // Use get_author_posts_url(). 463 function get_author_link($echo = false, $author_id, $author_nicename = '') { 464 $link = get_author_posts_url($author_id, $author_nicename); 465 466 if ( $echo ) 467 echo $link; 468 return $link; 469 } 470 471 // Use wp_link_pages(). 472 function link_pages($before='<br />', $after='<br />', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') { 473 $args = compact('before', 'after', 'next_or_number', 'nextpagelink', 'previouspagelink', 'pagelink', 'more_file'); 474 return wp_link_pages($args); 475 } 476 477 // Use get_option(). 478 function get_settings($option) { 479 return get_option($option); 480 } 481 482 // Use the_permalink(). 483 function permalink_link() { 484 the_permalink(); 485 } 486 487 // Use the_permalink_rss() 488 function