Changeset 8092 for trunk/wp-includes/functions.php
- Timestamp:
- 06/15/2008 09:38:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r8087 r8092 1 1 <?php 2 2 /** 3 * Main WordPress API 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Converts MySQL DATETIME field to user specified date format. 10 * 11 * If $dateformatstring has 'G' value, then gmmktime() function will be used to 12 * make the time. If $dateformatstring is set to 'U', then mktime() function 13 * will be used to make the time. 14 * 15 * The $translate will only be used, if it is set to true and it is by default 16 * and if the $wp_locale object has the month and weekday set. 17 * 18 * @since 0.71 19 * 20 * @param string $dateformatstring Either 'G', 'U', or php date format. 21 * @param string $mysqlstring Time from mysql DATETIME field. 22 * @param bool $translate Optional. Default is true. Will switch format to locale. 23 * @return string Date formated by $dateformatstring or locale (if available). 24 */ 3 25 function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { 4 26 global $wp_locale; … … 52 74 } 53 75 54 76 /** 77 * Retrieve the current time based on specified type. 78 * 79 * The 'mysql' type will return the time in the format for MySQL DATETIME field. 80 * The 'timestamp' type will return the current timestamp. 81 * 82 * If the $gmt is set to either '1' or 'true', then both types will use the 83 * GMT offset in the WordPress option to add the GMT offset to the time. 84 * 85 * @since 1.0.0 86 * 87 * @param string $type Either 'mysql' or 'timestamp'. 88 * @param int|bool $gmt Optional. Whether to use $gmt offset. Default is false. 89 * @return unknown 90 */ 55 91 function current_time( $type, $gmt = 0 ) { 56 92 switch ( $type ) { … … 89 125 } 90 126 91 127 /** 128 * Convert number to format based on the locale. 129 * 130 * @since 2.3.0 131 * 132 * @param mixed $number The number to convert based on locale. 133 * @param int $decimals Precision of the number of decimal places. 134 * @return string Converted number in string format. 135 */ 92 136 function number_format_i18n( $number, $decimals = null ) { 93 137 global $wp_locale; … … 98 142 } 99 143 100 144 /** 145 * Convert number of bytes largest unit bytes will fit into. 146 * 147 * It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts 148 * number of bytes to human readable number by taking the number of that unit 149 * that the bytes will go into it. Supports TB value. 150 * 151 * Please note that integers in PHP are limited to 32 bits, unless they are on 152 * 64 bit architecture, then they have 64 bit size. If you need to place the 153 * larger size then what PHP integer type will hold, then use a string. It will 154 * be converted to a double, which should always have 64 bit length. 155 * 156 * Technically the correct unit names for powers of 1024 are KiB, MiB etc. 157 * @link http://en.wikipedia.org/wiki/Byte 158 * 159 * @since 2.3.0 160 * 161 * @param int|string $bytes Number of bytes. Note max integer size for integers. 162 * @param int $decimals Precision of number of decimal places. 163 * @return unknown 164 */ 101 165 function size_format( $bytes, $decimals = null ) { 102 // technically the correct unit names for powers of 1024 are KiB, MiB etc103 // see http://en.wikipedia.org/wiki/Byte104 166 $quant = array( 105 167 // ========================= Origin ==== … … 145 207 } 146 208 147 209 /** 210 * Unserialize value only if it was serialized. 211 * 212 * @since 2.0.0 213 * 214 * @param string $original Maybe unserialized original, if is needed. 215 * @return mixed Unserialized data can be any type. 216 */ 148 217 function maybe_unserialize( $original ) { 149 218 if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in … … 153 222 } 154 223 155 224 /** 225 * Check value to find if it was serialized. 226 * 227 * If $data is not an string, then returned value will always be false. 228 * Serialized data is always a string. 229 * 230 * @since 2.0.5 231 * 232 * @param mixed $data Value to check to see if was serialized. 233 * @return bool False if not serialized and true if it was. 234 */ 156 235 function is_serialized( $data ) { 157 236 // if it isn't a string, it isn't serialized … … 180 259 } 181 260 182 261 /** 262 * Check whether serialized data is of string type. 263 * 264 * @since 2.0.5 265 * 266 * @param mixed $data Serialized data 267 * @return bool False if not a serialized string, true if it is. 268 */ 183 269 function is_serialized_string( $data ) { 184 270 // if it isn't a string, it isn't a serialized string … … 191 277 } 192 278 193 194 279 /* Options functions */ 195 280 196 // expects $setting to already be SQL-escaped 281 /** 282 * Retrieve option value based on setting name. 283 * 284 * {@internal Missing Long Description}} 285 * 286 * @since 1.5.0 287 * @package WordPress 288 * @subpackage Option 289 * 290 * @param string $setting Name of option to retrieve. Should already be SQL-escaped 291 * @return mixed Value set for the option. 292 */ 197 293 function get_option( $setting ) { 198 294 global $wpdb; … … 244 340 } 245 341 246 342 /** 343 * Protect WordPress special option from being modified. 344 * 345 * Will die if $option is in protected list. 346 * 347 * @since 2.2.0 348 * @package WordPress 349 * @subpackage Option 350 * 351 * @param string $option Option name. 352 */ 247 353 function wp_protect_special_option( $option ) { 248 354 $protected = array( 'alloptions', 'notoptions' ); … … 251 357 } 252 358 359 /** 360 * Print option value after sanitizing for forms. 361 * 362 * @uses attribute_escape Sanitizes value. 363 * @since 1.5.0 364 * @package WordPress 365 * @subpackage Option 366 * 367 * @param string $option Option name. 368 */ 253 369 function form_option( $option ) { 254 370 echo attribute_escape (get_option( $option ) ); … … 537 653 } 538 654 539 // perform a HTTP HEAD or GET request 540 // if $file_path is a writable filename, this will do a GET request and write the file to that path 541 // returns a list of HTTP headers 655 /** 656 * Perform a HTTP HEAD or GET request. 657 * 658 * If $file_path is a writable filename, this will do a GET request and write 659 * the file to that path. 660 * 661 * @since unknown 662 * 663 * @param string $url 664 * @param string|bool $file_path Optional. File path to write request to. 665 * @param int $red Optional. Number of Redirects. Stops at 5 redirects. 666 * @return bool|string False on failure and string of headers if HEAD request. 667 */ 542 668 function wp_get_http( $url, $file_path = false, $red = 1 ) { 543 669 global $wp_version; … … 611 737 } 612 738 739 /** 740 * Retrieve HTTP Headers from URL. 741 * 742 * @since 1.5.1 743 * 744 * @param string $url 745 * @param int $red Optional. Number of redirects. 746 * @return bool|string False on failure, headers on success. 747 */ 613 748 function wp_get_http_headers( $url, $red = 1 ) { 614 749 return wp_get_http( $url, false, $red ); 615 750 } 616 751 617 752 /** 753 * Whether today is a new day. 754 * 755 * {@internal Need to find out how this function is used.}} 756 * 757 * @since 0.71 758 * @uses $day Today 759 * @uses $previousday Previous day 760 * 761 * @return int 1 when new day, 0 if not a new day. 762 */ 618 763 function is_new_day() { 619 764 global $day, $previousday; … … 629 774 } 630 775 631 632 /* 633 add_query_arg: Returns a modified querystring by adding 634 a single key & value or an associative array. 635 Setting a key value to emptystring removes the key. 636 Omitting oldquery_or_uri uses the $_SERVER value. 637 638 Parameters: 639 add_query_arg(newkey, newvalue, oldquery_or_uri) or 640 add_query_arg(associative_array, oldquery_or_uri) 641 */ 776 /** 777 * Retrieve a modified query string. 778 * 779 * {@internal Missing Long Description}} 780 * 781 * Adding a single key & value or an associative array. 782 * Setting a key value to emptystring removes the key. 783 * Omitting oldquery_or_uri uses the $_SERVER value. 784 * 785 * @since 1.5.0 786 * 787 * @param mixed $param1 Either newkey or an associative_array 788 * @param mixed $param2 Either newvalue or oldquery or uri 789 * @param mixed $param3 Optional. Old query or uri 790 * @return unknown 791 */ 642 792 function add_query_arg() { 643 793 $ret = ''; … … 705 855 } 706 856 707 708 /* 709 remove_query_arg: Returns a modified querystring by removing 710 a single key or an array of keys. 711 Omitting oldquery_or_uri uses the $_SERVER value. 712 713 Parameters: 714 remove_query_arg(removekey, [oldquery_or_uri]) or 715 remove_query_arg(removekeyarray, [oldquery_or_uri]) 716 */ 717 718 function remove_query_arg( $key, $query=FALSE ) { 857 /** 858 * Removes an item or list from the query string. 859 * 860 * @since 1.5.0 861 * 862 * @param string|array $key Query key or keys to remove. 863 * @param bool $query When false uses the $_SERVER value. 864 * @return unknown 865 */ 866 function remove_query_arg( $key, $query=false ) { 719 867 if ( is_array( $key ) ) { // removing multiple keys 720 868 foreach ( (array) $key as $k ) 721 $query = add_query_arg( $k, FALSE, $query );869 $query = add_query_arg( $k, false, $query ); 722 870 return $query; 723 871 } 724 return add_query_arg( $key, FALSE, $query ); 725 } 726 727 872 return add_query_arg( $key, false, $query ); 873 } 874 875 /** 876 * Walks the array while sanitizing the contents. 877 * 878 * @uses $wpdb Used to sanitize values 879 * 880 * @param array $array Array to used to walk while sanitizing contents. 881 * @return array Sanitized $array. 882 */ 728 883 function add_magic_quotes( $array ) { 729 884 global $wpdb; … … 783 938 } 784 939 785 940 /** 941 * Retrieve the description for the HTTP status. 942 * 943 * @since 2.3.0 944 * 945 * @param int $code HTTP status code. 946 * @return string Empty string if not found, or description if found. 947 */ 786 948 function get_status_header_desc( $code ) { 787 949 global $wp_header_to_desc; … … 863 1025 } 864 1026 865 1027 /** 1028 * Sets the headers to prevent caching for the different browsers. 1029 * 1030 * Different browsers support different nocache headers, so several headers must 1031 * be sent so that all of them get the point that no caching should occur. 1032 * 1033 * @since 2.0.0 1034 */ 866 1035 function nocache_headers() { 867 1036 // why are these @-silenced when other header calls aren't? … … 872 1041 } 873 1042 874 1043 /** 1044 * Set the headers for caching for 10 days with JavaScript content type. 1045 * 1046 * @since 2.1.0 1047 */ 875 1048 function cache_javascript_headers() { 876 1049 $expiresOffset = 864000; // 10 days … … 880 1053 } 881 1054 882 1055 /** 1056 * Retrieve the number of database queries during the WordPress execution. 1057 * 1058 * @since 2.0.0 1059 * 1060 * @return int Number of database queries 1061 */ 883 1062 function get_num_queries() { 884 1063 global $wpdb; … … 886 1065 } 887 1066 888 1067 /** 1068 * Whether input is yes or no. Must be 'y' to be true. 1069 * 1070 * @since 1.0.0 1071 * 1072 * @param string $yn Character string containing either 'y' or 'n' 1073 * @return bool True if yes, false on anything else 1074 */ 889 1075 function bool_from_yn( $yn ) { 890 1076 return ( strtolower( $yn ) == 'y' ); … … 912 1098 } 913 1099 914 1100 /** 1101 * Load the RDF RSS 0.91 Feed template. 1102 * 1103 * @since 2.1.0 1104 */ 915 1105 function do_feed_rdf() { 916 1106 load_template( ABSPATH . WPINC . '/feed-rdf.php' ); 917 1107 } 918 1108 919 1109 /** 1110 * Load the RSS 1.0 Feed Template 1111 * 1112 * @since 2.1.0 1113 */ 920 1114 function do_feed_rss() { 921 1115 load_template( ABSPATH . WPINC . '/feed-rss.php' ); 922 1116 } 923 1117 924 1118 /** 1119 * Load either the RSS2 comment feed or the RSS2 posts feed. 1120 * 1121 * @since 2.1.0 1122 * 1123 * @param bool $for_comments True for the comment feed, false for normal feed. 1124 */ 925 1125 function do_feed_rss2( $for_comments ) { 926 1126 if ( $for_comments ) … … 930 1130 } 931 1131 932 1132 /** 1133 * Load either Atom comment feed or Atom posts feed. 1134 * 1135 * @since 2.1.0 1136 * 1137 * @param bool $for_comments True for the comment feed, false for normal feed. 1138 */ 933 1139 function do_feed_atom( $for_comments ) { 934 1140 if ($for_comments) … … 938 1144 } 939 1145 1146 /** 1147 * Display the robot.txt file content. 1148 * 1149 * The echo content should be with usage of the permalinks or for creating the 1150 * robot.txt file. 1151 * 1152 * @since 2.1.0 1153 * @uses do_action() Calls 'do_robotstxt' hook for displaying robot.txt rules. 1154 */ 940 1155 function do_robots() { 941 1156 header( 'Content-Type: text/plain; charset=utf-8' ); … … 1512 1727 } 1513 1728 1514 1729 /** 1730 * Merge user defined arguments into defaults array. 1731 * 1732 * This function is used throughout WordPress to allow for both string or array 1733 * to be merged into another array. 1734 * 1735 * @since 2.2.0 1736 * 1737 * @param string|array $args Value to merge with $defaults 1738 * @param array $defaults Array that serves as the defaults. 1739 * @return array Merged user defined values with defaults. 1740 */ 1515 1741 function wp_parse_args( $args, $defaults = '' ) { 1516 1742 if ( is_object( $args ) ) … … 1526 1752 } 1527 1753 1528 1754 /** 1755 * Determines if Widgets library should be loaded. 1756 * 1757 * Checks to make sure that the widgets library hasn't already been loaded. If 1758 * it hasn't, then it will load the widgets library and run an action hook. 1759 * 1760 * @since 2.2.0 1761 * @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value. 1762 */ 1529 1763 function wp_maybe_load_widgets() { 1530 1764 if ( !function_exists( 'dynamic_sidebar' ) ) { … … 1534 1768 } 1535 1769 1536 1770 /** 1771 * Append the Widgets menu to the themes main menu. 1772 * 1773 * @since 2.2.0 1774 * @uses $submenu The administration submenu list. 1775 */ 1537 1776 function wp_widgets_add_menu() { 1538 1777 global $submenu; … … 1541 1780 } 1542 1781 1543 1544 // For PHP 5.2, make sure all output buffers are flushed 1545 // before our singletons our destroyed. 1782 /** 1783 * Flush all output buffers for PHP 5.2. 1784 * 1785 * Make sure all output buffers are flushed before our singletons our destroyed. 1786 * 1787 * @since 2.2.0 1788 / 1546 1789 function wp_ob_end_flush_all() { 1547 1790 while ( @ob_end_flush() ); … … 1549 1792 1550 1793 1551 /* 1552 * require_wp_db() - require_once the correct database class file. 1553 * 1554 * This function is used to load the database class file either at runtime or by wp-admin/setup-config.php 1555 * We must globalise $wpdb to ensure that it is defined globally by the inline code in wp-db.php 1556 * 1557 * @global $wpdb 1794 /** 1795 * Load the correct database class file. 1796 * 1797 * This function is used to load the database class file either at runtime or by 1798 * wp-admin/setup-config.php We must globalise $wpdb to ensure that it is 1799 * defined globally by the inline code in wp-db.php. 1800 * 1801 * @since 2.5 1802 * @global $wpdb WordPress Database Object 1558 1803 */ 1559 1804 function require_wp_db() { … … 1565 1810 } 1566 1811 1812 1813 /** 1814 * Load custom DB error or display WordPress DB error. 1815 * 1816 * If a file exists in the wp-content directory named db-error.php, then it will 1817 * be loaded instead of displaying the WordPress DB error. If it is not found, 1818 * then the WordPress DB error will be displayed instead. 1819 * 1820 * The WordPress DB error sets the HTTP status header to 500 to try to prevent 1821 * search engines from caching the message. Custom DB messages should do the 1822 * same. 1823 * 1824 * @since 2.5 1825 * @uses $wpdb 1826 */ 1567 1827 function dead_db() { 1568 1828 global $wpdb; … … 1598 1858 } 1599 1859 1600 /** 1601 * Converts input to an absolute integer 1860 1861 /** 1862 * Converts value to positive integer. 1863 * 1864 * @since 2.5 1865 * 1602 1866 * @param mixed $maybeint data you wish to have convered to an absolute integer 1603 1867 * @return int an absolute integer … … 1607 1871 } 1608 1872 1609 /** 1610 * Determines if the blog can be accessed over SSL 1611 * @return bool whether of not SSL access is available 1873 1874 /** 1875 * Determines if the blog can be accessed over SSL. 1876 * 1877 * Determines if blog can be accessed over SSL by using cURL to access the site 1878 * using the https in the siteurl. Requires cURL extension to work correctly. 1879 * 1880 * @since 2.5 1881 * 1882 * @return bool Whether or not SSL access is available 1612 1883 */ 1613 1884 function url_is_accessable_via_ssl($url) … … 1634 1905 } 1635 1906 1907 1908 /** 1909 * Secure URL, if available or the given URL. 1910 * 1911 * @since 2.5 1912 * 1913 * @param string $url Complete URL path with transport. 1914 * @return string Secure or regular URL path. 1915 */ 1636 1916 function atom_service_url_filter($url) 1637 1917 { 1638 1918 if ( url_is_accessable_via_ssl($url) ) 1639 return 1919 return preg_replace( '/^http:\/\//', 'https://', $url ); 1640 1920 else 1641 1921 return $url; 1642 1922 } 1643 1923 1644 /** 1645 * _deprecated_function() - Marks a function as deprecated and informs when it has been used. 1646 * 1647 * There is a hook deprecated_function_run that will be called that can be used to get the backtrace 1648 * up to what file and function called the deprecated function. 1649 * 1650 * The current behavior is to trigger an user error if WP_DEBUG is defined and is true. 1924 1925 /** 1926 * Marks a function as deprecated and informs when it has been used. 1927 * 1928 * There is a hook deprecated_function_run that will be called that can be used 1929 * to get the backtrace up to what file and function called the deprecated 1930 * function. 1931 * 1932 * The current behavior is to trigger an user error if WP_DEBUG is defined and 1933 * is true. 1651 1934 * 1652 1935 * This function is to be used in every function in depreceated.php … … 1677 1960 } 1678 1961 1679 /** 1680 * _deprecated_file() - Marks a file as deprecated and informs when it has been used. 1681 * 1682 * There is a hook deprecated_file_included that will be called that can be used to get the backtrace 1683 * up to what file and function included the deprecated file. 1684 * 1685 * The current behavior is to trigger an user error if WP_DEBUG is defined and is true. 1962 1963 /** 1964 * Marks a file as deprecated and informs when it has been used. 1965 * 1966 * There is a hook deprecated_file_included that will be called that can be used 1967 * to get the backtrace up to what file and function included the deprecated 1968 * file. 1969 * 1970 * The current behavior is to trigger an user error if WP_DEBUG is defined and 1971 * is true. 1686 1972 * 1687 1973 * This function is to be used in every file that is depreceated … … 1712 1998 } 1713 1999 1714 /** 1715 * is_lighttpd_before_150() - Is the server running earlier than 1.5.0 version of lighttpd 2000 2001 /** 2002 * Is the server running earlier than 1.5.0 version of lighttpd 2003 * 2004 * @since unknown 1716 2005 * 1717 2006 * @return bool Whether the server is running lighttpd < 1.5.0 … … 1723 2012 } 1724 2013 1725 /** 1726 * apache_mod_loaded() - Does the specified module exist in the apache config? 2014 2015 /** 2016 * Does the specified module exist in the apache config? 2017 * 2018 * @since unknown 1727 2019 * 1728 2020 * @param string $mod e.g. mod_rewrite … … 1750 2042 } 1751 2043 2044 2045 /** 2046 * File validates against allowed set of defined rules. 2047 * 2048 * A return value of '1' means that the $file contains either '..' or './'. A 2049 * return value of '2' means that the $file contains ':' after the first 2050 * character. A return value of '3' means that the file is not in the allowed 2051 * files list. 2052 * 2053 * @since 2.6 2054 * 2055 * @param string $file File path. 2056 * @param array $allowed_files List of allowed files. 2057 * @return int 0 means nothing is wrong, greater than 0 means something was wrong. 2058 */ 1752 2059 function validate_file( $file, $allowed_files = '' ) { 1753 2060 if ( false !== strpos( $file, '..' )) … … 1766 2073 } 1767 2074 2075 2076 /** 2077 * Determine if SSL is used. 2078 * 2079 * @since 2.6 2080 * 2081 * @return bool True if SSL, false if not used. 2082 */ 1768 2083 function is_ssl() { 1769 2084 return ( 'on' == strtolower($_SERVER['HTTPS']) ) ? true : false; 1770 2085 } 1771 2086 2087 2088 /** 2089 * Whether SSL login should be forced. 2090 * 2091 * @since 2.6 2092 * 2093 * @param string|bool $force Optional. 2094 * @return bool True if forced, false if not forced. 2095 */ 1772 2096 function force_ssl_login($force = '') { 1773 2097 static $forced; … … 1782 2106 } 1783 2107 2108 2109 /** 2110 * Whether to force SSL used for the Administration Panels. 2111 * 2112 * @since 2.6 2113 * 2114 * @param string|bool $force 2115 * @return bool True if forced, false if not forced. 2116 */ 1784 2117 function force_ssl_admin($force = '') { 1785 2118 static $forced;
Note: See TracChangeset
for help on using the changeset viewer.