Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r47098 r47122  
    324324    global $wp_locale;
    325325
    326     // i18n functions are not available in SHORTINIT mode
     326    // i18n functions are not available in SHORTINIT mode.
    327327    if ( ! function_exists( '_x' ) ) {
    328328        return $date;
     
    385385    }
    386386
    387     // Used for locale-specific rules
     387    // Used for locale-specific rules.
    388388    $locale = get_locale();
    389389
     
    591591 */
    592592function maybe_unserialize( $original ) {
    593     if ( is_serialized( $original ) ) { // don't attempt to unserialize data that wasn't serialized going in
     593    if ( is_serialized( $original ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
    594594        return @unserialize( $original );
    595595    }
     
    610610 */
    611611function is_serialized( $data, $strict = true ) {
    612     // if it isn't a string, it isn't serialized.
     612    // If it isn't a string, it isn't serialized.
    613613    if ( ! is_string( $data ) ) {
    614614        return false;
     
    654654                return false;
    655655            }
    656             // or else fall through
     656            // Or else fall through.
    657657        case 'a':
    658658        case 'O':
     
    709709    }
    710710
    711     // Double serialization is required for backward compatibility.
    712     // See https://core.trac.wordpress.org/ticket/12930
    713     // Also the world will end. See WP 3.6.1.
     711    /*
     712     * Double serialization is required for backward compatibility.
     713     * See https://core.trac.wordpress.org/ticket/12930
     714     * Also the world will end. See WP 3.6.1.
     715     */
    714716    if ( is_serialized( $data, false ) ) {
    715717        return serialize( $data );
     
    898900                $allowed_types = array( 'video', 'audio' );
    899901
    900                 // Check to see if we can figure out the mime type from
    901                 // the extension
     902                // Check to see if we can figure out the mime type from the extension.
    902903                $url_parts = @parse_url( $url );
    903904                if ( false !== $url_parts ) {
     
    11221123
    11231124    wp_parse_str( $query, $qs );
    1124     $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
     1125    $qs = urlencode_deep( $qs ); // This re-URL-encodes things that were already in the query string.
    11251126    if ( is_array( $args[0] ) ) {
    11261127        foreach ( $args[0] as $k => $v ) {
     
    11551156 */
    11561157function remove_query_arg( $key, $query = false ) {
    1157     if ( is_array( $key ) ) { // removing multiple keys
     1158    if ( is_array( $key ) ) { // Removing multiple keys.
    11581159        foreach ( $key as $k ) {
    11591160            $query = add_query_arg( $k, false, $query );
     
    14861487
    14871488    header( 'Content-Type: text/javascript; charset=' . get_bloginfo( 'charset' ) );
    1488     header( 'Vary: Accept-Encoding' ); // Handle proxies
     1489    header( 'Vary: Accept-Encoding' ); // Handle proxies.
    14891490    header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiresOffset ) . ' GMT' );
    14901491}
     
    17041705        $alloptions = wp_load_alloptions();
    17051706    }
    1706     // If siteurl is not set to autoload, check it specifically
     1707    // If siteurl is not set to autoload, check it specifically.
    17071708    if ( ! isset( $alloptions['siteurl'] ) ) {
    17081709        $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
     
    20792080function wp_normalize_path( $path ) {
    20802081    $wrapper = '';
     2082
    20812083    if ( wp_is_stream( $path ) ) {
    20822084        list( $wrapper, $path ) = explode( '://', $path, 2 );
    2083         $wrapper               .= '://';
    2084     }
    2085 
    2086     // Standardise all paths to use /
     2085
     2086        $wrapper .= '://';
     2087    }
     2088
     2089    // Standardise all paths to use '/'.
    20872090    $path = str_replace( '\\', '/', $path );
    20882091
     
    20902093    $path = preg_replace( '|(?<=.)/+|', '/', $path );
    20912094
    2092     // Windows paths should uppercase the drive letter
     2095    // Windows paths should uppercase the drive letter.
    20932096    if ( ':' === substr( $path, 1, 1 ) ) {
    20942097        $path = ucfirst( $path );
     
    21822185 */
    21832186function win_is_writable( $path ) {
    2184 
    2185     if ( $path[ strlen( $path ) - 1 ] == '/' ) { // if it looks like a directory, check a random file within the directory
     2187    if ( $path[ strlen( $path ) - 1 ] == '/' ) {
     2188        // If it looks like a directory, check a random file within the directory.
    21862189        return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' );
    2187     } elseif ( is_dir( $path ) ) { // If it's a directory (and not a file) check a random file within the directory
     2190    } elseif ( is_dir( $path ) ) {
     2191        // If it's a directory (and not a file), check a random file within the directory.
    21882192        return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
    21892193    }
    2190     // check tmp file for read/write capabilities
     2194
     2195    // Check tmp file for read/write capabilities.
    21912196    $should_delete_tmp_file = ! file_exists( $path );
    2192     $f                      = @fopen( $path, 'a' );
     2197
     2198    $f = @fopen( $path, 'a' );
    21932199    if ( $f === false ) {
    21942200        return false;
    21952201    }
    21962202    fclose( $f );
     2203
    21972204    if ( $should_delete_tmp_file ) {
    21982205        unlink( $path );
    21992206    }
     2207
    22002208    return true;
    22012209}
     
    23282336        $dir = WP_CONTENT_DIR . '/uploads';
    23292337    } elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
    2330         // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
     2338        // $dir is absolute, $upload_path is (maybe) relative to ABSPATH.
    23312339        $dir = path_join( ABSPATH, $upload_path );
    23322340    } else {
     
    23522360    }
    23532361
    2354     // If multisite (and if not the main site in a post-MU network)
     2362    // If multisite (and if not the main site in a post-MU network).
    23552363    if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
    23562364
     
    24032411    $subdir = '';
    24042412    if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
    2405         // Generate the yearly and monthly dirs
     2413        // Generate the yearly and monthly directories.
    24062414        if ( ! $time ) {
    24072415            $time = current_time( 'mysql' );
     
    25252533
    25262534                // Ensure this never goes into infinite loop
    2527                 // as it uses pathinfo() and regex in the check but string replacement for the changes.
     2535                // as it uses pathinfo() and regex in the check, but string replacement for the changes.
    25282536                $count = count( $files );
    25292537                $i     = 0;
     
    25662574    $ext   = pathinfo( $filename, PATHINFO_EXTENSION );
    25672575
    2568     // Edge case, file names like `.ext`
     2576    // Edge case, file names like `.ext`.
    25692577    if ( empty( $fname ) ) {
    25702578        return false;
     
    26822690    clearstatcache();
    26832691
    2684     // Set correct file permissions
     2692    // Set correct file permissions.
    26852693    $stat  = @ stat( dirname( $new_file ) );
    26862694    $perms = $stat['mode'] & 0007777;
     
    26892697    clearstatcache();
    26902698
    2691     // Compute the URL
     2699    // Compute the URL.
    26922700    $url = $upload['url'] . "/$filename";
    26932701
     
    27862794    $proper_filename = false;
    27872795
    2788     // Do basic extension validation and MIME mapping
     2796    // Do basic extension validation and MIME mapping.
    27892797    $wp_filetype = wp_check_filetype( $filename, $mimes );
    27902798    $ext         = $wp_filetype['ext'];
    27912799    $type        = $wp_filetype['type'];
    27922800
    2793     // We can't do any further validation without a file to work with
     2801    // We can't do any further validation without a file to work with.
    27942802    if ( ! file_exists( $file ) ) {
    27952803        return compact( 'ext', 'type', 'proper_filename' );
     
    28012809    if ( $type && 0 === strpos( $type, 'image/' ) ) {
    28022810
    2803         // Attempt to figure out what type of image it actually is
     2811        // Attempt to figure out what type of image it actually is.
    28042812        $real_mime = wp_get_image_mime( $file );
    28052813
     
    28232831            );
    28242832
    2825             // Replace whatever is after the last period in the filename with the correct extension
     2833            // Replace whatever is after the last period in the filename with the correct extension.
    28262834            if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
    28272835                $filename_parts = explode( '.', $filename );
     
    28312839
    28322840                if ( $new_filename != $filename ) {
    2833                     $proper_filename = $new_filename; // Mark that it changed
     2841                    $proper_filename = $new_filename; // Mark that it changed.
    28342842                }
    2835                 // Redefine the extension / MIME
     2843                // Redefine the extension / MIME.
    28362844                $wp_filetype = wp_check_filetype( $new_filename, $mimes );
    28372845                $ext         = $wp_filetype['ext'];
     
    28502858        finfo_close( $finfo );
    28512859
    2852         // fileinfo often misidentifies obscure files as one of these types
     2860        // fileinfo often misidentifies obscure files as one of these types.
    28532861        $nonspecific_types = array(
    28542862            'application/octet-stream',
     
    29212929    }
    29222930
    2923     // The mime type must be allowed
     2931    // The mime type must be allowed.
    29242932    if ( $type ) {
    29252933        $allowed = get_allowed_mime_types();
     
    30323040            'webm'                         => 'video/webm',
    30333041            'mkv'                          => 'video/x-matroska',
    3034             '3gp|3gpp'                     => 'video/3gpp', // Can also be audio
    3035             '3g2|3gp2'                     => 'video/3gpp2', // Can also be audio
     3042            '3gp|3gpp'                     => 'video/3gpp',  // Can also be audio.
     3043            '3g2|3gp2'                     => 'video/3gpp2', // Can also be audio.
    30363044            // Text formats.
    30373045            'txt|asc|c|cc|h|srt'           => 'text/plain',
     
    39833991 *
    39843992 * @ignore
    3985  * @since      4.4.0
     3993 * @since 4.4.0
    39863994 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3
    39873995 *                   has been dropped.
     
    42234231    global $wpsmiliestrans, $wp_smiliessearch;
    42244232
    4225     // don't bother setting up smilies if they are disabled
     4233    // Don't bother setting up smilies if they are disabled.
    42264234    if ( ! get_option( 'use_smilies' ) ) {
    42274235        return;
     
    43034311    $spaces = wp_spaces_regexp();
    43044312
    4305     // Begin first "subpattern"
     4313    // Begin first "subpattern".
    43064314    $wp_smiliessearch = '/(?<=' . $spaces . '|^)';
    43074315
     
    43114319        $rest      = substr( $smiley, 1 );
    43124320
    4313         // new subpattern?
     4321        // New subpattern?
    43144322        if ( $firstchar != $subchar ) {
    43154323            if ( $subchar != '' ) {
    4316                 $wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern"
    4317                 $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
     4324                $wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern".
     4325                $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern".
    43184326            }
    43194327            $subchar           = $firstchar;
     
    53495357        $script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
    53505358
    5351         // The request is for the admin
     5359        // The request is for the admin.
    53525360        if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
    53535361            $path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
    53545362
    5355             // The request is for a file in ABSPATH
     5363            // The request is for a file in ABSPATH.
    53565364        } elseif ( $script_filename_dir . '/' == $abspath_fix ) {
    5357             // Strip off any file/query params in the path
     5365            // Strip off any file/query params in the path.
    53585366            $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
    53595367
    53605368        } else {
    53615369            if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
    5362                 // Request is hitting a file inside ABSPATH
     5370                // Request is hitting a file inside ABSPATH.
    53635371                $directory = str_replace( ABSPATH, '', $script_filename_dir );
    5364                 // Strip off the sub directory, and any file/query params
     5372                // Strip off the subdirectory, and any file/query params.
    53655373                $path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] );
    53665374            } elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
    5367                 // Request is hitting a file above ABSPATH
     5375                // Request is hitting a file above ABSPATH.
    53685376                $subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
    5369                 // Strip off any file/query params from the path, appending the sub directory to the installation
     5377                // Strip off any file/query params from the path, appending the subdirectory to the installation.
    53705378                $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory;
    53715379            } else {
     
    53745382        }
    53755383
    5376         $schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
     5384        $schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet.
    53775385        $url    = $schema . $_SERVER['HTTP_HOST'] . $path;
    53785386    }
     
    56425650 */
    56435651function _wp_timezone_choice_usort_callback( $a, $b ) {
    5644     // Don't use translated versions of Etc
     5652    // Don't use translated versions of Etc.
    56455653    if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
    5646         // Make the order of these more like the old dropdown
     5654        // Make the order of these more like the old dropdown.
    56475655        if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
    56485656            return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
     
    56685676        return strnatcasecmp( $a['t_city'], $b['t_city'] );
    56695677    } else {
    5670         // Force Etc to the bottom of the list
     5678        // Force Etc to the bottom of the list.
    56715679        if ( 'Etc' === $a['continent'] ) {
    56725680            return 1;
     
    57135721        }
    57145722
    5715         // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
     5723        // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later.
    57165724        $exists    = array(
    57175725            0 => ( isset( $zone[0] ) && $zone[0] ),
     
    57435751
    57445752    foreach ( $zonen as $key => $zone ) {
    5745         // Build value in an array to join later
     5753        // Build value in an array to join later.
    57465754        $value = array( $zone['continent'] );
    57475755
    57485756        if ( empty( $zone['city'] ) ) {
    5749             // It's at the continent level (generally won't happen)
     5757            // It's at the continent level (generally won't happen).
    57505758            $display = $zone['t_continent'];
    57515759        } else {
    5752             // It's inside a continent group
    5753 
    5754             // Continent optgroup
     5760            // It's inside a continent group.
     5761
     5762            // Continent optgroup.
    57555763            if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) {
    57565764                $label       = $zone['t_continent'];
     
    57585766            }
    57595767
    5760             // Add the city to the value
     5768            // Add the city to the value.
    57615769            $value[] = $zone['city'];
    57625770
    57635771            $display = $zone['t_city'];
    57645772            if ( ! empty( $zone['subcity'] ) ) {
    5765                 // Add the subcity to the value
     5773                // Add the subcity to the value.
    57665774                $value[]  = $zone['subcity'];
    57675775                $display .= ' - ' . $zone['t_subcity'];
     
    57695777        }
    57705778
    5771         // Build the value
     5779        // Build the value.
    57725780        $value    = join( '/', $value );
    57735781        $selected = '';
     
    57775785        $structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . '</option>';
    57785786
    5779         // Close continent optgroup
     5787        // Close continent optgroup.
    57805788        if ( ! empty( $zone['city'] ) && ( ! isset( $zonen[ $key + 1 ] ) || ( isset( $zonen[ $key + 1 ] ) && $zonen[ $key + 1 ]['continent'] !== $zone['continent'] ) ) ) {
    57815789            $structure[] = '</optgroup>';
     
    57835791    }
    57845792
    5785     // Do UTC
     5793    // Do UTC.
    57865794    $structure[] = '<optgroup label="' . esc_attr__( 'UTC' ) . '">';
    57875795    $selected    = '';
     
    57925800    $structure[] = '</optgroup>';
    57935801
    5794     // Do manual UTC offsets
     5802    // Do manual UTC offsets.
    57955803    $structure[]  = '<optgroup label="' . esc_attr__( 'Manual Offsets' ) . '">';
    57965804    $offset_range = array(
     
    59865994    $extra_headers = $context ? apply_filters( "extra_{$context}_headers", array() ) : array();
    59875995    if ( $extra_headers ) {
    5988         $extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
     5996        $extra_headers = array_combine( $extra_headers, $extra_headers ); // Keys equal values.
    59895997        $all_headers   = array_merge( $extra_headers, (array) $default_headers );
    59905998    } else {
     
    61756183    $return          = array();
    61766184
    6177     // Set evanescent_hare to one past hare
    6178     // Increment hare two steps
     6185    // Set evanescent_hare to one past hare.
     6186    // Increment hare two steps.
    61796187    while (
    61806188        $tortoise
     
    61906198        }
    61916199
    6192         // tortoise got lapped - must be a loop
     6200        // Tortoise got lapped - must be a loop.
    61936201        if ( $tortoise == $evanescent_hare || $tortoise == $hare ) {
    61946202            return $_return_loop ? $return : $tortoise;
    61956203        }
    61966204
    6197         // Increment tortoise by one step
     6205        // Increment tortoise by one step.
    61986206        $tortoise = isset( $override[ $tortoise ] ) ? $override[ $tortoise ] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
    61996207    }
     
    62786286    $caller      = array();
    62796287    $check_class = ! is_null( $ignore_class );
    6280     $skip_frames++; // skip this function
     6288    $skip_frames++; // Skip this function.
    62816289
    62826290    if ( ! isset( $truncate_paths ) ) {
     
    62926300        } elseif ( isset( $call['class'] ) ) {
    62936301            if ( $check_class && $ignore_class == $call['class'] ) {
    6294                 continue; // Filter out calls
     6302                continue; // Filter out calls.
    62956303            }
    62966304
     
    63726380
    63736381    if ( false === $scheme_separator ) {
    6374         // $path isn't a stream
     6382        // $path isn't a stream.
    63756383        return false;
    63766384    }
     
    67236731    }
    67246732
    6725     // Has to match the window name used in post_submit_meta_box()
     6733    // Has to match the window name used in post_submit_meta_box().
    67266734    $name = 'wp-preview-' . (int) $post->ID;
    67276735
     
    70137021    );
    70147022
    7015     // get site name
     7023    // Get site name.
    70167024    $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    70177025
     
    74607468    }
    74617469
    7462     // Exclude individual site directories from the total when checking the main site of a network
     7470    // Exclude individual site directories from the total when checking the main site of a network,
    74637471    // as they are subdirectories and should not be counted.
    74647472    if ( is_multisite() && is_main_site() ) {
Note: See TracChangeset for help on using the changeset viewer.