Changeset 47122 for trunk/src/wp-includes/functions.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/functions.php (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r47098 r47122 324 324 global $wp_locale; 325 325 326 // i18n functions are not available in SHORTINIT mode 326 // i18n functions are not available in SHORTINIT mode. 327 327 if ( ! function_exists( '_x' ) ) { 328 328 return $date; … … 385 385 } 386 386 387 // Used for locale-specific rules 387 // Used for locale-specific rules. 388 388 $locale = get_locale(); 389 389 … … 591 591 */ 592 592 function maybe_unserialize( $original ) { 593 if ( is_serialized( $original ) ) { // don't attempt to unserialize data that wasn't serialized going in593 if ( is_serialized( $original ) ) { // Don't attempt to unserialize data that wasn't serialized going in. 594 594 return @unserialize( $original ); 595 595 } … … 610 610 */ 611 611 function 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. 613 613 if ( ! is_string( $data ) ) { 614 614 return false; … … 654 654 return false; 655 655 } 656 // or else fall through656 // Or else fall through. 657 657 case 'a': 658 658 case 'O': … … 709 709 } 710 710 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 */ 714 716 if ( is_serialized( $data, false ) ) { 715 717 return serialize( $data ); … … 898 900 $allowed_types = array( 'video', 'audio' ); 899 901 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. 902 903 $url_parts = @parse_url( $url ); 903 904 if ( false !== $url_parts ) { … … 1122 1123 1123 1124 wp_parse_str( $query, $qs ); 1124 $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string1125 $qs = urlencode_deep( $qs ); // This re-URL-encodes things that were already in the query string. 1125 1126 if ( is_array( $args[0] ) ) { 1126 1127 foreach ( $args[0] as $k => $v ) { … … 1155 1156 */ 1156 1157 function remove_query_arg( $key, $query = false ) { 1157 if ( is_array( $key ) ) { // removing multiple keys1158 if ( is_array( $key ) ) { // Removing multiple keys. 1158 1159 foreach ( $key as $k ) { 1159 1160 $query = add_query_arg( $k, false, $query ); … … 1486 1487 1487 1488 header( 'Content-Type: text/javascript; charset=' . get_bloginfo( 'charset' ) ); 1488 header( 'Vary: Accept-Encoding' ); // Handle proxies 1489 header( 'Vary: Accept-Encoding' ); // Handle proxies. 1489 1490 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiresOffset ) . ' GMT' ); 1490 1491 } … … 1704 1705 $alloptions = wp_load_alloptions(); 1705 1706 } 1706 // If siteurl is not set to autoload, check it specifically 1707 // If siteurl is not set to autoload, check it specifically. 1707 1708 if ( ! isset( $alloptions['siteurl'] ) ) { 1708 1709 $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); … … 2079 2080 function wp_normalize_path( $path ) { 2080 2081 $wrapper = ''; 2082 2081 2083 if ( wp_is_stream( $path ) ) { 2082 2084 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 '/'. 2087 2090 $path = str_replace( '\\', '/', $path ); 2088 2091 … … 2090 2093 $path = preg_replace( '|(?<=.)/+|', '/', $path ); 2091 2094 2092 // Windows paths should uppercase the drive letter 2095 // Windows paths should uppercase the drive letter. 2093 2096 if ( ':' === substr( $path, 1, 1 ) ) { 2094 2097 $path = ucfirst( $path ); … … 2182 2185 */ 2183 2186 function win_is_writable( $path ) { 2184 2185 if ( $path[ strlen( $path ) - 1 ] == '/' ) { // if it looks like a directory, check a random file within the directory2187 if ( $path[ strlen( $path ) - 1 ] == '/' ) { 2188 // If it looks like a directory, check a random file within the directory. 2186 2189 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. 2188 2192 return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); 2189 2193 } 2190 // check tmp file for read/write capabilities 2194 2195 // Check tmp file for read/write capabilities. 2191 2196 $should_delete_tmp_file = ! file_exists( $path ); 2192 $f = @fopen( $path, 'a' ); 2197 2198 $f = @fopen( $path, 'a' ); 2193 2199 if ( $f === false ) { 2194 2200 return false; 2195 2201 } 2196 2202 fclose( $f ); 2203 2197 2204 if ( $should_delete_tmp_file ) { 2198 2205 unlink( $path ); 2199 2206 } 2207 2200 2208 return true; 2201 2209 } … … 2328 2336 $dir = WP_CONTENT_DIR . '/uploads'; 2329 2337 } 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. 2331 2339 $dir = path_join( ABSPATH, $upload_path ); 2332 2340 } else { … … 2352 2360 } 2353 2361 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). 2355 2363 if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) { 2356 2364 … … 2403 2411 $subdir = ''; 2404 2412 if ( get_option( 'uploads_use_yearmonth_folders' ) ) { 2405 // Generate the yearly and monthly dir s2413 // Generate the yearly and monthly directories. 2406 2414 if ( ! $time ) { 2407 2415 $time = current_time( 'mysql' ); … … 2525 2533 2526 2534 // 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. 2528 2536 $count = count( $files ); 2529 2537 $i = 0; … … 2566 2574 $ext = pathinfo( $filename, PATHINFO_EXTENSION ); 2567 2575 2568 // Edge case, file names like `.ext` 2576 // Edge case, file names like `.ext`. 2569 2577 if ( empty( $fname ) ) { 2570 2578 return false; … … 2682 2690 clearstatcache(); 2683 2691 2684 // Set correct file permissions 2692 // Set correct file permissions. 2685 2693 $stat = @ stat( dirname( $new_file ) ); 2686 2694 $perms = $stat['mode'] & 0007777; … … 2689 2697 clearstatcache(); 2690 2698 2691 // Compute the URL 2699 // Compute the URL. 2692 2700 $url = $upload['url'] . "/$filename"; 2693 2701 … … 2786 2794 $proper_filename = false; 2787 2795 2788 // Do basic extension validation and MIME mapping 2796 // Do basic extension validation and MIME mapping. 2789 2797 $wp_filetype = wp_check_filetype( $filename, $mimes ); 2790 2798 $ext = $wp_filetype['ext']; 2791 2799 $type = $wp_filetype['type']; 2792 2800 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. 2794 2802 if ( ! file_exists( $file ) ) { 2795 2803 return compact( 'ext', 'type', 'proper_filename' ); … … 2801 2809 if ( $type && 0 === strpos( $type, 'image/' ) ) { 2802 2810 2803 // Attempt to figure out what type of image it actually is 2811 // Attempt to figure out what type of image it actually is. 2804 2812 $real_mime = wp_get_image_mime( $file ); 2805 2813 … … 2823 2831 ); 2824 2832 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. 2826 2834 if ( ! empty( $mime_to_ext[ $real_mime ] ) ) { 2827 2835 $filename_parts = explode( '.', $filename ); … … 2831 2839 2832 2840 if ( $new_filename != $filename ) { 2833 $proper_filename = $new_filename; // Mark that it changed 2841 $proper_filename = $new_filename; // Mark that it changed. 2834 2842 } 2835 // Redefine the extension / MIME 2843 // Redefine the extension / MIME. 2836 2844 $wp_filetype = wp_check_filetype( $new_filename, $mimes ); 2837 2845 $ext = $wp_filetype['ext']; … … 2850 2858 finfo_close( $finfo ); 2851 2859 2852 // fileinfo often misidentifies obscure files as one of these types 2860 // fileinfo often misidentifies obscure files as one of these types. 2853 2861 $nonspecific_types = array( 2854 2862 'application/octet-stream', … … 2921 2929 } 2922 2930 2923 // The mime type must be allowed 2931 // The mime type must be allowed. 2924 2932 if ( $type ) { 2925 2933 $allowed = get_allowed_mime_types(); … … 3032 3040 'webm' => 'video/webm', 3033 3041 'mkv' => 'video/x-matroska', 3034 '3gp|3gpp' => 'video/3gpp', // Can also be audio3035 '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. 3036 3044 // Text formats. 3037 3045 'txt|asc|c|cc|h|srt' => 'text/plain', … … 3983 3991 * 3984 3992 * @ignore 3985 * @since 4.4.03993 * @since 4.4.0 3986 3994 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3 3987 3995 * has been dropped. … … 4223 4231 global $wpsmiliestrans, $wp_smiliessearch; 4224 4232 4225 // don't bother setting up smilies if they are disabled4233 // Don't bother setting up smilies if they are disabled. 4226 4234 if ( ! get_option( 'use_smilies' ) ) { 4227 4235 return; … … 4303 4311 $spaces = wp_spaces_regexp(); 4304 4312 4305 // Begin first "subpattern" 4313 // Begin first "subpattern". 4306 4314 $wp_smiliessearch = '/(?<=' . $spaces . '|^)'; 4307 4315 … … 4311 4319 $rest = substr( $smiley, 1 ); 4312 4320 4313 // new subpattern?4321 // New subpattern? 4314 4322 if ( $firstchar != $subchar ) { 4315 4323 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". 4318 4326 } 4319 4327 $subchar = $firstchar; … … 5349 5357 $script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] ); 5350 5358 5351 // The request is for the admin 5359 // The request is for the admin. 5352 5360 if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) { 5353 5361 $path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] ); 5354 5362 5355 // The request is for a file in ABSPATH 5363 // The request is for a file in ABSPATH. 5356 5364 } 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. 5358 5366 $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] ); 5359 5367 5360 5368 } else { 5361 5369 if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) { 5362 // Request is hitting a file inside ABSPATH 5370 // Request is hitting a file inside ABSPATH. 5363 5371 $directory = str_replace( ABSPATH, '', $script_filename_dir ); 5364 // Strip off the sub directory, and any file/query params5372 // Strip off the subdirectory, and any file/query params. 5365 5373 $path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ); 5366 5374 } elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) { 5367 // Request is hitting a file above ABSPATH 5375 // Request is hitting a file above ABSPATH. 5368 5376 $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 installation5377 // Strip off any file/query params from the path, appending the subdirectory to the installation. 5370 5378 $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory; 5371 5379 } else { … … 5374 5382 } 5375 5383 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. 5377 5385 $url = $schema . $_SERVER['HTTP_HOST'] . $path; 5378 5386 } … … 5642 5650 */ 5643 5651 function _wp_timezone_choice_usort_callback( $a, $b ) { 5644 // Don't use translated versions of Etc 5652 // Don't use translated versions of Etc. 5645 5653 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. 5647 5655 if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) { 5648 5656 return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) ); … … 5668 5676 return strnatcasecmp( $a['t_city'], $b['t_city'] ); 5669 5677 } else { 5670 // Force Etc to the bottom of the list 5678 // Force Etc to the bottom of the list. 5671 5679 if ( 'Etc' === $a['continent'] ) { 5672 5680 return 1; … … 5713 5721 } 5714 5722 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. 5716 5724 $exists = array( 5717 5725 0 => ( isset( $zone[0] ) && $zone[0] ), … … 5743 5751 5744 5752 foreach ( $zonen as $key => $zone ) { 5745 // Build value in an array to join later 5753 // Build value in an array to join later. 5746 5754 $value = array( $zone['continent'] ); 5747 5755 5748 5756 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). 5750 5758 $display = $zone['t_continent']; 5751 5759 } else { 5752 // It's inside a continent group 5753 5754 // Continent optgroup 5760 // It's inside a continent group. 5761 5762 // Continent optgroup. 5755 5763 if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) { 5756 5764 $label = $zone['t_continent']; … … 5758 5766 } 5759 5767 5760 // Add the city to the value 5768 // Add the city to the value. 5761 5769 $value[] = $zone['city']; 5762 5770 5763 5771 $display = $zone['t_city']; 5764 5772 if ( ! empty( $zone['subcity'] ) ) { 5765 // Add the subcity to the value 5773 // Add the subcity to the value. 5766 5774 $value[] = $zone['subcity']; 5767 5775 $display .= ' - ' . $zone['t_subcity']; … … 5769 5777 } 5770 5778 5771 // Build the value 5779 // Build the value. 5772 5780 $value = join( '/', $value ); 5773 5781 $selected = ''; … … 5777 5785 $structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . '</option>'; 5778 5786 5779 // Close continent optgroup 5787 // Close continent optgroup. 5780 5788 if ( ! empty( $zone['city'] ) && ( ! isset( $zonen[ $key + 1 ] ) || ( isset( $zonen[ $key + 1 ] ) && $zonen[ $key + 1 ]['continent'] !== $zone['continent'] ) ) ) { 5781 5789 $structure[] = '</optgroup>'; … … 5783 5791 } 5784 5792 5785 // Do UTC 5793 // Do UTC. 5786 5794 $structure[] = '<optgroup label="' . esc_attr__( 'UTC' ) . '">'; 5787 5795 $selected = ''; … … 5792 5800 $structure[] = '</optgroup>'; 5793 5801 5794 // Do manual UTC offsets 5802 // Do manual UTC offsets. 5795 5803 $structure[] = '<optgroup label="' . esc_attr__( 'Manual Offsets' ) . '">'; 5796 5804 $offset_range = array( … … 5986 5994 $extra_headers = $context ? apply_filters( "extra_{$context}_headers", array() ) : array(); 5987 5995 if ( $extra_headers ) { 5988 $extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values5996 $extra_headers = array_combine( $extra_headers, $extra_headers ); // Keys equal values. 5989 5997 $all_headers = array_merge( $extra_headers, (array) $default_headers ); 5990 5998 } else { … … 6175 6183 $return = array(); 6176 6184 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. 6179 6187 while ( 6180 6188 $tortoise … … 6190 6198 } 6191 6199 6192 // tortoise got lapped - must be a loop6200 // Tortoise got lapped - must be a loop. 6193 6201 if ( $tortoise == $evanescent_hare || $tortoise == $hare ) { 6194 6202 return $_return_loop ? $return : $tortoise; 6195 6203 } 6196 6204 6197 // Increment tortoise by one step 6205 // Increment tortoise by one step. 6198 6206 $tortoise = isset( $override[ $tortoise ] ) ? $override[ $tortoise ] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) ); 6199 6207 } … … 6278 6286 $caller = array(); 6279 6287 $check_class = ! is_null( $ignore_class ); 6280 $skip_frames++; // skip this function6288 $skip_frames++; // Skip this function. 6281 6289 6282 6290 if ( ! isset( $truncate_paths ) ) { … … 6292 6300 } elseif ( isset( $call['class'] ) ) { 6293 6301 if ( $check_class && $ignore_class == $call['class'] ) { 6294 continue; // Filter out calls 6302 continue; // Filter out calls. 6295 6303 } 6296 6304 … … 6372 6380 6373 6381 if ( false === $scheme_separator ) { 6374 // $path isn't a stream 6382 // $path isn't a stream. 6375 6383 return false; 6376 6384 } … … 6723 6731 } 6724 6732 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(). 6726 6734 $name = 'wp-preview-' . (int) $post->ID; 6727 6735 … … 7013 7021 ); 7014 7022 7015 // get site name7023 // Get site name. 7016 7024 $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 7017 7025 … … 7460 7468 } 7461 7469 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, 7463 7471 // as they are subdirectories and should not be counted. 7464 7472 if ( is_multisite() && is_main_site() ) {
Note: See TracChangeset
for help on using the changeset viewer.