Ticket #3982: post-phpdoc.diff
| File post-phpdoc.diff, 16.5 kB (added by m0n5t3r, 2 years ago) |
|---|
-
wp-includes/post.php
old new 1 1 <?php 2 3 // 4 // Post functions 5 // 6 2 /** 3 * Post functions 4 * 5 * @author Wordpress team (FIXME) 6 * @version "$Id$" 7 * @copyright (FIXME) 8 * @package wordpress 9 * @subpackage post 10 */ 11 12 /** 13 * get metadata for an attached file 14 * 15 * @filter get_attached_file 16 * @param int $attachment_id attachment ID 17 * @param bool $unfiltered whether to applu filters or not 18 * @return array 19 */ 7 20 function get_attached_file( $attachment_id, $unfiltered = false ) { 8 21 $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); 9 22 if ( $unfiltered ) … … 11 24 return apply_filters( 'get_attached_file', $file, $attachment_id ); 12 25 } 13 26 27 /** 28 * update attached file metadata 29 * 30 * @filter update_attached_file 31 * @param int $attachment_id 32 * @param string $file 33 * @return bool 34 */ 14 35 function update_attached_file( $attachment_id, $file ) { 15 36 if ( !get_post( $attachment_id ) ) 16 37 return false; … … 25 46 return add_post_meta( $attachment_id, '_wp_attached_file', $file ); 26 47 } 27 48 49 /** 50 * get post children 51 * 52 * @param mixed $args 53 * @param string $output 54 * @return mixed 55 */ 28 56 function &get_children($args = '', $output = OBJECT) { 29 57 global $post_cache, $wpdb, $blog_id; 30 58 … … 71 99 } 72 100 } 73 101 74 // get extended entry info (<!--more-->) 102 /** 103 * get extended entry info (<!--more-->) 104 * 105 * @param string $post 106 * @return array 107 */ 75 108 function get_extended($post) { 76 109 //Match the new style more links 77 110 if ( preg_match('/<!--more(.*?)-->/', $post, $matches) ) { … … 88 121 return array('main' => $main, 'extended' => $extended); 89 122 } 90 123 91 // Retrieves post data given a post ID or post object. 92 // Handles post caching. 124 /** 125 * Retrieves post data given a post ID or post object. 126 * Handles post caching. 127 * 128 * @param mixed &$post post ID or post object 129 * @param string $output 130 * @return mixed 131 */ 93 132 function &get_post(&$post, $output = OBJECT) { 94 133 global $post_cache, $wpdb, $blog_id; 95 134 … … 133 172 } 134 173 } 135 174 136 // Takes a post ID, returns its mime type. 175 /** 176 * Takes a post ID, returns its mime type. 177 * 178 * @param int $ID 179 * @return mixed string or false 180 */ 137 181 function get_post_mime_type($ID = '') { 138 182 $post = & get_post($ID); 139 183 … … 143 187 return false; 144 188 } 145 189 190 /** 191 * Takes a post ID and returns its status 192 * 193 * @param int $ID 194 * @return mixed post status or false 195 */ 146 196 function get_post_status($ID = '') { 147 197 $post = get_post($ID); 148 198 … … 156 206 return false; 157 207 } 158 208 209 /** 210 * Returns post type 211 * 212 * @param mixed $post post object or post ID 213 * @return mixed post type or false 214 */ 159 215 function get_post_type($post = false) { 160 216 global $wpdb, $posts; 161 217 … … 170 226 return false; 171 227 } 172 228 229 /** 230 * returns a number of posts 231 * 232 * @param array $args 233 * @return array 234 */ 173 235 function get_posts($args) { 174 236 global $wpdb; 175 237 … … 254 316 return $posts; 255 317 } 256 318 257 // 258 // Post meta functions 259 // 260 319 /** 320 * adds metadata for post 321 * 322 * @param int $post_id post ID 323 * @param string $key 324 * @param mixed $value 325 * @param bool $unique whether to check for a value with the same key 326 * @return bool 327 */ 261 328 function add_post_meta($post_id, $key, $value, $unique = false) { 262 329 global $wpdb, $post_meta_cache, $blog_id; 263 330 … … 279 346 return true; 280 347 } 281 348 349 /** 350 * delete post metadata 351 * 352 * @param int $post_id post ID 353 * @param string $key 354 * @param mixed $value 355 * @return bool 356 */ 282 357 function delete_post_meta($post_id, $key, $value = '') { 283 358 global $wpdb, $post_meta_cache, $blog_id; 284 359 … … 309 384 return true; 310 385 } 311 386 387 /** 388 * get a post meta field 389 * 390 * @param int $post_id post ID 391 * @param string $key 392 * @param bool $single whether to return a single value 393 * @return mixed 394 */ 312 395 function get_post_meta($post_id, $key, $single = false) { 313 396 global $wpdb, $post_meta_cache, $blog_id; 314 397 … … 335 418 } 336 419 } 337 420 421 /** 422 * update a post meta field 423 * 424 * @param int $post_id post ID 425 * @param string $key 426 * @param mixed $value 427 * @param mixed $prev_value previous value (for differentiating between meta fields with the same key and post ID) 428 * @return bool 429 */ 338 430 function update_post_meta($post_id, $key, $value, $prev_value = '') { 339 431 global $wpdb, $post_meta_cache, $blog_id; 340 432 … … 371 463 } 372 464 373 465 466 /** 467 * retrieve post custom fields 468 * 469 * @param int $post_id post ID 470 * @return array 471 */ 374 472 function get_post_custom($post_id = 0) { 375 473 global $id, $post_meta_cache, $wpdb, $blog_id; 376 474 … … 385 483 return $post_meta_cache[$blog_id][$post_id]; 386 484 } 387 485 486 /** 487 * retrieve post custom field names 488 * 489 * @param int $post_id post ID 490 * @return array 491 */ 388 492 function get_post_custom_keys( $post_id = 0 ) { 389 493 $custom = get_post_custom( $post_id ); 390 494 … … 396 500 } 397 501 398 502 503 /** 504 * retrieve values for a custom post field 505 * 506 * @param string $key field name 507 * @param int $post_id post ID 508 * @return mixed 509 */ 399 510 function get_post_custom_values( $key = '', $post_id = 0 ) { 400 511 $custom = get_post_custom($post_id); 401 512 402 513 return $custom[$key]; 403 514 } 404 515 516 /** 517 * delete post 518 * 519 * @action delete_post 520 * @action edit_category 521 * @param int $postid post ID 522 * @return mixed 523 */ 405 524 function wp_delete_post($postid = 0) { 406 525 global $wpdb, $wp_rewrite; 407 526 $postid = (int) $postid; … … 446 565 return $post; 447 566 } 448 567 568 /** 569 * retrieve the list of categories for a post 570 * 571 * @param int $post_id post ID 572 * @return array 573 */ 449 574 function wp_get_post_categories($post_id = 0) { 450 575 $cats = &get_the_category($post_id); 451 576 $cat_ids = array(); … … 454 579 return array_unique($cat_ids); 455 580 } 456 581 582 /** 583 * get the $num most recent posts 584 * 585 * @param int $num number of posts to get 586 * @return array 587 */ 457 588 function wp_get_recent_posts($num = 10) { 458 589 global $wpdb; 459 590 … … 468 599 return $result?$result:array(); 469 600 } 470 601 602 /** 603 * get one post 604 * 605 * @param int $postid post ID 606 * @param string $mode what to return 607 * @return mixed 608 */ 471 609 function wp_get_single_post($postid = 0, $mode = OBJECT) { 472 610 global $wpdb; 473 611 … … 484 622 return $post; 485 623 } 486 624 625 /** 626 * insert a post 627 * 628 * @filter content_save_pre 629 * @filter content_filtered_save_pre 630 * @filter excerpt_save_pre 631 * @filter title_save_pre 632 * @filter category_save_pre 633 * @filter status_save_pre 634 * @filter name_save_pre 635 * @filter comment_status_pre 636 * @filter ping_status_pre 637 * @action private_to_published 638 * @action edit_post 639 * @action publish_post 640 * @action xmlrpc_publish_post 641 * @action app_publish_post 642 * @action publish_page 643 * @action save_post 644 * @action wp_insert_post 645 * @param array $postarr post contents 646 * @return int post ID or 0 on error 647 */ 487 648 function wp_insert_post($postarr = array()) { 488 649 global $wpdb, $wp_rewrite, $allowedtags, $user_ID; 489 650 … … 712 873 return $post_ID; 713 874 } 714 875 876 /** 877 * update a post 878 * 879 * @param array $postarr post data 880 * @return int 881 */ 715 882 function wp_update_post($postarr = array()) { 716 883 global $wpdb; 717 884 … … 752 919 return wp_insert_post($postarr); 753 920 } 754 921 922 /** 923 * mark a post as "published" 924 * 925 * @param int $post_id post ID 926 * @return mixed int or void 927 */ 755 928 function wp_publish_post($post_id) { 756 929 $post = get_post($post_id); 757 930 758 if ( empty($post) ) 931 if ( empty($post) ) //FIXME: inconsistent error handling, should return 0 759 932 return; 760 933 761 934 if ( 'publish' == $post->post_status ) … … 764 937 return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id, 'no_filter' => true)); 765 938 } 766 939 940 /** 941 * set categories for a post 942 * 943 * @action edit_category 944 * @param int $post_ID post ID 945 * @param array $post_categories 946 */ 767 947 function wp_set_post_categories($post_ID = 0, $post_categories = array()) { 768 948 global $wpdb; 769 949 // If $post_categories isn't already an array, make it one: … … 820 1000 } 821 1001 } // wp_set_post_categories() 822 1002 823 / /824 //Trackback and ping functions825 //1003 /** 1004 * Trackback and ping functions 1005 */ 826 1006 827 function add_ping($post_id, $uri) { // Add a URL to those already pung 1007 /** 1008 * add URL to the pinged URLs list 1009 * 1010 * @filter add_ping 1011 * @param int $post_id post ID 1012 * @param string $uri 1013 * @return mixed 1014 */ 1015 function add_ping($post_id, $uri) { 828 1016 global $wpdb; 829 1017 $pung = $wpdb->get_var("SELECT pinged FROM $wpdb->posts WHERE ID = $post_id"); 830 1018 $pung = trim($pung); … … 835 1023 return $wpdb->query("UPDATE $wpdb->posts SET pinged = '$new' WHERE ID = $post_id"); 836 1024 } 837 1025 838 function get_enclosed($post_id) { // Get enclosures already enclosed for a post 1026 /** 1027 * Get enclosures already enclosed for a post 1028 * 1029 * @filter get_enclosed 1030 * @param int $post_id post ID 1031 * @return array 1032 */ 1033 function get_enclosed($post_id) { 839 1034 global $wpdb; 840 1035 $custom_fields = get_post_custom( $post_id ); 841 1036 $pung = array(); … … 854 1049 return $pung; 855 1050 } 856 1051 857 function get_pung($post_id) { // Get URLs already pung for a post 1052 /** 1053 * Get URLs already pinged for a post 1054 * 1055 * @filter get_pung 1056 * @param int $post_id post ID 1057 * @return array 1058 */ 1059 function get_pung($post_id) { 858 1060 global $wpdb; 859 1061 $pung = $wpdb->get_var("SELECT pinged FROM $wpdb->posts WHERE ID = $post_id"); 860 1062 $pung = trim($pung); … … 863 1065 return $pung; 864 1066 } 865 1067 866 function get_to_ping($post_id) { // Get any URLs in the todo list 1068 /** 1069 * Get any URLs in the todo list 1070 * 1071 * @filter get_to_ping 1072 * @param int $post_id post ID 1073 * @return array 1074 */ 1075 function get_to_ping($post_id) { 867 1076 global $wpdb; 868 1077 $to_ping = $wpdb->get_var("SELECT to_ping FROM $wpdb->posts WHERE ID = $post_id"); 869 1078 $to_ping = trim($to_ping); … … 872 1081 return $to_ping; 873 1082 } 874 1083 875 // do trackbacks for a list of urls 876 // accepts a comma-separated list of trackback urls and a post id 1084 /** 1085 * do trackbacks for a list of urls 1086 * 1087 * @param string $tb_list comma separated list of URLs 1088 * @param int $post_id post ID 1089 */ 877 1090 function trackback_url_list($tb_list, $post_id) { 878 1091 if (!empty($tb_list)) { 879 1092 // get post data … … 897 1110 } 898 1111 } 899 1112 900 / /901 //Page functions902 //1113 /** 1114 * Page functions 1115 */ 903 1116 1117 /** 1118 * get a list of page IDs 1119 * handles caching 1120 * 1121 * @return array 1122 */ 904 1123 function get_all_page_ids() { 905 1124 global $wpdb; 906 1125 … … 913 1132 } 914 1133 915 1134 916 // Retrieves page data given a page ID or page object. 917 // Handles page caching. 1135 /** 1136 * retrieves page data given a page ID or page object 1137 * 1138 * @param mixed &$page page object or page ID 1139 * @param string $output what to output 1140 * @return mixed 1141 */ 918 1142 function &get_page(&$page, $output = OBJECT) { 919 1143 global $wpdb, $blog_id; 920 1144 … … 967 1191 } 968 1192 } 969 1193 1194 /** 1195 * retrieves a page given its path 1196 * 1197 * @param string $page_path page path 1198 * @param string $output output type 1199 * @return mixed 1200 */ 970 1201 function get_page_by_path($page_path, $output = OBJECT) { 971 1202 global $wpdb; 972 1203 $page_path = rawurlencode(urldecode($page_path)); … … 998 1229 return NULL; 999 1230 } 1000 1231 1232 /** 1233 * retrieve a page given its title 1234 * 1235 * @param string $page_title page title 1236 * @param string $output output type 1237 * @return mixed 1238 */ 1001 1239 function get_page_by_title($page_title, $output = OBJECT) { 1002 1240 global $wpdb; 1003 1241 $page_title = $wpdb->escape($page_title); … … 1008 1246 return NULL; 1009 1247 } 1010 1248 1249 /** 1250 * retrieve child pages 1251 * 1252 * @param int $page_id page ID 1253 * @param array $pages list of pages 1254 * @return array 1255 */ 1011 1256 function &get_page_children($page_id, $pages) { 1012 1257 global $page_cache, $blog_id; 1013 1258 … … 1025 1270 return $page_list; 1026 1271 } 1027 1272 1028 //fetches the pages returned as a FLAT list, but arranged in order of their hierarchy, i.e., child parents 1029 //immediately follow their parents 1273 /** 1274 * fetches the pages returned as a FLAT list, but arranged in order of their hierarchy, i.e., child parents 1275 * immediately follow their parents 1276 * 1277 * @param array $posts posts array 1278 * @param int $parent parent page ID 1279 * @return array 1280 */ 1030 1281 function get_page_hierarchy($posts, $parent = 0) { 1031 1282 $result = array ( ); 1032 1283 if ($posts) { foreach ($posts as $post) { … … 1039 1290 return $result; 1040 1291 } 1041 1292 1293 /** 1294 * builds a page URI 1295 * 1296 * @param int $page_id page ID 1297 * @return string 1298 */ 1042 1299 function get_page_uri($page_id) { 1043 1300 $page = get_page($page_id); 1044 1301 $uri = urldecode($page->post_name); … … 1055 1312 return $uri; 1056 1313 } 1057 1314 1315 /** 1316 * retrieve a list of pages 1317 * 1318 * @filter get_pages 1319 * @param mixed $args array or query string 1320 * @return array 1321 */ 1058 1322 function &get_pages($args = '') { 1059 1323 global $wpdb; 1060 1324 … … 1158 1422 return $pages; 1159 1423 } 1160 1424 1425 /** 1426 * build page URI index 1427 * 1428 */ 1161 1429 function generate_page_uri_index() { 1162 1430 global $wpdb; 1163 1431 … … 1196 1464 } 1197 1465 } 1198 1466 1199 / /1200 //Attachment functions1201 //1467 /** 1468 * Attachment functions 1469 */ 1202 1470 1471 /** 1472 * check if the attachment URI is a local one and it is really an attachment 1473 * 1474 * @param string $url URL to check 1475 * @return bool 1476 */ 1203 1477 function is_local_attachment($url) { 1204 1478 if (strpos($url, get_bloginfo('url')) === false) 1205 1479 return false; … … 1213 1487 return false; 1214 1488 } 1215 1489 1490 /** 1491 * insert an attachment 1492 * 1493 * @filter content_save_pre 1494 * @filter content_filtered_save_pre 1495 * @filter excerpt_save_pre 1496 * @filter title_save_pre 1497 * @filter category_save_pre 1498 * @filter name_save_pre 1499 * @filter comment_status_pre 1500 * @filter ping_status_pre 1501 * @filter post_mime_type_pre 1502 * @action edit_attachment 1503 * @action add_attachment 1504 * @param object $object attachment object 1505 * @param string $file filename 1506 * @param int $post_parent parent post ID 1507 * @return int 1508 */ 1216 1509 function wp_insert_attachment($object, $file = false, $post_parent = 0) { 1217 1510 global $wpdb, $user_ID; 1218 1511 … … 1368 1661 return $post_ID; 1369 1662 } 1370 1663 1664 /** 1665 * delete an attachment 1666 * 1667 * @filter wp_delete_file 1668 * @action delete_attachment 1669 * @param int $postid attachment Id 1670 * @return mixed 1671 */ 1371 1672 function wp_delete_attachment($postid) { 1372 1673 global $wpdb; 1373 1674 $postid = (int) $postid; … … 1408 1709 return $post; 1409 1710 } 1410 1711 1712 /** 1713 * retrieve metadata for an attachment 1714 * 1715 * @filter wp_get_attachment_metadata 1716 * @param int $post_id attachment ID 1717 * @param bool $unfiltered if true, filters are not ran 1718 * @return array 1719 */ 1411 1720 function wp_get_attachment_metadata( $post_id, $unfiltered = false ) { 1412 1721 $post_id = (int) $post_id; 1413 1722 if ( !$post =& get_post( $post_id ) ) … … 1419 1728 return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID ); 1420 1729 } 1421 1730 1731 /** 1732 * update metadata for an attachment 1733 * 1734 * @filter wp_update_attachment_metadata 1735 * @param int $post_id attachment ID 1736 * @param array $data attachment data 1737 * @return int 1738 */ 1422 1739 function wp_update_attachment_metadata( $post_id, $data ) { 1423 1740 $post_id = (int) $post_id; 1424 1741 if ( !$post =& get_post( $post_id ) ) … … 1434 1751 return add_post_meta( $post->ID, '_wp_attachment_metadata', $data ); 1435 1752 } 1436 1753 1754 /** 1755 * retrieve the URL for an attachment 1756 * 1757 * @filter wp_get_attachment_url 1758 * @param int $post_id attachment ID 1759 * @return string 1760 */ 1437 1761 function wp_get_attachment_url( $post_id = 0 ) { 1438 1762 $post_id = (int) $post_id; 1439 1763 if ( !$post =& get_post( $post_id ) ) … … 1447 1771 return apply_filters( 'wp_get_attachment_url', $url, $post->ID ); 1448 1772 } 1449 1773 1774 /** 1775 * retrieve thumbnail for an attachment 1776 * 1777 * @filter wp_get_attachment_thumb_file 1778 * @param int $post_id attachment ID 1779 * @return mixed 1780 */ 1450 1781 function wp_get_attachment_thumb_file( $post_id = 0 ) { 1451 1782 $post_id = (int) $post_id; 1452 1783 if ( !$post =& get_post( $post_id ) ) … … 1461 1792 return false; 1462 1793 } 1463 1794 1795 /** 1796 * retrieve URL for an attachment thumbnail 1797 * 1798 * @filter wp_get_attachment_thumb_url 1799 * @param int $post_id attachment ID 1800 * @return string 1801 */ 1464 1802 function wp_get_attachment_thumb_url( $post_id = 0 ) { 1465 1803 $post_id = (int) $post_id; 1466 1804 if ( !$post =& get_post( $post_id ) ) … … 1476 1814 return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID ); 1477 1815 } 1478 1816 1817 /** 1818 * check if the attachment is an image 1819 * 1820 * @param int $post_id attachment ID 1821 * @return bool 1822 */ 1479 1823 function wp_attachment_is_image( $post_id = 0 ) { 1480 1824 $post_id = (int) $post_id; 1481 1825 if ( !$post =& get_post( $post_id ) ) … … 1493 1837 return false; 1494 1838 } 1495 1839 1840 /** 1841 * retrieve the icon for a MIME type 1842 * 1843 * @filter icon_dir 1844 * @filter icon_dir_uri 1845 * @filter wp_mime_type_icon 1846 * @param string $mime MIME type 1847 * @return string 1848 */ 1496 1849 function wp_mime_type_icon( $mime = 0 ) { 1497 1850 $post_id = 0; 1498 1851 if ( is_numeric($mime) ) { … … 1532 1885 return apply_filters( 'wp_mime_type_icon', $src, $mime, $post_id ); // Last arg is 0 if function pass mime type. 1533 1886 } 1534 1887 1888 /** 1889 * store slug history as custom fields; only looks at published posts 1890 * 1891 * @param int $post_id post ID 1892 * @return int 1893 */ 1535 1894 function wp_check_for_changed_slugs($post_id) { 1536 1895 if ( !strlen($_POST['wp-old-slug']) ) 1537 1896 return $post_id;
