Make WordPress Core

Ticket #5639: functions.phpdoc.r8259.diff

File functions.phpdoc.r8259.diff, 20.0 KB (added by jacobsantos, 16 years ago)

PHPdoc inline documentation for functions.php based off of r8259

  • functions.php

     
    118118        // Sanity check for PHP 5.1.0-
    119119        if ( -1 == $i )
    120120                $i = false;
    121        
     121
    122122        if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
    123123                $datemonth = $wp_locale->get_month( date( 'm', $i ) );
    124124                $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
     
    195195        return false;
    196196}
    197197
    198 
     198/**
     199 * Get the week start and end from the datetime or date string from mysql.
     200 *
     201 * @since 0.71
     202 *
     203 * @param string $mysqlstring Date or datetime field type from mysql.
     204 * @param int $start_of_week Optional. Start of the week as an integer.
     205 * @return array Keys are 'start' and 'end'.
     206 */
    199207function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
    200         $my = substr( $mysqlstring, 0, 4 );
    201         $mm = substr( $mysqlstring, 8, 2 );
    202         $md = substr( $mysqlstring, 5, 2 );
    203         $day = mktime( 0, 0, 0, $md, $mm, $my );
    204         $weekday = date( 'w', $day );
    205         $i = 86400;
     208        $my = substr( $mysqlstring, 0, 4 ); // Mysql string Year
     209        $mm = substr( $mysqlstring, 8, 2 ); // Mysql string Month
     210        $md = substr( $mysqlstring, 5, 2 ); // Mysql string day
     211        $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day.
     212        $weekday = date( 'w', $day ); // The day of the week from the timestamp
     213        $i = 86400; // One day
    206214        if( !is_numeric($start_of_week) )
    207215                $start_of_week = get_option( 'start_of_week' );
    208216
     
    415423 * @return array List of all options.
    416424 */
    417425function get_alloptions() {
    418         global $wpdb, $wp_queries;
     426        global $wpdb;
    419427        $show = $wpdb->hide_errors();
    420428        if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
    421429                $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
     
    639647        return $data;
    640648}
    641649
    642 
     650/**
     651 * Strip HTML and put links at the bottom of stripped content.
     652 *
     653 * Searches for all of the links, strips them out of the content, and places
     654 * them at the bottom of the content with numbers.
     655 *
     656 * @since unknown
     657 *
     658 * @param string $content Content to get links
     659 * @return string HTML stripped out of content with links at the bottom.
     660 */
    643661function make_url_footnote( $content ) {
    644662        preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
    645663        $j = 0;
     
    659677        return $content;
    660678}
    661679
    662 
     680/**
     681 * Retrieve post title from XMLRPC XML.
     682 *
     683 * If the title element is not part of the XML, then the default post title from
     684 * the $post_default_title will be used instead.
     685 *
     686 * @package WordPress
     687 * @subpackage XMLRPC
     688 * @since unknown
     689 *
     690 * @global string $post_default_title Default XMLRPC post title.
     691 *
     692 * @param string $content XMLRPC XML Request content
     693 * @return string Post title
     694 */
    663695function xmlrpc_getposttitle( $content ) {
    664696        global $post_default_title;
    665697        if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
     
    672704        return $post_title;
    673705}
    674706
    675 
     707/**
     708 * Retrieve the post category or categories from XMLRPC XML.
     709 *
     710 * If the category element is not found, then the default post category will be
     711 * used. The return type then would be what $post_default_category. If the
     712 * category is found, then it will always be an array.
     713 *
     714 * @package WordPress
     715 * @subpackage XMLRPC
     716 * @since unknown
     717 *
     718 * @global string $post_default_category Default XMLRPC post category.
     719 *
     720 * @param string $content XMLRPC XML Request content
     721 * @return string|array List of categories or category name.
     722 */
    676723function xmlrpc_getpostcategory( $content ) {
    677724        global $post_default_category;
    678725        if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
     
    684731        return $post_category;
    685732}
    686733
    687 
     734/**
     735 * XMLRPC XML content without title and category elements.
     736 *
     737 * @package WordPress
     738 * @subpackage XMLRPC
     739 * @since unknown
     740 *
     741 * @param string $content XMLRPC XML Request content
     742 * @return string XMLRPC XML Request content without title and category elements.
     743 */
    688744function xmlrpc_removepostdata( $content ) {
    689745        $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
    690746        $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
     
    903959/**
    904960 * Whether today is a new day.
    905961 *
    906  * {@internal Need to find out how this function is used.}}
    907  *
    908962 * @since 0.71
    909963 * @uses $day Today
    910964 * @uses $previousday Previous day
     
    935989 * @return string URL encoded string
    936990 */
    937991function build_query( $data ) {
    938         return _http_build_query( $data, NULL, '&', '', false );
     992        return _http_build_query( $data, null, '&', '', false );
    939993}
    940994
    941995/**
     
    9531007 * @param mixed $param1 Either newkey or an associative_array
    9541008 * @param mixed $param2 Either newvalue or oldquery or uri
    9551009 * @param mixed $param3 Optional. Old query or uri
    956  * @return unknown
     1010 * @return string New URL query string.
    9571011 */
    9581012function add_query_arg() {
    9591013        $ret = '';
     
    10271081 *
    10281082 * @param string|array $key Query key or keys to remove.
    10291083 * @param bool $query When false uses the $_SERVER value.
    1030  * @return unknown
     1084 * @return string New URL query string.
    10311085 */
    10321086function remove_query_arg( $key, $query=false ) {
    10331087        if ( is_array( $key ) ) { // removing multiple keys
     
    11051159        }
    11061160}
    11071161
    1108 
     1162/**
     1163 * Setup the WordPress query.
     1164 *
     1165 * @since 2.0.0
     1166 *
     1167 * @param string $query_vars Default WP_Query arguments.
     1168 */
    11091169function wp( $query_vars = '' ) {
    11101170        global $wp, $wp_query, $wp_the_query;
    11111171        $wp->main( $query_vars );
     
    12631323        return ( strtolower( $yn ) == 'y' );
    12641324}
    12651325
    1266 
     1326/**
     1327 * Loads the feed template from the use of an action hook.
     1328 *
     1329 * If the feed action does not have a hook, then the function will die with a
     1330 * message telling the visitor that the feed is not valid.
     1331 *
     1332 * It is better to only have one hook for each feed.
     1333 *
     1334 * @since 2.1.0
     1335 * @uses $wp_query Used to tell if the use a comment feed.
     1336 * @uses do_action() Calls 'do_feed_$feed' hook, if a hook exists for the feed.
     1337 */
    12671338function do_feed() {
    12681339        global $wp_query;
    12691340
     
    13531424        }
    13541425}
    13551426
    1356 
     1427/**
     1428 * Test whether blog is already installed.
     1429 *
     1430 * The cache will be checked first. If you have a cache plugin, which saves the
     1431 * cache values, then this will work. If you use the default WordPress cache,
     1432 * and the database goes away, then you might have problems.
     1433 *
     1434 * Checks for the option siteurl for whether WordPress is installed.
     1435 *
     1436 * @since 2.1.0
     1437 * @uses $wpdb
     1438 *
     1439 * @return bool Whether blog is already installed.
     1440 */
    13571441function is_blog_installed() {
    13581442        global $wpdb;
    13591443
    1360         // Check cache first.  If options table goes away and we have true cached, oh well.
     1444        // Check cache first. If options table goes away and we have true cached, oh well.
    13611445        if ( wp_cache_get('is_blog_installed') )
    13621446                return true;
    13631447
     
    13711455        return $installed;
    13721456}
    13731457
    1374 
     1458/**
     1459 * Retrieve URL with nonce added to URL query.
     1460 *
     1461 * @since 2.0.4
     1462 *
     1463 * @param string $actionurl URL to add nonce action
     1464 * @param string $action Optional. Nonce action name
     1465 * @return string URL with nonce action added.
     1466 */
    13751467function wp_nonce_url( $actionurl, $action = -1 ) {
    13761468        $actionurl = str_replace( '&amp;', '&', $actionurl );
    13771469        return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) );
    13781470}
    13791471
    1380 
    13811472function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {
    13821473        $name = attribute_escape( $name );
    13831474        $nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
     
    13901481        return $nonce_field;
    13911482}
    13921483
    1393 
    13941484function wp_referer_field( $echo = true) {
    13951485        $ref = attribute_escape( $_SERVER['REQUEST_URI'] );
    13961486        $referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
     
    14091499        return $orig_referer_field;
    14101500}
    14111501
    1412 
    14131502function wp_get_referer() {
    14141503        if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
    14151504                $ref = $_REQUEST['_wp_http_referer'];
     
    14281517        return false;
    14291518}
    14301519
    1431 
    14321520function wp_mkdir_p( $target ) {
    14331521        // from php.net/mkdir user contributed notes
    14341522        $target = str_replace( '//', '/', $target );
     
    14521540        return false;
    14531541}
    14541542
    1455 // Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows')
     1543/**
     1544 * Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows').
     1545 *
     1546 * @since unknown
     1547 *
     1548 * @param string $path File path
     1549 * @return bool True if path is absolute, false is not absolute.
     1550 */
    14561551function path_is_absolute( $path ) {
    14571552        // this is definitive if true but fails if $path does not exist or contains a symbolic link
    14581553        if ( realpath($path) == $path )
     
    14691564        return (bool) preg_match('#^[/\\\\]#', $path);
    14701565}
    14711566
    1472 // Join two filesystem paths together (e.g. 'give me $path relative to $base')
     1567/**
     1568 * Join two filesystem paths together (e.g. 'give me $path relative to $base').
     1569 *
     1570 * If the $path is absolute, then it the full path is returned.
     1571 *
     1572 * @since unknown
     1573 *
     1574 * @param string $base
     1575 * @param string $path
     1576 * @return string The path with the base or absolute path.
     1577 */
    14731578function path_join( $base, $path ) {
    14741579        if ( path_is_absolute($path) )
    14751580                return $path;
     
    14771582        return rtrim($base, '/') . '/' . ltrim($path, '/');
    14781583}
    14791584
    1480 // Returns an array containing the current upload directory's path and url, or an error message.
    1481 function wp_upload_dir( $time = NULL ) {
     1585/**
     1586 * Get an array containing the current upload directory's path and url, or an error message.
     1587 *
     1588 * {@internal Missing Long Description}}
     1589 *
     1590 * @since 2.0.0
     1591 *
     1592 * @param unknown_type $time
     1593 * @return unknown
     1594 */
     1595function wp_upload_dir( $time = null ) {
    14821596        $siteurl = get_option( 'siteurl' );
    14831597        $upload_path = get_option( 'upload_path' );
    14841598        if ( trim($upload_path) === '' )
     
    15191633        return apply_filters( 'upload_dir', $uploads );
    15201634}
    15211635
    1522 // return a filename that is sanitized and unique for the given directory
    1523 function wp_unique_filename( $dir, $filename, $unique_filename_callback = NULL ) {
     1636/**
     1637 * Get a filename that is sanitized and unique for the given directory.
     1638 *
     1639 * {@internal Missing Long Description}}
     1640 *
     1641 * @since 2.5
     1642 *
     1643 * @param string $dir
     1644 * @param string $filename
     1645 * @param string $unique_filename_callback Function name
     1646 * @return unknown
     1647 */
     1648function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
    15241649        $filename = strtolower( $filename );
    15251650        // separate the filename into a name and extension
    15261651        $info = pathinfo($filename);
    15271652        $ext = $info['extension'];
    15281653        $name = basename($filename, ".{$ext}");
    1529        
     1654
    15301655        // edge case: if file is named '.ext', treat as an empty name
    15311656        if( $name === ".$ext" )
    15321657                $name = '';
     
    15571682        return $filename;
    15581683}
    15591684
    1560 function wp_upload_bits( $name, $deprecated, $bits, $time = NULL ) {
     1685function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
    15611686        if ( empty( $name ) )
    15621687                return array( 'error' => __( "Empty filename" ) );
    15631688
     
    15961721        return array( 'file' => $new_file, 'url' => $url, 'error' => false );
    15971722}
    15981723
     1724/**
     1725 * Retrieve the file type based on the extension name.
     1726 *
     1727 * @package WordPress
     1728 * @since unknown
     1729 * @uses apply_filters() Calls 'ext2type' hook on default supported types.
     1730 *
     1731 * @param string $ext The extension to search.
     1732 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found.
     1733 */
    15991734function wp_ext2type( $ext ) {
    16001735        $ext2type = apply_filters('ext2type', array(
    16011736                'audio' => array('aac','ac3','aif','aiff','mp1','mp2','mp3','m3a','m4a','m4b','ogg','ram','wav','wma'),
     
    16121747                        return $type;
    16131748}
    16141749
     1750/**
     1751 * Retrieve the file type from the file name.
     1752 *
     1753 * You can optionally define the mime array, if needed.
     1754 *
     1755 * @since 2.0.4
     1756 *
     1757 * @param string $filename File name or path.
     1758 * @param array $mimes Optional. Key is the file extension with value as the mime type.
     1759 * @return array Values with extension first and mime type.
     1760 */
    16151761function wp_check_filetype( $filename, $mimes = null ) {
    16161762        // Accepted MIME types are set here as PCRE unless provided.
    16171763        $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
     
    16761822        return compact( 'ext', 'type' );
    16771823}
    16781824
     1825/**
     1826 * Retrieve nonce action "Are you sure" message.
     1827 *
     1828 * The action is split by verb and noun. The action format is as follows:
     1829 * verb-action_extra. The verb is before the first dash and has the format of
     1830 * letters and no spaces and numbers. The noun is after the dash and before the
     1831 * underscore, if an underscore exists. The noun is also only letters.
     1832 *
     1833 * The filter will be called for any action, which is not defined by WordPress.
     1834 * You may use the filter for your plugin to explain nonce actions to the user,
     1835 * when they get the "Are you sure?" message. The filter is in the format of
     1836 * 'explain_nonce_$verb-$noun' with the $verb replaced by the found verb and the
     1837 * $noun replaced by the found noun. The two parameters that are given to the
     1838 * hook are the localized "Are you sure you want to do this?" message with the
     1839 * extra text (the text after the underscore).
     1840 *
     1841 * @since 2.0.4
     1842 *
     1843 * @param string $action Nonce action.
     1844 * @return string Are you sure message.
     1845 */
    16791846function wp_explain_nonce( $action ) {
    16801847        if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) {
    16811848                $verb = $matches[1];
     
    17411908        return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
    17421909}
    17431910
    1744 
     1911/**
     1912 * Display "Are You Sure" message to confirm the action being taken.
     1913 *
     1914 * If the action has the nonce explain message, then it will be displayed along
     1915 * with the "Are you sure?" message.
     1916 *
     1917 * @since 2.0.4
     1918 *
     1919 * @param string $action The nonce action.
     1920 */
    17451921function wp_nonce_ays( $action ) {
    17461922        $title = __( 'WordPress Failure Notice' );
    17471923        $html = wp_specialchars( wp_explain_nonce( $action ) ) . '</p>';
     
    17501926        wp_die( $html, $title);
    17511927}
    17521928
    1753 
     1929/**
     1930 * Kill WordPress execution and display HTML message with error message.
     1931 *
     1932 * Call this function complements the die() PHP function. The difference is that
     1933 * HTML will be displayed to the user. It is recommended to use this function
     1934 * only, when the execution should not continue any further. It is not
     1935 * recommended to call this function very often and try to handle as many errors
     1936 * as possible siliently.
     1937 *
     1938 * @since 2.0.4
     1939 *
     1940 * @param string $message Error message.
     1941 * @param string $title Error title.
     1942 */
    17541943function wp_die( $message, $title = '' ) {
    17551944        global $wp_locale;
    17561945
     
    18202009        die();
    18212010}
    18222011
    1823 
     2012/**
     2013 * Retrieve the WordPress home page URL.
     2014 *
     2015 * If the constant named 'WP_HOME' exists, then it willl be used and returned by
     2016 * the function. This can be used to counter the redirection on your local
     2017 * development environment.
     2018 *
     2019 * @access private
     2020 * @package WordPress
     2021 * @since 2.2.0
     2022 *
     2023 * @param string $url URL for the home location
     2024 * @return string Homepage location.
     2025 */
    18242026function _config_wp_home( $url = '' ) {
    18252027        if ( defined( 'WP_HOME' ) )
    18262028                return WP_HOME;
    18272029        return $url;
    18282030}
    18292031
    1830 
     2032/**
     2033 * Retrieve the WordPress site URL.
     2034 *
     2035 * If the constant named 'WP_SITEURL' is defined, then the value in that
     2036 * constant will always be returned. This can be used for debugging a site on
     2037 * your localhost while not having to change the database to your URL.
     2038 *
     2039 * @access private
     2040 * @package WordPress
     2041 * @since 2.2.0
     2042 *
     2043 * @param string $url URL to set the WordPress site location.
     2044 * @return string The WordPress Site URL
     2045 */
    18312046function _config_wp_siteurl( $url = '' ) {
    18322047        if ( defined( 'WP_SITEURL' ) )
    18332048                return WP_SITEURL;
    18342049        return $url;
    18352050}
    18362051
    1837 
     2052/**
     2053 * Set the localized direction for MCE plugin.
     2054 *
     2055 * Will only set the direction to 'rtl', if the WordPress locale has the text
     2056 * direction set to 'rtl'.
     2057 *
     2058 * Fills in the 'directionality', 'plugins', and 'theme_advanced_button1' array
     2059 * keys. These keys are then returned in the $input array.
     2060 *
     2061 * @access private
     2062 * @package WordPress
     2063 * @subpackage MCE
     2064 * @since 2.1.0
     2065 *
     2066 * @param array $input MCE plugin array.
     2067 * @return array Direction set for 'rtl', if needed by locale.
     2068 */
    18382069function _mce_set_direction( $input ) {
    18392070        global $wp_locale;
    18402071
     
    18472078        return $input;
    18482079}
    18492080
    1850 
     2081/**
     2082 * Convert smiley code to the icon graphic file equivalent.
     2083 *
     2084 * You can turn off smilies, by going to the write setting screen and unchecking
     2085 * the box, or by setting 'use_smilies' option to false or removing the option.
     2086 *
     2087 * Plugins may override the default smiley list by setting the $wpsmiliestrans
     2088 * to an array, with the key the code the blogger types in and the value the
     2089 * image file.
     2090 *
     2091 * The $wp_smiliessearch global is for the regular expression array and is
     2092 * set each time the function is called. The $wp_smiliesreplace is the full
     2093 * replacement. Supposely, the $wp_smiliessearch array is looped over using
     2094 * preg_replace() or just setting the array of $wp_smiliessearch along with the
     2095 * array of $wp_smiliesreplace in the search and replace parameters of
     2096 * preg_replace(), which would be faster and less overhead. Either way, both are
     2097 * used with preg_replace() and can be defined after the function is called.
     2098 *
     2099 * The full list of smilies can be found in the function and won't be listed in
     2100 * the description. Probably should create a Codex page for it, so that it is
     2101 * available.
     2102 *
     2103 * @global array $wpsmiliestrans
     2104 * @global array $wp_smiliesreplace
     2105 * @global array $wp_smiliessearch
     2106 * @since 2.2.0
     2107 */
    18512108function smilies_init() {
    18522109        global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;
    18532110
     
    20452302 * Converts value to positive integer.
    20462303 *
    20472304 * @since 2.5
    2048  * 
    2049  * @param mixed $maybeint data you wish to have convered to an absolute integer
    2050  * @return int an absolute integer
     2305 *
     2306 * @param mixed $maybeint Data you wish to have convered to an absolute integer
     2307 * @return int An absolute integer
    20512308 */
    20522309function absint( $maybeint ) {
    20532310        return abs( intval( $maybeint ) );
     
    20662323function url_is_accessable_via_ssl($url)
    20672324{
    20682325        if (in_array('curl', get_loaded_extensions())) {
    2069                  $ssl = preg_replace( '/^http:\/\//', 'https://',  $url );
     2326                $ssl = preg_replace( '/^http:\/\//', 'https://',  $url );
    20702327
    2071                  $ch = curl_init();
    2072                  curl_setopt($ch, CURLOPT_URL, $ssl);
    2073                  curl_setopt($ch, CURLOPT_FAILONERROR, true);
    2074                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    2075                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     2328                $ch = curl_init();
     2329                curl_setopt($ch, CURLOPT_URL, $ssl);
     2330                curl_setopt($ch, CURLOPT_FAILONERROR, true);
     2331                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     2332                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    20762333
    2077                  curl_exec($ch);
     2334                curl_exec($ch);
    20782335
    2079                  $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    2080                  curl_close ($ch);
     2336                $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     2337                curl_close ($ch);
    20812338
    2082                  if ($status == 200 || $status == 401) {
    2083                          return true;
    2084                  }
     2339                if ($status == 200 || $status == 401) {
     2340                        return true;
     2341                }
    20852342        }
    20862343        return false;
    20872344}
     
    21232380 * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
    21242381 *
    21252382 * @param string $function The function that was called
    2126  * @param string $version The version of WordPress that depreceated the function
     2383 * @param string $version The version of WordPress that deprecated the function
    21272384 * @param string $replacement Optional. The function that should have been called
    21282385 */
    21292386function _deprecated_function($function, $version, $replacement=null) {
     
    21602417 * @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
    21612418 *
    21622419 * @param string $file The file that was included
    2163  * @param string $version The version of WordPress that depreceated the function
     2420 * @param string $version The version of WordPress that deprecated the function
    21642421 * @param string $replacement Optional. The function that should have been called
    21652422 */
    21662423function _deprecated_file($file, $version, $replacement=null) {